public bool prepareConstructorArgements()
        {
            int classid = _class.classid;


            ASBinCode.rtti.FunctionDefine    funcDefine = player.swc.functions[player.swc.classes[classid].constructor_functionid];
            ASBinCode.rtti.FunctionSignature signature  = funcDefine.signature;

            constructorCaller            = player.funcCallerPool.create(invokerFrame,token);
            constructorCaller.toCallFunc = funcDefine;
            constructorCaller._tempSlot  = invokerFrame._tempSlot1;
            if (!constructorCaller.createParaScope())
            {
                return(false);
            }

            //constructorCaller.releaseAfterCall = true;

            if (constructor != null)
            {
                _function_constructor            = player.funcCallerPool.create(invokerFrame,token);
                _function_constructor._tempSlot  = invokerFrame._tempSlot1;
                _function_constructor.toCallFunc =
                    player.swc.functions[((ASBinCode.rtData.rtFunction)
                                          TypeConverter.ObjectImplicit_ToPrimitive(constructor)).functionId];

                if (!_function_constructor.createParaScope())
                {
                    return(false);
                }

                //_function_constructor.releaseAfterCall = true;
            }
            return(true);
        }
Пример #2
0
        public static void execBitOR(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope)
        {
            ASBinCode.RunTimeValueBase v1 = step.arg1.getValue(scope, frame);
            ASBinCode.RunTimeValueBase v2 = step.arg2.getValue(scope, frame);

            var f = frame.player.swc.operatorOverrides.getOperatorFunction(OverrideableOperator.bitOr,
                                                                           v1.rtType, v2.rtType);

            if (f != null)
            {
                FunctionCaller fc = frame.player.funcCallerPool.create(frame, step.token);
                fc.SetFunction(f);
                fc.loadDefineFromFunction();
                if (!fc.createParaScope())
                {
                    return;
                }
                //fc.releaseAfterCall = true;

                bool success;
                fc.pushParameter(v1, 0, out success);
                fc.pushParameter(v2, 1, out success);
                fc.returnSlot = step.reg.getSlot(scope, frame);
                fc.callbacker = fc;
                fc.call();
            }
            else
            {
                OpCast.InvokeTwoValueOf(v1, v2, frame, step.token, scope, frame._tempSlot1, frame._tempSlot2, step, _BitOR_ValueOf_CallBacker);
            }
        }
        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;
            }
        }
        private static void check_para_failed(BlockCallBackBase sender,object args)
        {
            FunctionCaller caller = (FunctionCaller)sender.cacheObjects[0];

            //清理栈
            clear_para_slot(caller.invokerFrame,caller.onstackparametercount); caller.onstackparametercount = 0;
            if (caller.callbacker != null)
            {
                caller.callbacker.noticeRunFailed();
            }
            caller.release();
        }
Пример #5
0
        public static void execAdd(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope)
        {
            ASBinCode.RunTimeValueBase v1 = step.arg1.getValue(scope, frame);
            ASBinCode.RunTimeValueBase v2 = step.arg2.getValue(scope, frame);

            var f = frame.player.swc.operatorOverrides.getOperatorFunction(OverrideableOperator.addition,
                                                                           v1.rtType, v2.rtType);

            if (f != null)
            {
                FunctionCaller fc = frame.player.funcCallerPool.create(frame, step.token);
                fc.SetFunction(f);
                fc.loadDefineFromFunction();
                if (!fc.createParaScope())
                {
                    return;
                }

                //fc.releaseAfterCall = true;

                bool success;
                fc.pushParameter(v1, 0, out success);
                fc.pushParameter(v2, 1, out success);
                fc.returnSlot = step.reg.getSlot(scope, frame);
                fc.callbacker = fc;
                fc.call();
            }
            else if (
                (v1.rtType > ASBinCode.RunTimeDataType.unknown && v2.rtType > ASBinCode.RunTimeDataType.unknown)
                ||
                v1.rtType == ASBinCode.RunTimeDataType.rt_int
                ||
                v1.rtType == ASBinCode.RunTimeDataType.rt_uint
                ||
                v1.rtType == ASBinCode.RunTimeDataType.rt_number
                ||
                v2.rtType == ASBinCode.RunTimeDataType.rt_int
                ||
                v2.rtType == ASBinCode.RunTimeDataType.rt_uint
                ||
                v2.rtType == ASBinCode.RunTimeDataType.rt_number
                )
            {
                OpCast.InvokeTwoValueOf(v1, v2, frame, step.token, scope,
                                        frame._tempSlot1, frame._tempSlot2, step, _execAdd_CallBacker);
            }
            else //toString
            {
                OpCast.InvokeTwoToString(v1, v2, frame, step.token, scope,
                                         frame._tempSlot1, frame._tempSlot2, step, _execAdd_InvokeToString_CallBacker);
            }
        }
        public static bool create_paraScope_WithSignature_AllParaOnStack(StackFrame frame, ASBinCode.OpStep step, RunTimeScope scope)
        {
            rtFunction function
                = (rtFunction)step.arg1.getValue(frame.scope, frame);

            var functionDefine = frame.player.swc.functions[function.functionId];

            if (frame.baseBottomSlotIndex + frame.call_parameter_slotCount + functionDefine.signature.onStackParameters >= Player.STACKSLOTLENGTH)
            {
                frame.throwError(new error.InternalError(frame.player.swc, step.token, "stack overflow"));
                frame.endStep();
                return(false);
            }

            var funcCaller = frame.player.funcCallerPool.create(frame, step.token);

            funcCaller.SetFunction(function); function.Clear();
            funcCaller.toCallFunc = functionDefine;
            frame.funCaller       = funcCaller;

            frame.call_parameter_slotCount  += functionDefine.signature.onStackParameters;
            funcCaller.onstackparametercount = functionDefine.signature.onStackParameters;
            funcCaller.CallFuncHeap          = Player.emptyMembers;

            var parameters = functionDefine.signature.parameters; int len = parameters.Count; int parast = frame.baseBottomSlotIndex + frame.call_parameter_slotCount;

            for (int i = step.jumoffset; i < len; i++)
            {
                var parameter = parameters[i];
                if (parameter.defaultValue != null)
                {
                    var dv = FunctionCaller.getDefaultParameterValue(parameter.type, parameter.defaultValue.getValue(null, null));

                    frame.stack[parast - i - 1].directSet(dv);
                    //_storeArgementToSlot(i, dv);
                }
                else if (parameter.isPara)
                {
                    frame.stack[parast - i - 1].directSet(new ASBinCode.rtData.rtArray());
                    //_storeArgementToSlot(i, new ASBinCode.rtData.rtArray());
                }
            }



            frame.endStepNoError();
            return(true);
        }
 private static void check_para_callbacker(BlockCallBackBase sender,object args)
 {
     if (sender.isSuccess)
     {
         FunctionCaller caller = (FunctionCaller)sender.cacheObjects[0];
         //CallFuncHeap[sender._intArg].directSet(_tempSlot.getValue());
         caller.setCheckedParameter(sender._intArg,caller._tempSlot.getValue());
         caller.check_para(sender);
     }
     else
     {
         throw new ASRunTimeException("解释器内部错误,参数类型检查",string.Empty);
         //invokerFrame.throwCastException(token, ((RunTimeValueBase)sender.args).rtType, toCallFunc.signature.parameters[sender._intArg].type);
         //return;
     }
 }
        public void clear()
        {
            token             = null;
            _class            = null;
            step              = null;
            callbacker        = null;
            constructorCaller = null;
            objectResult      = null;

            constructor           = null;
            _function_constructor = null;
            objectStoreToSlot     = null;

            toNoticeFailed1 = null;
            toNoticeFailed2 = null;


            tempSlot.directSet(ASBinCode.rtData.rtUndefined.undefined);
        }
Пример #9
0
        public static void execNeg(StackFrame frame, ASBinCode.OpStep step, ASBinCode.RunTimeScope scope)
        {
            ASBinCode.RunTimeValueBase v = step.arg1.getValue(scope, frame);

            if (v.rtType != ASBinCode.RunTimeDataType.rt_number)
            {
                var f = frame.player.swc.operatorOverrides.getOperatorFunction(OverrideableOperator.Unary_negation,
                                                                               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
                {
                    OpCast.InvokeTwoValueOf(v, ASBinCode.rtData.rtNull.nullptr, frame, step.token, scope, frame._tempSlot1, frame._tempSlot2, step, _execNeg_ValueOf_Callbacker);
                }
            }
            else
            {
                step.reg.getSlot(scope, frame).setValue(-((ASBinCode.rtData.rtNumber)v).value);//new ASBinCode.rtData.rtNumber( -((ASBinCode.rtData.rtNumber)v).value));
                //frame.endStep(step);
                frame.endStepNoError();
            }
        }
        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 exec_step2(
            ASBinCode.rtti.Object obj,
            RunTimeScope objScope,ASBinCode.rtData.rtObjectBase _object)
        {
            //***添加Object的动态对象****
            if (
                //(obj._class.classid == 0)
                obj is DynamicObject &&
                obj._class.staticClass != null)
            {
                DynamicObject dobj = (DynamicObject)obj;

                if (constructor == null)
                {
                    dobj.createproperty("constructor",new DynamicPropertySlot(_object,false,player.swc.FunctionClass.getRtType()));
                    dobj["constructor"].directSet(player.static_instance[obj._class.staticClass.classid]);
                    dobj._prototype_ = (DynamicObject)player.static_instance[_class.staticClass.classid].value;
                }
                else
                {
                    dobj._prototype_ = (DynamicObject)constructor.value;
                }
            }

            ClassMember ctor = obj._class.constructor;

            //if (obj._class.isCrossExtend)
            //{
            //	//***创建Adapter***
            //	var scls = obj._class.super;
            //	while (!scls.isLink_System)
            //	{
            //		scls = scls.super;
            //	}

            //	ctor = scls.crossExtendAdapterCreator;

            //	var nf = player.swc.getNativeFunction(((MethodGetterBase)ctor.bindField).functionId);
            //	if (!(nf is ICrossExtendAdapterCreator))
            //	{
            //		invokerFrame.throwAneException(token, "adapter不是ICrossExtendAdapterCreator");
            //		callbacker.noticeRunFailed();
            //		noticeWhenCreateAneFailed();
            //		invokerFrame.endStep();
            //		return;

            //	}

            //	constructorCaller.toCallFunc =  player.swc.functions[((MethodGetterBase)ctor.bindField).functionId];

            //}


            //调用构造函数
            if (ctor != null)
            {
                ASBinCode.rtData.rtFunction function =
                    (ASBinCode.rtData.rtFunction)((MethodGetterBase)ctor.bindField).getConstructor(objScope);


                HeapSlot _temp = tempSlot;
                constructorCaller.returnSlot = _temp;
                constructorCaller.SetFunction(function); function.Clear();


                //afterCallConstructor callbacker = new afterCallConstructor();
                var callbacker = player.blockCallBackPool.create();
                callbacker.args = this;
                //callbacker.obj = obj;
                //callbacker.objScope = objScope;
                //callbacker.rtObject = _object;
                callbacker.cacheObjects[0] = _object;
                callbacker.setWhenFailed(creatorFailed);
                callbacker.setCallBacker(afterCallConstructorCallbacker);


                constructorCaller.callbacker = callbacker;

                toNoticeFailed2 = callbacker;
                constructorCaller.call();
                toNoticeFailed2 = null;

                constructorCaller = null;
            }
            else
            {
                exec_step3(_object);
            }
        }