public static OperatorFunctions LoadOperatorFunctions(BinaryReader reader, CSWCSerizlizer serizlizer, IDictionary <int, object> serizlized, int key) { OperatorFunctions operatorFunctions = new OperatorFunctions(); serizlized.Add(key, operatorFunctions); for (int i = 0; i < operatorFunctions.operFunctions.Length; i++) { var dict = operatorFunctions.operFunctions[i]; int count = reader.ReadInt32(); for (int j = 0; j < count; j++) { RunTimeDataType v1 = reader.ReadInt32(); RunTimeDataType v2 = reader.ReadInt32(); OperatorFunctionKey operatorFunctionKey = new OperatorFunctionKey(v1, v2); rtti.FunctionDefine define = serizlizer.DeserializeObject <rtti.FunctionDefine>(reader, rtti.FunctionDefine.LoadFunctionDefine); rtData.rtFunction function = serizlizer.DeserializeObject <rtData.rtFunction>(reader, RunTimeValueBase.LoadRunTimeValueBase); DefineAndFunc defineAndFunc = new DefineAndFunc(); defineAndFunc.define = define; defineAndFunc.func = function; dict.Add(operatorFunctionKey, defineAndFunc); } } return(operatorFunctions); }
public sealed override object Clone() { rtFunction result = new rtFunction(_functionid, _ismethod, _objid); result.CopyFrom(this); return(result); }
//public override RunTimeValueBase execute(RunTimeValueBase thisObj, SLOT[] argements, object stackframe, out string errormessage, out int errorno) //{ // errormessage = null; // errorno = 0; // if (argements[0].getValue().rtType == RunTimeDataType.rt_null) // { // return ASBinCode.rtData.rtBoolean.False; // } // else // { // ASBinCode.rtData.rtFunction f = (ASBinCode.rtData.rtFunction)argements[0].getValue(); // if (f.ismethod) // { // return ASBinCode.rtData.rtBoolean.True; // } // else // { // return ASBinCode.rtData.rtBoolean.False; // } // } //} public override void execute3(RunTimeValueBase thisObj, FunctionDefine functionDefine, SLOT returnSlot,SourceToken token,StackFrame stackframe,out bool success) { //errormessage = null; //errorno = 0; success = true; if (argements[0].rtType == RunTimeDataType.rt_null) { //return ASBinCode.rtData.rtBoolean.False; returnSlot.directSet(rtBoolean.False); } else { ASBinCode.rtData.rtFunction f = (ASBinCode.rtData.rtFunction)argements[0]; if (f.ismethod) { //return ASBinCode.rtData.rtBoolean.True; returnSlot.directSet(rtBoolean.True); } else { //return ASBinCode.rtData.rtBoolean.False; returnSlot.directSet(rtBoolean.False); } } //throw new NotImplementedException(); }
public override bool Equals(object obj) { rtFunction right = obj as rtFunction; if (right == null) { return(false); } if (_ismethod == right._ismethod && _functionid == right.functionId) { if (_ismethod) { return(Equals(this_pointer, right.this_pointer)); //this_pointer.Equals(right.this_pointer); } else { return(_objid == right._objid); } } else { return(false); } }
private static void _do_clear_thispointer(Player player, ASBinCode.rtData.rtFunction function, StackFrame frame, RunTimeValueBase outscope) { if (!function.ismethod) { function.setThis(outscope); } }
public void CopyFrom(rtFunction right) { _objid = right._objid; _functionid = right._functionid; _bindScope = right._bindScope; _ismethod = right._ismethod; _this_pointer = right._this_pointer; objHandle = right.objHandle; wapperContainer = right.wapperContainer; }
//class funbacker : IBlockCallBack //{ // public object args // { // get // ; // set // ; // } // public void call(object args) // { // object[] a = (object[])args; // ((StackFrame)a[0]).endStep((OpStep)a[1]); // } //} public static void exec_return(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope) { RunTimeValueBase result = step.arg1.getValue(frame.scope, frame); if (result.rtType == RunTimeDataType.rt_function) { ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)result; if (!function.ismethod)//闭包 { function.setThis(null); } } frame.returnSlot.directSet(result); frame.endStep(step); }
public static void exec_yieldreturn(StackFrame frame, OpStep step, RunTimeScope scope) { RunTimeValueBase result = step.arg1.getValue(scope, frame); if (result.rtType == RunTimeDataType.rt_function) { ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)result; if (!function.ismethod)//闭包 { function.setThis(null); } } scope.memberData[scope.memberData.Length - 2].directSet(new rtInt(frame.codeLinePtr + 1)); scope.memberData[scope.memberData.Length - 1].directSet(rtBoolean.True); frame.returnSlot.directSet(result); frame.endStep(step); //退出当前调用 *** yield语句不可能包含在try中,所以直接移动到最后一行退出即可 frame.codeLinePtr = frame.block.instructions.Length; }
public static bool isFunctionEqual(rtFunction fun1, rtFunction fun2) { return(fun1.Equals(fun2)); }
public static void bind(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope) { var rv = step.arg1.getValue(frame.scope, frame); if (rv.rtType != RunTimeDataType.rt_function) { frame.throwError( step.token, 0, "value is not a function"); frame.endStep(step); return; } else { ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv; if (function.bindScope == null || function.bindScope.blockId == frame.scope.blockId ) { function.bind(frame.scope); } if (!function.ismethod) { if (function.this_pointer == null) { var s = frame.scope; if (s.this_pointer != null && s.this_pointer is rtObjectBase) { rtObjectBase obj = (rtObjectBase)s.this_pointer; if (obj.value is Global_Object) { function.setThis(obj); } else { var cls = obj.value._class; if (cls.staticClass == null) { cls = cls.instanceClass; } if (cls.mainClass != null) { cls = cls.mainClass; } var ot = frame.player.outpackage_runtimescope[cls.classid]; function.setThis(ot.this_pointer); } } else { if (frame.player.infoOutput != null) { frame.player.infoOutput.Warring("当前函数没有this指针。也许不是从文档类启动,而是从包外代码启动的"); } } } } frame.endStepNoError(); } }
public static void create_paraScope(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope) { 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 > RunTimeDataType.unknown && ClassMemberFinder.check_isinherits(rv, RunTimeDataType._OBJECT + 2, frame.player.swc)) { //***说明要调用强制类型转换*** ASBinCode.rtti.Class cls = ((rtObjectBase)rv).value._class; if (frame.typeconvertoperator != null) { frame.endStepNoError(); //frame.endStep(step); return; } else if (frame.typeconvertoperator.targettype.instanceClass == null || frame.typeconvertoperator.targettype != cls ) { frame.throwError(new error.InternalError(frame.player.swc, step.token, "类型转换函数发现内部错误" )); frame.endStep(step); return; } } if (rv.rtType == frame.player.swc.FunctionClass.getRtType()) { rv = TypeConverter.ObjectImplicit_ToPrimitive((rtObjectBase)rv); } if (rv.rtType != RunTimeDataType.rt_function) { frame.throwError(step.token, 0, "value is not a function"); frame.endStep(step); } else { ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv; var funcCaller = frame.player.funcCallerPool.create(frame, step.token); funcCaller.SetFunction(function); if (toclear != null) { toclear.Clear(); } funcCaller._tempSlot = frame._tempSlot1; funcCaller.loadDefineFromFunction(); if (!funcCaller.createParaScope()) { return; } frame.funCaller = funcCaller; frame.endStepNoError(); } }
public static void clear_thispointer(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope) { RunTimeValueBase rv; rtFunction toclear = null; if (step.arg1 is MethodGetterBase) { rv = ((ClassMethodGetter)step.arg1).getMethodForClearThis(frame.scope); toclear = (rtFunction)rv; } else { rv = step.arg1.getValue(frame.scope, frame); } if (rv.rtType > RunTimeDataType.unknown && ClassMemberFinder.check_isinherits(rv, RunTimeDataType._OBJECT + 2, frame.player.swc)) { //***说明要调用强制类型转换*** ASBinCode.rtti.Class cls = ((rtObjectBase)rv).value._class; if (cls.explicit_from != null) { var member = (MethodGetterBase)cls.explicit_from.bindField; var func = member.getValue(((rtObjectBase)rv).objScope, null); step.reg.getSlot(scope, frame).directSet(func); } else if (cls.implicit_from != null) { var member = (MethodGetterBase)cls.implicit_from.bindField; var func = member.getValue(((rtObjectBase)rv).objScope, null); step.reg.getSlot(scope, frame).directSet(func); } else { frame.typeconvertoperator = new typeConvertOperator(); frame.typeconvertoperator.targettype = cls; step.reg.getSlot(scope, frame).directSet(rv); } if (toclear != null) { toclear.Clear(); } frame.endStepNoError(); //frame.endStep(step); return; } if (rv.rtType != RunTimeDataType.rt_function) { frame.throwError( step.token, 0, "value is not a function"); if (toclear != null) { toclear.Clear(); } frame.endStep(step); return; } else { ASBinCode.rtData.rtFunction function = (ASBinCode.rtData.rtFunction)rv; step.reg.getSlot(scope, frame).directSet(rv); if (!function.ismethod) { int classid = ((ASBinCode.rtData.rtInt)step.arg2.getValue(scope, frame)).value; RunTimeScope o; if (frame.player.outpackage_runtimescope.TryGetValue(classid, out o)) { _do_clear_thispointer(frame.player, (ASBinCode.rtData.rtFunction)step.reg.getValue(scope, frame), frame, o.this_pointer); } } if (toclear != null) { toclear.Clear(); } frame.endStepNoError(); } }