Просмотр исходного кода

Fix a bug introduced by code to allow local declared functions been called recursivelly, this bug only manifest when the function has default parameters.

mingodad 12 лет назад
Родитель
Сommit
f8926bfb8a
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      SquiLu/squirrel/sqcompiler.cpp

+ 4 - 4
SquiLu/squirrel/sqcompiler.cpp

@@ -1178,13 +1178,13 @@ public:
 			//the following is an attempt to allow local declared functions be called recursivelly
 			//the following is an attempt to allow local declared functions be called recursivelly
 			SQInteger old_pos = _fs->GetCurrentPos(); //save current instructions position
 			SQInteger old_pos = _fs->GetCurrentPos(); //save current instructions position
 			_fs->PushLocalVariable(varname, _scope.nested, _VAR_CLOSURE); //add function name to find it as outer var if needed
 			_fs->PushLocalVariable(varname, _scope.nested, _VAR_CLOSURE); //add function name to find it as outer var if needed
-			CreateFunction(varname,false);
+			CreateFunction(varname,false, -1);
 			_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, 0);
 			_fs->AddInstruction(_OP_CLOSURE, _fs->PushTarget(), _fs->_functions.size() - 1, 0);
 			//rellocate any stack operation (default parameters & _OP_Closure)
 			//rellocate any stack operation (default parameters & _OP_Closure)
 			for(int i=old_pos+1, curr_pos = _fs->GetCurrentPos(); i <= curr_pos; ++i){
 			for(int i=old_pos+1, curr_pos = _fs->GetCurrentPos(); i <= curr_pos; ++i){
 			    SQInstruction & inst = _fs->GetInstruction(i);
 			    SQInstruction & inst = _fs->GetInstruction(i);
 			    _fs->SetIntructionParam(i, 0, inst._arg0 -1);
 			    _fs->SetIntructionParam(i, 0, inst._arg0 -1);
-			}
+			}
 			_fs->PopTarget();
 			_fs->PopTarget();
 			return;
 			return;
 		}
 		}
@@ -1713,7 +1713,7 @@ if(color == "yellow"){
 		}
 		}
 		_es = es;
 		_es = es;
 	}
 	}
-	void CreateFunction(SQObject &name,bool lambda = false)
+	void CreateFunction(SQObject &name,bool lambda = false, int stack_offset=0)
 	{
 	{
 		SQFuncState *funcstate = _fs->PushChildState(_ss(_vm));
 		SQFuncState *funcstate = _fs->PushChildState(_ss(_vm));
 		funcstate->_name = name;
 		funcstate->_name = name;
@@ -1744,7 +1744,7 @@ if(color == "yellow"){
 					Lex();
 					Lex();
 					if(_token == _SC('[') || _token == _SC('{')) Error(_SC("default parameter with array/table values not supported"));
 					if(_token == _SC('[') || _token == _SC('{')) Error(_SC("default parameter with array/table values not supported"));
 					Expression();
 					Expression();
-					funcstate->AddDefaultParam(_fs->TopTarget());
+					funcstate->AddDefaultParam(_fs->TopTarget()+stack_offset);
 					defparams++;
 					defparams++;
 				}
 				}
 			else if(_token == _SC(':')){
 			else if(_token == _SC(':')){