private static void _execAdd_InvokeToString_CallBacker( ASBinCode.RunTimeValueBase v1, ASBinCode.RunTimeValueBase v2, StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { ASBinCode.RunTimeDataType v1type = v1.rtType; ASBinCode.RunTimeDataType v2type = v2.rtType; if (v1type == ASBinCode.RunTimeDataType.rt_void) { v1type = ASBinCode.RunTimeDataType.rt_number; } if (v2type == ASBinCode.RunTimeDataType.rt_void) { v2type = ASBinCode.RunTimeDataType.rt_number; } ASBinCode.RunTimeDataType finalType = TypeConverter.getImplicitOpType( v1type, v2type, ASBinCode.OpCode.add, frame.player.swc ); if (finalType == ASBinCode.RunTimeDataType.rt_number) { step.reg.getSlot(scope, frame).setValue( TypeConverter.ConvertToNumber(v1) + TypeConverter.ConvertToNumber(v2) ); frame.endStepNoError(); return; } else if (finalType == ASBinCode.RunTimeDataType.rt_string) { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_Cast_TwoString_Callbacker); cb.args = frame; cb.scope = scope; cb.step = step; OpCast.CastTwoValue(v1, v2, finalType, frame, step.token, scope, frame._tempSlot1, frame._tempSlot2, cb ); return; } else if (finalType == ASBinCode.RunTimeDataType.rt_void) { step.reg.getSlot(scope, frame).setValue(ASBinCode.rtData.rtUndefined.undefined); } else { frame.throwOpException(step.token, ASBinCode.OpCode.add); } frame.endStep(step); }
private void _SeptoString_CB(BlockCallBackBase sender,object args) { object[] receiveArgs = (object[])sender.args; StackFrame frame = (StackFrame)receiveArgs[2]; rtArray array = (rtArray)receiveArgs[1]; BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg + 1; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(_ValueToString_CB); valueCB._intArg2 = sender._intArg2; var v = array.innerArray[sender._intArg]; if (v.rtType == RunTimeDataType.rt_void) { v = UNDEFINED; } sender.noticeEnd(); operators.OpCast.CastValue(v,RunTimeDataType.rt_string, frame, (SourceToken)receiveArgs[3], (RunTimeScope)receiveArgs[4], frame._tempSlot1, valueCB,false ); }
private void exec_step3(ASBinCode.rtData.rtObjectBase rtobject) { if (constructor == null) { objectResult = rtobject; //objectResult.directSet(rtobject); if (callbacker != null) { callbacker.call(this); callbacker = null; } } else { HeapSlot _temp = tempSlot; _temp.directSet(ASBinCode.rtData.rtUndefined.undefined); _function_constructor.returnSlot = _temp; //_function_constructor.function = (ASBinCode.rtData.rtFunction)TypeConverter.ObjectImplicit_ToPrimitive(constructor).Clone(); //_function_constructor.function.setThis(rtobject); _function_constructor.SetFunction((ASBinCode.rtData.rtFunction)TypeConverter.ObjectImplicit_ToPrimitive(constructor),rtobject); BlockCallBackBase cb = player.blockCallBackPool.create(); cb.args = cb.cacheObjects; //new object[] { rtobject , _temp }; cb.cacheObjects[0] = rtobject; cb.cacheObjects[1] = _temp; cb.setCallBacker(_finalStep); _function_constructor.callbacker = cb; _function_constructor.call(); _function_constructor = null; } }
public static void _pusharray(ASBinCode.rtti.Vector_Data o, StackFrame frame, OpStep step, RunTimeScope scope) { var arr = step.arg2.getValue(scope, frame); if (arr.rtType == RunTimeDataType.rt_null) { frame.throwCastException(step.token, RunTimeDataType.rt_null, step.arg1.getValue(scope, frame).rtType ); frame.endStep(step); } else { rtArray array = (rtArray)arr; if (array.innerArray.Count == 0) { frame.endStep(step); } else { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.step = step; cb.args = frame; cb.setCallBacker(_allpushed); pushAllElementToVector(o, array.innerArray, frame, step.token, scope, cb); } } }
public static void _pushVector(ASBinCode.rtti.Vector_Data o, StackFrame frame, OpStep step, RunTimeScope scope) { var arr = step.arg2.getValue(scope, frame); if (arr.rtType == RunTimeDataType.rt_null) { frame.throwCastException(step.token, RunTimeDataType.rt_null, step.arg1.getValue(scope, frame).rtType ); frame.endStep(step); } else { ASBinCode.rtti.Vector_Data array = (ASBinCode.rtti.Vector_Data)((ASBinCode.rtti.HostedObject)((rtObjectBase)step.arg2.getValue(scope, frame)).value).hosted_object; if (array.innnerList.Count == 0) { frame.endStep(step); } else { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.step = step; cb.args = frame; cb.setCallBacker(D_allpushed); pushAllElementToVector(o, array.innnerList, frame, step.token, scope, cb); } } }
private static void _SeptoString_CB(BlockCallBackBase sender,object args) { object[] receiveArgs = (object[])sender.args; StackFrame frame = (StackFrame)receiveArgs[2]; RunTimeValueBase aSep = (RunTimeValueBase)receiveArgs[5]; if (aSep.rtType != RunTimeDataType.rt_null) { string sep = TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,(SourceToken)receiveArgs[3]); receiveArgs[5] = sep; } else { receiveArgs[5] = ","; } rtArray array = (rtArray)receiveArgs[1]; BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg + 1; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(D_ValueToString_CB); operators.OpCast.CastValue(array.innerArray[sender._intArg],RunTimeDataType.rt_string, frame, (SourceToken)receiveArgs[3], (RunTimeScope)receiveArgs[4], frame._tempSlot1, valueCB,false ); }
public sealed override void executeAsync(RunTimeValueBase thisObj, SLOT[] argements,SLOT resultSlot,object callbacker, object stackframe,SourceToken token,RunTimeScope scope) { ASBinCode.rtti.YieldObject yieldObj = (ASBinCode.rtti.YieldObject) ((ASBinCode.rtData.rtObjectBase)thisObj).value; yieldObj.returnSlot.directSet(ASBinCode.rtData.rtUndefined.undefined); yieldObj._moveNextResultSlot = resultSlot; yieldObj._callbacker = callbacker; StackFrame frame = (StackFrame)stackframe; var toCallFunc = yieldObj.yield_function; var CallFuncHeap = yieldObj.argements; CallFuncHeap[CallFuncHeap.Length - 1].directSet(ASBinCode.rtData.rtBoolean.False); BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.args = yieldObj; cb.setCallBacker(_movenext_callbacker); frame.player.callBlock( frame.player.swc.blocks[toCallFunc.blockid], CallFuncHeap, yieldObj.returnSlot, yieldObj.function_bindscope, token,cb,yieldObj.thispointer,RunTimeScopeType.function); }
public static void _doSetThisItem(ASBinCode.rtData.rtObjectBase thisObj, RunTimeValueBase v,RunTimeValueBase index,StackSlot slot,StackFrame frame,OpStep step ) { //***读取setter*** RunTimeValueBase func; func = ((MethodGetterBase)thisObj.value._class.set_this_item.bindField).getMethod( thisObj ); //***调用设置器*** var funCaller = frame.player.funcCallerPool.create(frame,step.token); funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } //funCaller.releaseAfterCall = true; bool success; funCaller.pushParameter(v,0,out success); if (!success) { frame.endStep(step); return; } funCaller.pushParameter(index,1,out success); if (!success) { frame.endStep(step); return; } funCaller._tempSlot = frame._tempSlot1; funCaller.returnSlot = frame._tempSlot1; BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(_setthisitem_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; }
private void exec_step1() { BlockCallBackBase callbacker = player.blockCallBackPool.create(); callbacker.args = this; callbacker.setCallBacker(afterCreateInstanceDataCallBacker); callbacker.setWhenFailed(creatorFailed); ASBinCode.RunTimeScope objScope; makeObj(player,token,_class,callbacker,this,out objScope); }
public static void enumerator_current(StackFrame frame,OpStep step,RunTimeScope scope) { //StackSlot slot = (StackSlot)((Register)step.arg1).getSlot(scope); rtObjectBase save = (rtObjectBase)(step.arg1).getValue(scope,frame); HostedDynamicObject saveObj = (HostedDynamicObject)save.value; IEnumerator <RunTimeValueBase> enumerator = saveObj.hosted_object as IEnumerator <RunTimeValueBase>; //IEnumerator<RunTimeValueBase> enumerator = scope.cache_enumerator as IEnumerator<RunTimeValueBase>; if (enumerator != null) { step.reg.getSlot(scope,frame).directSet(enumerator.Current); } else { if (saveObj.hosted_object is rtObjectBase) //是否是接口 { var movenext = ClassMemberFinder.find(frame.player.swc.IEnumeratorInterface,"current",frame.player.swc.IEnumeratorInterface); var method = ((ClassPropertyGetter)movenext.bindField).getter.getMethod(((rtObjectBase)saveObj.hosted_object)); //***调用方法*** var funCaller = frame.player.funcCallerPool.create(frame,step.token); //funCaller.releaseAfterCall = true; funCaller.SetFunction((ASBinCode.rtData.rtFunction)method); ((ASBinCode.rtData.rtFunction)method).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } funCaller._tempSlot = step.reg.getSlot(scope,frame); funCaller.returnSlot = step.reg.getSlot(scope,frame); BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_enumerator_operator_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; } } frame.endStep(step); }
public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,SLOT resultSlot,object callbacker,object stackframe,SourceToken token,RunTimeScope scope) { IBlockCallBack cb = (IBlockCallBack)callbacker; StackFrame frame = (StackFrame)stackframe; if (argements[0].getValue().rtType == RunTimeDataType.rt_null) { if (frame.player.infoOutput != null) { frame.player.infoOutput.Info(string.Empty); } cb.call(cb.args); return; } rtArray array = (rtArray)(argements[0].getValue()); if (array.innerArray.Count == 0) { if (frame.player.infoOutput != null) { frame.player.infoOutput.Info(string.Empty); } cb.call(cb.args); return; } BlockCallBackBase sepcb = frame.player.blockCallBackPool.create(); sepcb.scope = scope; sepcb._intArg = 0; sepcb.setCallBacker(null); sepcb._intArg2 = 0; object[] sendargs = sepcb.cacheObjects; sendargs[0] = cb; sendargs[1] = array; sendargs[2] = frame; sendargs[3] = token; sendargs[4] = scope; sendargs[5] = " "; sendargs[6] = new StringBuilder(); sendargs[7] = resultSlot; //sendargs[8] = new rtInt(0); sepcb.args = sendargs; _SeptoString_CB(sepcb,sendargs); }
public static void exec_instanceClass(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { //frame.instanceCreator.objectResult = step.reg.getISlot(scope); frame.instanceCreator.step = step; frame.instanceCreator.token = step.token; frame.instanceCreator.objectStoreToSlot = step.reg.getSlot(scope, frame); BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.args = frame; cb.setCallBacker(D_objcreated); cb.scope = scope; cb.step = step; frame.instanceCreator.callbacker = cb; frame.instanceCreator.createInstance(); }
public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements, SLOT resultSlot,object callbacker,object stackframe,SourceToken token,RunTimeScope scope) { IBlockCallBack cb = (IBlockCallBack)callbacker; StackFrame frame = (StackFrame)stackframe; rtArray array = (rtArray)((rtObjectBase)thisObj).value.memberData[0].getValue(); if (array.innerArray.Count == 0) { cb.call(cb.args); resultSlot.directSet(new rtString(string.Empty)); return; } BlockCallBackBase sepcb = frame.player.blockCallBackPool.create(); sepcb.scope = scope; sepcb._intArg = 0; object[] sendargs = sepcb.cacheObjects; sendargs[0] = cb; sendargs[1] = array; sendargs[2] = frame; sendargs[3] = token; sendargs[4] = scope; sendargs[5] = argements[0].getValue(); sendargs[6] = new StringBuilder(); sendargs[7] = resultSlot; sendargs[8] = new rtInt(0); sepcb.args = sendargs; sepcb.setCallBacker(D_SeptoString_CB); operators.OpCast.CastValue(argements[0].getValue(),RunTimeDataType.rt_string, frame,token,scope,frame._tempSlot1,sepcb,false); }
public static void exec(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { //int classid = ((ASBinCode.rtData.rtInt)step.arg1.getValue(scope)).value; //ASBinCode.rtti.Class as3class = player.swc.classes[classid]; //exec_createinstance(as3class, player, frame, step, scope); //frame.instanceCreator.objectResult = step.reg.getISlot(scope); frame.instanceCreator.step = step; frame.instanceCreator.token = step.token; frame.instanceCreator.objectStoreToSlot = step.reg.getSlot(scope, frame); BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.args = frame; cb.setCallBacker(D_objcreated); cb.scope = scope; cb.step = step; frame.instanceCreator.callbacker = cb; frame.instanceCreator.createInstance(); }
public static void pushAllElementToVector(ASBinCode.rtti.Vector_Data vd, List <RunTimeValueBase> datalist, StackFrame frame, SourceToken token, RunTimeScope scope, IBlockCallBack callbacker ) { BlockCallBackBase convertCb = frame.player.blockCallBackPool.create(); convertCb._intArg = 0; convertCb.setCallBacker(_convertCB); object[] args = convertCb.cacheObjects; //new object[6]; args[0] = vd; args[1] = datalist; args[2] = token; args[3] = scope; args[4] = callbacker; args[5] = frame; convertCb.args = args; OpCast.CastValue(datalist[convertCb._intArg], vd.vector_type, frame, token, scope, frame._tempSlot1, convertCb, false); }
public static void execUnaryPlus(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { ASBinCode.RunTimeValueBase v = step.arg1.getValue(scope, frame); var f = frame.player.swc.operatorOverrides.getOperatorFunction(OverrideableOperator.Unary_plus, v.rtType, RunTimeDataType.unknown); if (f != null) { FunctionCaller fc = frame.player.funcCallerPool.create(frame, step.token); //fc.releaseAfterCall = true; fc.SetFunction(f); fc.loadDefineFromFunction(); if (!fc.createParaScope()) { return; } bool success; fc.pushParameter(v, 0, out success); fc.returnSlot = step.reg.getSlot(scope, frame); fc.callbacker = fc; fc.call(); return; } else { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.scope = scope; cb.step = step; cb.args = frame; cb.setCallBacker(_tonumber_cb); OpCast.CastValue(v, RunTimeDataType.rt_number, frame, step.token, scope, frame._tempSlot1, cb, false); } }
private void _ValueToString_CB(BlockCallBackBase sender,object args) { object[] receiveArgs = (object[])sender.args; StackFrame frame = (StackFrame)receiveArgs[2]; rtArray array = (rtArray)receiveArgs[1]; //((rtInt)receiveArgs[8]).value++; sender._intArg2++; if (sender._intArg2 == 10) //((rtInt)receiveArgs[8]).value == 10) //堆栈清理,防止溢出... { sender._intArg2 = 0; //((rtInt)receiveArgs[8]).value = 0; BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg; valueCB._intArg2 = 0; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(_ValueToString_CB); frame.player.CallBlankBlock(valueCB); return; } StringBuilder sb = (StringBuilder)receiveArgs[6]; SourceToken token = (SourceToken)receiveArgs[3]; string aSep = (string)receiveArgs[5]; sb.Append( TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token) == null?"null": TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token) ); if (sender._intArg < array.innerArray.Count) { sb.Append(aSep); BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg + 1; valueCB._intArg2 = sender._intArg2; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(_ValueToString_CB); var v = array.innerArray[sender._intArg]; if (v.rtType == RunTimeDataType.rt_void) { v = UNDEFINED; } operators.OpCast.CastValue(v,RunTimeDataType.rt_string, frame, (SourceToken)receiveArgs[3], (RunTimeScope)receiveArgs[4], frame._tempSlot1, valueCB,false ); } else { //ISLOT result = (ISLOT)receiveArgs[7]; //result.directSet(new rtString(sb.ToString())); if (frame.player.infoOutput != null) { frame.player.infoOutput.Info(sb.ToString()); } IBlockCallBack cb = (IBlockCallBack)receiveArgs[0]; cb.call(cb.args); } }
public static void exec_initfromdata(StackFrame frame, OpStep step, RunTimeScope scope) { var player = frame.player; RunTimeValueBase initdata = step.arg2.getValue(scope, frame); int classrttype = ((rtInt)step.arg1.getValue(scope, frame)).value; while (true) { if (initdata.rtType == classrttype) { step.reg.getSlot(scope, frame).directSet(initdata); frame.endStep(step); return; } else if (initdata.rtType == RunTimeDataType.rt_array) { break; } else if ( initdata.rtType > RunTimeDataType.unknown ) { var cls = ((rtObjectBase)initdata).value._class; if (player.swc.dict_Vector_type.ContainsKey(cls)) { break; } } frame.throwCastException(step.token, initdata.rtType, classrttype); frame.endStep(step); return; } var _class = player.swc.getClassByRunTimeDataType(classrttype); //frame.instanceCreator = new InstanceCreator(player, frame, step.token, _class); frame.activeInstanceCreator(step.token, _class); frame.instanceCreator.step = step; frame.instanceCreator.token = step.token; if (_class.constructor != null) { if (!frame.instanceCreator.prepareConstructorArgements()) { return; } } BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.args = frame; cb.setCallBacker(objcreated); cb.scope = scope; cb.step = step; frame.instanceCreator.callbacker = cb; frame.instanceCreator.createInstance(); return; }
private static void _ValueToString_CB(BlockCallBackBase sender,object args) { object[] receiveArgs = (object[])sender.args; StackFrame frame = (StackFrame)receiveArgs[2]; rtArray array = (rtArray)receiveArgs[1]; ((rtInt)receiveArgs[8]).value++; if (((rtInt)receiveArgs[8]).value == 10) //堆栈清理,防止溢出... { ((rtInt)receiveArgs[8]).value = 0; BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(D_ValueToString_CB); frame.player.CallBlankBlock(valueCB); return; } StringBuilder sb = (StringBuilder)receiveArgs[6]; SourceToken token = (SourceToken)receiveArgs[3]; string aSep = (string)receiveArgs[5]; string toappend = TypeConverter.ConvertToString(frame._tempSlot1.getValue(),frame,token); while (true) { sb.Append(toappend == null ? "null" : toappend); if (sender._intArg < array.innerArray.Count) { sb.Append(aSep); if (//sender._intArg < array.innerArray.Count //&& array.innerArray[sender._intArg].rtType < RunTimeDataType.unknown ) { toappend = TypeConverter.ConvertToString(array.innerArray[sender._intArg],frame,token); sender._intArg++; continue; } else { BlockCallBackBase valueCB = frame.player.blockCallBackPool.create(); valueCB._intArg = sender._intArg + 1; valueCB.args = valueCB.copyFromReceiveArgs(receiveArgs); valueCB.setCallBacker(D_ValueToString_CB); operators.OpCast.CastValue(array.innerArray[sender._intArg],RunTimeDataType.rt_string, frame, (SourceToken)receiveArgs[3], (RunTimeScope)receiveArgs[4], frame._tempSlot1, valueCB,false ); break; } } else { SLOT result = (SLOT)receiveArgs[7]; result.directSet(new rtString(sb.ToString())); IBlockCallBack cb = (IBlockCallBack)receiveArgs[0]; cb.call(cb.args); break; } } }
private void check_para(BlockCallBackBase checkparacb) { while (check_para_id < pushedArgs) { var parameter = toCallFunc.signature.parameters; RunTimeValueBase argement = getToCheckParameter(check_para_id); var argtype = argement.rtType; var targettype = parameter[check_para_id].type; if (argtype != targettype && targettype != RunTimeDataType.rt_void && !(argtype == RunTimeDataType.rt_null && targettype > RunTimeDataType.unknown) && !(argtype > RunTimeDataType.unknown && targettype > RunTimeDataType.unknown && ( ClassMemberFinder.check_isinherits(argement,targettype,player.swc) || ClassMemberFinder.check_isImplements(argement,targettype,player.swc) ) ) ) { BlockCallBackBase cb = player.blockCallBackPool.create(); cb.args = argement; cb._intArg = check_para_id; cb.setCallBacker(check_para_callbacker); cb.setWhenFailed(check_para_failed); check_para_id++; OpCast.CastValue(argement,parameter[ cb._intArg].type, invokerFrame,token,invokerFrame.scope,_tempSlot,cb,false); return; } else { check_para_id++; } } if (pushedArgs < toCallFunc.signature.parameters.Count && !toCallFunc.IsAnonymous) //匿名函数能跳过参数检查 { for (int i = pushedArgs; i < toCallFunc.signature.parameters.Count; i++) { if (toCallFunc.signature.parameters[pushedArgs].defaultValue == null && !toCallFunc.signature.parameters[pushedArgs].isPara ) { invokerFrame.throwArgementException( token, string.Format( "Argument count mismatch on Function/{0}. Expected {1}, got {2}.", player.swc.blocks[toCallFunc.blockid].name,toCallFunc.signature.parameters.Count,pushedArgs ) ); clear_para_slot(invokerFrame,onstackparametercount); onstackparametercount = 0; //***中断本帧本次代码执行进入try catch阶段 invokerFrame.endStep(); if (callbacker != null) { callbacker.noticeRunFailed(); } release(); return; } } } if (!check_return_objtypeisclasscreated()) { return; } if (checkparacb != null) { checkparacb.noticeEnd(); } //***全部参数检查通过*** doCall_allcheckpass(); }
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(); } } }
public static void enumerator_movenext(StackFrame frame,OpStep step,RunTimeScope scope) { //StackSlot slot = (StackSlot)((Register)step.arg1).getSlot(scope); rtObjectBase save = (rtObjectBase)(step.arg1).getValue(scope,frame); HostedDynamicObject saveObj = (HostedDynamicObject)save.value; IEnumerator <RunTimeValueBase> enumerator = saveObj.hosted_object as IEnumerator <RunTimeValueBase>; if (enumerator != null) //&& enumerator.MoveNext() )//slot.cache_enumerator !=null && slot.cache_enumerator.MoveNext()) { try { if (enumerator.MoveNext()) { step.reg.getSlot(scope,frame).setValue(rtBoolean.True); } else { step.reg.getSlot(scope,frame).setValue(rtBoolean.False); } } catch (ASRunTimeException ex) { step.reg.getSlot(scope,frame).setValue(rtBoolean.False); frame.throwAneException(step.token,ex.Message + "\n" + ex.AS3StackTrace); return; } } else { if (saveObj.hosted_object is rtObjectBase) //是否是接口 { var movenext = ClassMemberFinder.find(frame.player.swc.IEnumeratorInterface,"moveNext",frame.player.swc.IEnumeratorInterface); var method = ((InterfaceMethodGetter)movenext.bindField).getMethod( (((rtObjectBase)saveObj.hosted_object))); //***调用方法*** var funCaller = frame.player.funcCallerPool.create(frame,step.token); //funCaller.releaseAfterCall = true; funCaller.SetFunction((ASBinCode.rtData.rtFunction)method); ((ASBinCode.rtData.rtFunction)method).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } funCaller._tempSlot = step.reg.getSlot(scope,frame); funCaller.returnSlot = step.reg.getSlot(scope,frame); BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_enumerator_operator_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; } else { step.reg.getSlot(scope,frame).setValue(rtBoolean.False); } } frame.endStep(step); }
public static void forin_get_enumerator(StackFrame frame, OpStep step, RunTimeScope scope) { var player = frame.player; SLOT slot = step.reg.getSlot(scope,frame); ASBinCode.rtti.HostedDynamicObject saveObj = new HostedDynamicObject(player.swc.ObjectClass); rtObject save = new rtObject(saveObj,null); slot.directSet(save); var obj = step.arg1.getValue(scope,frame); if (obj.rtType > RunTimeDataType.unknown) { rtObject rtObj = (rtObject)obj; if (ClassMemberFinder.isInherits(rtObj.value._class, player.swc.primitive_to_class_table[RunTimeDataType.rt_array])) { rtArray arr = (rtArray)rtObj.value.memberData[0].getValue(); saveObj.hosted_object = getArrayForIn(arr.innerArray); } else if (player.swc.dict_Vector_type.ContainsKey(rtObj.value._class)) { saveObj.hosted_object = getArrayForIn(((Vector_Data)((HostedObject)rtObj.value).hosted_object).innnerList); } else if (ClassMemberFinder.isImplements(rtObj.value._class,player.swc.IEnumerableInterface)) { //***调用getIEnumerator方法**** var movenext = ClassMemberFinder.find( frame.player.swc.IEnumerableInterface,"getEnumerator", frame.player.swc.IEnumerableInterface); var method = ((InterfaceMethodGetter)movenext.bindField).getMethod( rtObj); //***调用方法*** var funCaller = player.funcCallerPool.create(frame,step.token); //funCaller.releaseAfterCall = true; funCaller.SetFunction((rtFunction)method); ((rtFunction)method).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } funCaller._tempSlot = frame._tempSlot1; funCaller.returnSlot = frame._tempSlot1; BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_getEnumerator_callbacker); cb.step = step; cb.args = frame; cb.scope = scope; funCaller.callbacker = cb; funCaller.call(); return; } else if (ClassMemberFinder.isImplements( rtObj.value._class,player.swc.IEnumeratorInterface)) { saveObj.hosted_object = rtObj; } else { IEnumerator <RunTimeValueBase> forinenum = getForinIEnumerator(player,rtObj.value,frame,step,scope); saveObj.hosted_object = forinenum; } } frame.endStep(); }
public static void exec(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope) { #if DEBUG #region 函数调用检查 现基本不需要了 // RunTimeValueBase rv;rtFunction toclear = null; //if (step.arg1 is MethodGetterBase) //{ // rv = ((MethodGetterBase)step.arg1).getMethod(frame.scope); toclear = (rtFunction)rv; //} //else //{ // rv = step.arg1.getValue(frame.scope, frame); //} // if (rv.rtType == frame.player.swc.FunctionClass.getRtType()) // { // rv = TypeConverter.ObjectImplicit_ToPrimitive((rtObject)rv); // } // if (rv.rtType > RunTimeDataType.unknown && ClassMemberFinder.check_isinherits(rv, RunTimeDataType._OBJECT + 2, frame.player.swc)) // { // //***说明要调用强制类型转换*** // ASBinCode.rtti.Class cls = ((rtObject)rv).value._class; // if (frame.typeconvertoperator == null || frame.typeconvertoperator.targettype != cls // ) // { // frame.throwError(new error.InternalError(frame.player.swc, step.token, "应该是强制类型转换,内部异常")); // frame.endStep(step); // return; // } // else if (frame.typeconvertoperator.inputvalue == null) // { // frame.throwError(step.token,0, "Argument count mismatch on class coercion. Expected 1, got 0." // ); // frame.endStep(step); // return; // } // } // else // { // if (rv.rtType != RunTimeDataType.rt_function) // { // frame.throwError(step.token,0, "value is not a function" // ); // frame.endStep(step); // return; // } // ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv; // ASBinCode.rtti.FunctionDefine funcDefine = frame.player.swc.functions[function.functionId]; // if (!frame.funCaller.isFuncEquals(function)) // { // if (toclear != null) { toclear.Clear(); } // frame.throwError(new error.InternalError(frame.player.swc, step.token, "运行时异常,调用函数不对")); // frame.endStep(step); // return; // } // } #endregion #endif if (frame.typeconvertoperator == null) { var funCaller = frame.funCaller; funCaller.callbacker = funCaller; funCaller.returnSlot = step.reg.getSlot(frame.scope, frame); funCaller.call(); frame.funCaller = null; } else { if (frame.typeconvertoperator.targettype.instanceClass == null) { frame.throwError(new error.InternalError(frame.player.swc, step.token, "强制类型转换类型错误", new ASBinCode.rtData.rtString("强制类型转换类型错误"))); frame.endStep(step); return; } else { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.step = step; cb.args = frame; cb.setCallBacker(_convert_cb); OpCast.CastValue(frame.typeconvertoperator.inputvalue, frame.typeconvertoperator.targettype.instanceClass.getRtType(), frame, step.token, frame.scope, step.reg.getSlot(frame.scope, frame), cb, false); frame.typeconvertoperator = null; } } }
public static void exec_try_read_prop(StackFrame frame, OpStep step, RunTimeScope scope) { ASBinCode.SLOT slot = ((StackSlotAccessor)step.arg1).getSlot(scope,frame); if (slot.isPropGetterSetter) { ((StackSlot)slot).linkTo(null); _do_prop_read( ((StackSlot)slot).stackObjects.propGetSet, frame,step,frame.player,scope,((StackSlot)slot).stackObjects.propBindObj,((StackSlot)slot).stackObjects.superPropBindClass ); } else if (slot.isSetThisItem) { SetThisItemSlot sslot = (SetThisItemSlot)((StackSlot)slot).getLinkSlot(); ((StackSlot)slot).linkTo(null); //***调用索引器get*** RunTimeValueBase func; var rtObj = sslot.bindObj; var player = frame.player; var v2 = sslot.setindex; func = ((MethodGetterBase)sslot.get_this_item.bindField).getMethod( rtObj ); var funCaller = player.funcCallerPool.create(frame,step.token); funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } //funCaller.releaseAfterCall = true; bool success; funCaller.pushParameter(v2,0,out success); if (!success) { frame.endStep(step); return; } funCaller._tempSlot = frame._tempSlot1; funCaller.returnSlot = step.reg.getSlot(scope,frame); StackSlot ret = (StackSlot)funCaller.returnSlot; ret.stackObjects._temp_try_write_setthisitem = ret._cache_setthisslot; ret.refPropChanged = true; ret._cache_setthisslot.bindObj = rtObj; ret._cache_setthisslot.setindex = v2; ret._cache_setthisslot.set_this_item = sslot.set_this_item; BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_get_this_item_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; } else { SLOT regslot = step.reg.getSlot(scope,frame); StackSlot d = regslot as StackSlot; StackSlot s = slot as StackSlot; if (d != null && s != null && s.getLinkSlot() != null) { d.linkTo(s.getLinkSlot()); s.linkTo(null); } else { regslot.directSet(slot.getValue()); } //frame.endStep(step); frame.endStepNoError(); } }
public static void _doPropAssigning(ClassPropertyGetter prop,StackFrame frame, OpStep step,Player player,RunTimeScope scope, ASBinCode.rtData.rtObjectBase bindobj,RunTimeValueBase v,StackSlot sslot) { do { if (prop.setter == null) { frame.throwError( step.token,0,"Illegal write to read-only property " ); break; } //检查访问权限 CodeBlock block = player.swc.blocks[scope.blockId]; Class finder; if (block.isoutclass) { var c = prop._class; if (c.instanceClass != null) { c = c.instanceClass; } if (c.mainClass != null) { c = c.mainClass; } if (block.define_class_id == c.classid) { finder = player.swc.classes[block.define_class_id]; } else { finder = null; } } else { finder = player.swc.classes[block.define_class_id]; } var setter = ClassMemberFinder.find(prop._class,prop.setter.name,finder); if (setter == null || setter.bindField != prop.setter) { frame.throwError( step.token,0,"Illegal write to read-only property " ); break; } //***读取setter*** RunTimeValueBase func; if (sslot.stackObjects.superPropBindClass != null) { func = ((MethodGetterBase)setter.bindField).getSuperMethod( bindobj.objScope, sslot.stackObjects.superPropBindClass ); } else { func = ((MethodGetterBase)setter.bindField).getMethod( bindobj ); } //***调用设置器*** var funCaller = frame.player.funcCallerPool.create(frame,step.token); funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } //funCaller.releaseAfterCall = true; bool success; funCaller.pushParameter(v,0,out success); if (!success) { frame.endStep(step); return; } funCaller._tempSlot = frame._tempSlot1; funCaller.returnSlot = frame._tempSlot1; BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(_assign_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; } while (false); frame.endStep(step); }
public static void execAssigning(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { ASBinCode.SLOT slot = step.reg.getSlotForAssign(scope,frame); ASBinCode.RunTimeValueBase v = step.arg1.getValue(scope,frame); bool success; var lt = slot.assign(v,out success); if (!success) //(!slot.directSet(v)) { if (!(slot is StackSlot)) //直接赋值时 { //ext = "Illegal assignment to function " + ((MethodGetterBase)step.reg).name + "."; } else { StackSlot oslot = (StackSlot)slot; //if (oslot.linktarget != null) { //slot = oslot.linktarget; slot = lt; } if (step.arg1 is IMemReg) { //将其暂存到临时槽内 frame._tempSlot2.directSet(v); v = frame._tempSlot2.getValue(); } if (slot is SetThisItemSlot) { _doSetThisItem(((SetThisItemSlot)slot).bindObj,v,((SetThisItemSlot)slot).setindex,oslot,frame,step); return; } if (slot is ClassPropertyGetter.PropertySlot) { ClassPropertyGetter.PropertySlot propslot = (ASBinCode.ClassPropertyGetter.PropertySlot)slot; //***调用访问器。*** ASBinCode.ClassPropertyGetter prop = oslot.stackObjects.propGetSet; //propslot.property; _doPropAssigning(prop,frame,step,frame.player,scope, //propslot.bindObj oslot.stackObjects.propBindObj ,v, oslot ); return; } if (slot is OpVector.vectorSLot) //Vector类型不匹配 { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.scope = scope; cb.step = step; cb.args = frame; cb.setCallBacker(_vectorConvertCallBacker); cb.cacheObjects[0] = slot; //***调用强制类型转换*** OpCast.CastValue(v,((OpVector.vectorSLot)slot).vector_data.vector_type, frame,step.token,scope,frame._tempSlot1,cb,false); return; } if (slot is ObjectMemberSlot && !((ObjectMemberSlot)slot).isConstMember) { BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.scope = scope; cb.step = step; cb.args = frame; cb.setCallBacker(_objectmemberslotConvertCallbacker); cb.cacheObjects[0] = slot; //***调用强制类型转换*** OpCast.CastValue(v,((ObjectMemberSlot)slot).slottype, frame,step.token,scope,frame._tempSlot1,cb,false); return; } } string ext = String.Empty; if (slot is MethodGetterBase.MethodSlot) { ext = "Cannot assign to a method "; // + ((ASBinCode.ClassMethodGetter.MethodSlot)slot).method; } else if (slot is ObjectMemberSlot) { ext = "Illegal write to read-only property "; //+ ((ObjectMemberSlot)slot).obj.value._class.name //+" on ppp.PPC." } else if (slot is ClassPropertyGetter.PropertySlot) { ext = "Illegal write to read-only property "; } else if (slot is OpAccess_Dot.prototypeSlot) { ext = "Cannot create property " + ((OpAccess_Dot.prototypeSlot)slot)._protoname + " on " + ((OpAccess_Dot.prototypeSlot)slot)._protoRootObj.value._class.name; } frame.throwError( step.token,0,ext ); frame.endStep(step); } else { frame.endStepNoError(); } }
public static void _do_prop_read( ClassPropertyGetter prop,StackFrame frame,OpStep step,Player player,RunTimeScope scope, ASBinCode.rtData.rtObjectBase propBindObj,Class superPropBindClass ) { do { //***调用访问器。*** if (prop.getter == null) { frame.throwError( step.token,0,"Illegal read of write-only property" ); break; } //检查访问权限 CodeBlock block = player.swc.blocks[scope.blockId]; Class finder; if (block.isoutclass) { var c = prop._class; if (c.instanceClass != null) { c = c.instanceClass; } if (c.mainClass != null) { c = c.mainClass; } if (block.define_class_id == c.classid) { finder = player.swc.classes[block.define_class_id]; } else { finder = null; } } else { finder = player.swc.classes[block.define_class_id]; } var getter = ClassMemberFinder.find(prop._class,prop.getter.name,finder); if (getter == null || getter.bindField != prop.getter) { frame.throwError( step.token,0,"Illegal read of write-only property" ); break; } //***读取getter*** RunTimeValueBase func; if (superPropBindClass != null) { func = ((MethodGetterBase)getter.bindField).getSuperMethod( //propslot.bindObj.objScope propBindObj.objScope, superPropBindClass ); } else { func = ((MethodGetterBase)getter.bindField).getMethod( //propslot.bindObj.objScope propBindObj ); } //***调用访问器*** var funCaller = player.funcCallerPool.create(frame,step.token); //funCaller.releaseAfterCall = true; funCaller.SetFunction((ASBinCode.rtData.rtFunction)func); ((ASBinCode.rtData.rtFunction)func).Clear(); funCaller.loadDefineFromFunction(); if (!funCaller.createParaScope()) { return; } funCaller._tempSlot = frame._tempSlot1; funCaller.returnSlot = step.reg.getSlot(scope,frame); ((StackSlot)funCaller.returnSlot).stackObjects.propGetSet = prop; ((StackSlot)funCaller.returnSlot).refPropChanged = true; ((StackSlot)funCaller.returnSlot).stackObjects.propBindObj = propBindObj; BlockCallBackBase cb = frame.player.blockCallBackPool.create(); cb.setCallBacker(D_getter_callbacker); cb.step = step; cb.args = frame; funCaller.callbacker = cb; funCaller.call(); return; } while (false); frame.endStep(step); }