private static void _convertCB(BlockCallBackBase sender, object args) { object[] a = (object[])sender.args; if (sender.isSuccess) { ASBinCode.rtti.Vector_Data vd = (ASBinCode.rtti.Vector_Data)a[0]; var v = ((StackFrame)a[5])._tempSlot1.getValue().Clone(); //必须Clone var list = (List <RunTimeValueBase>)a[1]; vd.innnerList.Add((RunTimeValueBase)v); sender._intArg = sender._intArg + 1; if (sender._intArg >= list.Count) { IBlockCallBack cb = (IBlockCallBack)a[4]; cb.call(cb.args); } else { OpCast.CastValue(list[sender._intArg], vd.vector_type, (StackFrame)a[5], (SourceToken)a[2], (RunTimeScope)a[3], ((StackFrame)a[5])._tempSlot1, sender, false); } } }
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 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(); }
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 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; } } }