internal void doCall_allcheckpass() { if (toCallFunc.isYield) { if (!player.static_instance.ContainsKey(player.swc.YieldIteratorClass.staticClass.classid)) { if (!InstanceCreator.init_static_class(player.swc.YieldIteratorClass,player,token)) { invokerFrame.endStep(); if (callbacker != null) { callbacker.noticeRunFailed(); } release(); return; } } ASBinCode.rtti.YieldObject yobj = new ASBinCode.rtti.YieldObject( player.swc.YieldIteratorClass); CallFuncHeap[CallFuncHeap.Length - 2].directSet(new ASBinCode.rtData.rtInt(1)); yobj.argements = CallFuncHeap; yobj.function_bindscope = function.bindScope; yobj.block = player.swc.blocks[toCallFunc.blockid]; yobj.yield_function = toCallFunc; ASBinCode.rtData.rtObject rtYield = new ASBinCode.rtData.rtObject(yobj,null); yobj.thispointer = (function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer); RunTimeScope scope = new RunTimeScope(null, player.swc.YieldIteratorClass.blockid,null,rtYield,RunTimeScopeType.objectinstance); rtYield.objScope = scope; returnSlot.directSet(rtYield); if (callbacker != null) { callbacker.call(callbacker.args); } release(); return; } else if (!toCallFunc.isNative) { if (returnSlot is StackSlot) { TypeConverter.setDefaultValueToStackSlot( toCallFunc.signature.returnType, (StackSlot)returnSlot); } else { returnSlot.directSet( TypeConverter.getDefaultValue(toCallFunc.signature.returnType).getValue(null,null)); } if (!ReferenceEquals(callbacker,this)) { //***执行完成后,先清理参数*** BlockCallBackBase cb = player.blockCallBackPool.create(); cb.args = cb.cacheObjects; cb.cacheObjects[0] = callbacker; cb.cacheObjects[1] = invokerFrame; cb.setCallBacker(callfun_cb); cb.setWhenFailed(callfun_failed); cb._intArg = onstackparametercount; onstackparametercount = 0; player.callBlock( player.swc.blocks[toCallFunc.blockid], CallFuncHeap, returnSlot, function.bindScope, token,cb,function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,RunTimeScopeType.function); release(); } else { player.callBlock( player.swc.blocks[toCallFunc.blockid], CallFuncHeap, returnSlot, function.bindScope, token,callbacker,function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer,RunTimeScopeType.function); } } else { //if (toCallFunc.native_index <0) //{ // toCallFunc.native_index = player.swc.nativefunctionNameIndex[toCallFunc.native_name]; //} //var nf = player.swc.nativefunctions[toCallFunc.native_index]; var nf = player.swc.getNativeFunction(toCallFunc); nf.bin = player.swc; if (nf.mode == NativeFunctionBase.NativeFunctionMode.normal_0) { player._nativefuncCaller = this; string errormsg; int errorno; var result = nf.execute( function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer, CallFuncHeap,invokerFrame, out errormsg, out errorno ); player._nativefuncCaller = null; if (errormsg == null) { returnSlot.directSet(result); if (callbacker != null) { callbacker.call(callbacker.args); } release(); } else { invokerFrame.throwError( token,0,errormsg ); invokerFrame.endStep(); if (callbacker != null) { callbacker.noticeRunFailed(); } release(); } } //else if (nf.mode == NativeFunctionBase.NativeFunctionMode.normal_1) //{ // player._nativefuncCaller = this; // bool success; // nf.execute2( // function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer, // toCallFunc, // CallFuncHeap, // returnSlot, // token, // invokerFrame, // out success // ); // player._nativefuncCaller = null; // if (success) // { // if (callbacker != null) // { // callbacker.call(callbacker.args); // } // } // else // { // invokerFrame.endStep(); // if (callbacker != null) // { // callbacker.noticeRunFailed(); // } // } // release(); //} else if (nf.mode == NativeFunctionBase.NativeFunctionMode.async_0) { nf.executeAsync(function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer, CallFuncHeap, returnSlot, callbacker, invokerFrame, token, function.bindScope ); if (!ReferenceEquals(callbacker,this)) { release(); } } else if (nf.mode == NativeFunctionBase.NativeFunctionMode.const_parameter_0) { bool success = false; player._nativefuncCaller = this; var nf3 = (nativefuncs.NativeConstParameterFunction)nf; player._executeToken = nf3.getExecToken(toCallFunc.functionid); nf3.execute3( function.this_pointer != null ? function.this_pointer : invokerFrame.scope.this_pointer, toCallFunc, returnSlot, token, invokerFrame, out success ); player._executeToken = nativefuncs.NativeConstParameterFunction.ExecuteToken.nulltoken; player._nativefuncCaller = null; ((nativefuncs.NativeConstParameterFunction)nf).clearParameter(); clear_para_slot(invokerFrame,onstackparametercount); onstackparametercount = 0; if (success) { var receive_err = player.clear_nativeinvokeraiseerror(); if (receive_err != null) { invokerFrame.receiveErrorFromStackFrame(receive_err); if (callbacker != null) { callbacker.noticeRunFailed(); } } else if (callbacker != null) { callbacker.call(callbacker.args); } } else { invokerFrame.endStep(); if (callbacker != null) { callbacker.noticeRunFailed(); } } release(); } } }
private static ASBinCode.rtti.Object createObject(CSWC swc,Class cls,InstanceCreator creator, out ASBinCode.rtData.rtObjectBase rtObjectBase, out ASBinCode.rtData.rtObjectBase linkrtobj, out string errinfo ) { ASBinCode.rtti.Object obj = null;// = new ASBinCode.rtti.Object(cls); rtObjectBase = null; linkrtobj = null; errinfo = null; if (cls.isLink_System) { if (creator != null) { StackSlot stackSlot = creator.objectStoreToSlot as StackSlot; if (stackSlot != null) { rtObjectBase = stackSlot.getStackCacheObject(cls); return(rtObjectBase.value); } } var func = (NativeFunctionBase)swc.class_Creator[cls]; string err; int no; ASBinCode.rtData.rtObjectBase rtObj = func.execute(null,null,cls,out err,out no) as ASBinCode.rtData.rtObjectBase; linkrtobj = rtObj; if (rtObj == null) { errinfo = cls.ToString() + " create linksystem object failed"; return(null); } else { return(rtObj.value); } } else if (cls.isCrossExtend) { var scls = cls.super; while (!scls.isLink_System) { scls = scls.super; } var cextend = scls.staticClass.linkObjCreator; var func = swc.getNativeFunction(((ClassMethodGetter)cextend.bindField).functionId); if (func == null) { errinfo = cls.ToString() + " create crossextend object failed, creator function not found"; return(null); } string err; int no; ASBinCode.rtData.rtObjectBase rtObj = func.execute(null,null,cls,out err,out no) as ASBinCode.rtData.rtObjectBase; linkrtobj = rtObj; if (rtObj == null) { errinfo = cls.ToString() + " create crossextend object failed"; return(null); } else { LinkSystemObject lo = (LinkSystemObject)rtObj.value; return(lo); } } else if ( swc.DictionaryClass != null && ClassMemberFinder.isInherits(cls,swc.DictionaryClass)) { obj = new DictionaryObject(cls); } else if (cls.dynamic) { if (cls.isUnmanaged) { obj = new HostedDynamicObject(cls); } else { obj = new DynamicObject(cls); } } else if (cls.isUnmanaged) { obj = new HostedObject(cls); } else { obj = new ASBinCode.rtti.Object(cls); } return(obj); }
private static ASBinCode.rtData.rtObjectBase makeObj( Player player, SourceToken token, ASBinCode.rtti.Class cls, BlockCallBackBase callbacker,InstanceCreator creator,out ASBinCode.RunTimeScope objScope) { ASBinCode.rtData.rtObjectBase result; ASBinCode.rtData.rtObjectBase lr; string err; ASBinCode.rtti.Object obj = createObject(player.swc,cls,creator,out result,out lr,out err); if (obj == null) { objScope = null; if (callbacker != null) { callbacker.noticeRunFailed(); } player.throwWhenMakeObjFailed(new ASRunTimeException(err,player.stackTrace(0))); return(null); } if (result == null) { if (lr == null) { result = new ASBinCode.rtData.rtObject(obj,null); } else { result = lr; } if (cls.fields.Count > 0) { obj.memberData = new ObjectMemberSlot[cls.fields.Count]; for (int i = 0; i < obj.memberData.Length; i++) { obj.memberData[i] = new ObjectMemberSlot(result,player.swc.FunctionClass.getRtType(),cls.fields[i].valueType,player.swc); if (cls.fields[i].defaultValue == null) { obj.memberData[i].directSet(TypeConverter.getDefaultValue(cls.fields[i].valueType).getValue(null,null)); } ((ObjectMemberSlot)obj.memberData[i]).isConstMember = cls.fields[i].isConst; } } else { obj.memberData = blankFields; } ASBinCode.CodeBlock codeblock = player.swc.blocks[cls.blockid]; objScope = player.callBlock(codeblock, (ObjectMemberSlot[])obj.memberData,null, null ,token,callbacker , result,RunTimeScopeType.objectinstance ); result.objScope = objScope; if (objScope == null) { if (callbacker != null) { callbacker.noticeRunFailed(); } return(null); } //***把父类的初始化函数推到栈上去*** var ss = cls.super; while (ss != null) { var scope = player.callBlock(player.swc.blocks[ss.blockid], (ObjectMemberSlot[])obj.memberData, null,null,token,null,result,RunTimeScopeType.objectinstance ); ss = ss.super; if (scope == null) { if (callbacker != null) { callbacker.noticeRunFailed(); } return(null); } } } else { objScope = result.objScope; player.CallBlankBlock(callbacker); } if (callbacker != null) { //callbacker.obj = obj; //callbacker.rtObject = result; //callbacker.objScope = objScope; callbacker.cacheObjects[0] = obj; callbacker.cacheObjects[1] = result; callbacker.cacheObjects[2] = objScope; } return(result); }
private static void afterCreateStaticInstanceCallBacker(BlockCallBackBase sender,object args) { InstanceCreator ic = (InstanceCreator)sender.args; ic.set_Class_constructor(); }