/*函数的调用*/ Var IL_CallFunc (int args, int f_index,int mode) { Var result; Var arg_list[args]; /*回溯添加参数,并把当前层的开头的相应的*/ /*局部变量赋值为此*/ { IL_node * tmp=current_node->pre; int i=0; for ( i=0; i<args; i++) { Var source= (*get_tmp(tmp->tmp_index)); tmp=tmp->pre; arg_list[args-i-1]=source; } if(mode==FUNC_DYNAMIC)/*说延迟绑定函数索引,这是需要在开头寻找*/ { f_index=vm_RTstackVarGetAbs (f_index)->content.var_value.func.func_index; mode=vm_RTstackVarGetAbs(f_index)->content.var_value.func.func_type; } if(mode==FUNC_METHOD) { f_index=get_tmp(tmp->tmp_index)->content.var_value.func.func_index; mode=get_tmp(tmp->tmp_index)->content.var_value.func.func_type; } } if(mode==FUNC_NORMAL)/*普通的脚本函数调用*/ { Function * f =func_get_by_index ( f_index); int i=0; vm_RTstackPush(); if(f->is_var_arg==0) { /*检查执行时刻的参数是否与所对应的函数的参数数目相符*/ if(f->arg_counts!=args) { printf("error,the index %d %s the args count is not match p: %d a:%d\n",f_index,f->name,f->arg_counts,args); exit(0); } for ( i=0; i<args; i++) { Var source=arg_list[i]; vm_rt_stack_var_set ( i,source); } } else/*不定长参数*/ { if(args==0)/*带有变长参数的函数,不允许出现无参数的情况*/ { STOP("the variable argument list shall not be empty."); } vm_rt_stack_var_set ( 0,tuple_CreateByList(args,arg_list)); } /*保存当前的表环境*/ IL_list * old_list =current_list; result =func_invoke ( f_index); current_list=old_list; /*函数的栈弹出*/ vm_RTstackPop(); } else if(mode==FUNC_API)/*API函数调用情况*/ { int i=0; for ( i=0; i<args; i++ ) { API_argument_list[i]=arg_list[i]; } API_SetArgCount(args); Var return_value=API_InovkeByIndex ( f_index); return return_value; } return result; }
virtual void invoke( ::osiris::IEvent * e ){ ::osiris::PythonState __pystate(getPythonThreadState()); ::osiris::PythonOverride func_invoke = this->get_override( "invoke" ); func_invoke( boost::python::ptr(e) ); }