public static void prepareConstructorClassArgements(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope) { var rv = step.arg1.getValue(scope, frame); if (rv.rtType > RunTimeDataType.unknown) { var player = frame.player; var _class = getClass(player, frame, step, scope); if (_class != null && !_class.no_constructor) { //frame.instanceCreator = new InstanceCreator(player, frame, step.token, _class); frame.activeInstanceCreator(step.token, _class); if (_class.constructor != null) { if (!frame.instanceCreator.prepareConstructorArgements()) { return; } } //if (_class.constructor != null) //{ // ASBinCode.rtti.FunctionDefine funcDefine = player.swc.functions[_class.constructor_functionid]; // ASBinCode.rtti.FunctionSignature signature = funcDefine.signature; // frame.funCaller = new FunctionCaller(player, frame, step.token); // frame.funCaller.toCallFunc = funcDefine; // frame.funCaller.createParaScope(); //} } else if (_class.isInterface) { frame.throwError(step.token, 0, _class.name + " Interfaces cannot be instantiated with the new operator."); } else { frame.throwError(step.token, 0, _class.name + " is not a constructor"); } } else { if (rv.rtType == RunTimeDataType.rt_function) { ASBinCode.rtData.rtFunction func = (ASBinCode.rtData.rtFunction)rv; if (func.ismethod) { frame.throwError(step.token, 0, "Method cannot be used as a constructor." ); } else { //***创建一个Object对象,创建完毕之后,使用此函数执行初始化。将此对象作为此函数的this指针执行一次。 OpCast.Primitive_to_Object((ASBinCode.rtData.rtFunction)rv, frame, step.token, scope, frame._tempSlot1, step, _func_ToObj ); return; } } else { frame.throwCastException(step.token, rv.rtType, RunTimeDataType.rt_function); //new error.InternalError( step.token,"原始类型转对象未实现",new ASBinCode.rtData.rtString("原始类型转对象未实现") )); } } frame.endStep(step); }
public override void executeAsync(RunTimeValueBase thisObj,SLOT[] argements,SLOT resultSlot, object callbacker, object stackframe, SourceToken token,RunTimeScope scope) { //base.executeAsync(thisObj, argements, resultSlot, callbacker, stackframe, token, scope); var thisArg = argements[0].getValue(); rtFunction func = (rtFunction)((rtObjectBase)thisObj).value.memberData[0].getValue(); rtFunction toApply = (rtFunction)func; //.Clone(); if (!func.ismethod) //方法无法更改this { if (!(thisArg is rtObjectBase)) { var player = ((StackFrame)stackframe).player; var objtype = thisArg.rtType; if (objtype < RunTimeDataType.unknown && player.swc.primitive_to_class_table[objtype] != null ) { FunctionCaller toInsertStack = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token); toInsertStack.callbacker = (IBlockCallBack)callbacker; toInsertStack.SetFunction(toApply); toInsertStack._tempSlot = ((StackFrame)stackframe)._tempSlot1; toInsertStack.returnSlot = resultSlot; toInsertStack.tag = argements; stackCallers.Push(toInsertStack); //***转换为对象*** OpCast.Primitive_to_Object(thisArg,(StackFrame)stackframe,token,scope, ((StackFrame)stackframe)._tempSlot1, null,_primitive_toObj); return; } else { var fd = player.swc.functions[toApply.functionId]; var block = player.swc.blocks[fd.blockid]; //if (block.isoutclass )将this复位 { var oc = player.outpackage_runtimescope[block.define_class_id]; toApply.setThis(oc.this_pointer); } //else //{ // caller.function.setThis(null); //} } } else { toApply.setThis((rtObjectBase)thisArg); } } FunctionCaller caller = ((StackFrame)stackframe).player.funcCallerPool.create((StackFrame)(stackframe),token); caller.callbacker = (IBlockCallBack)callbacker; caller.SetFunction(toApply); caller._tempSlot = ((StackFrame)stackframe)._tempSlot1; caller.returnSlot = resultSlot; caller.loadDefineFromFunction(); if (!caller.createParaScope()) { return; } if (argements[1].getValue().rtType == RunTimeDataType.rt_array) { rtArray argArray = (rtArray)argements[1].getValue(); for (int i = 0; i < argArray.innerArray.Count; i++) { bool success; caller.pushParameter(argArray.innerArray[i],i,out success); } } caller.call(); }