コード例 #1
0
        public string getStackTrace()
        {
            if (errorValue != null)
            {
                string errinfo = string.Empty;
                if (errorValue.rtType > RunTimeDataType.unknown && swc.ErrorClass != null)
                {
                    if (ClassMemberFinder.check_isinherits(errorValue, swc.ErrorClass.getRtType(), swc))
                    {
                        errinfo =
                            ((rtObjectBase)errorValue).value.memberData[3].getValue().ToString();
                    }
                }
                else if (callStack != null)
                {
                    StringBuilder sb = new StringBuilder();

                    var toget = new List <ASRuntime.FrameInfo>(callStack);
                    toget.Reverse();

                    foreach (var item in toget)
                    {
                        if (item.block.instructions.Length == 0)
                        {
                            continue;
                        }

                        if (item.codeLinePtr < item.block.instructions.Length)
                        {
                            sb.Append("\tat ");
                            sb.Append(item.block.name);
                            sb.Append(" [");
                            sb.Append(item.block.instructions[item.codeLinePtr].token.sourceFile);
                            sb.Append(" ");
                            sb.Append(item.block.instructions[item.codeLinePtr].token.line + 1);
                            sb.Append(" ptr:");
                            sb.Append(item.block.instructions[item.codeLinePtr].token.ptr + 1);
                            sb.Append("]");
                            sb.AppendLine();
                        }
                        else
                        {
                            sb.Append("\tat ");
                            sb.AppendLine(item.block.name);
                        }
                    }



                    errinfo = sb.ToString();
                }

                return("\t" + errinfo);
            }
            else
            {
                return(string.Empty);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 public override SLOT assign(RunTimeValueBase value,out bool success)
 {
     if (slottype != value.rtType && slottype != RunTimeDataType.rt_void
         &&
         !
         (
             //***检查子类关系****
             (slottype > RunTimeDataType.unknown &&
              value.rtType > RunTimeDataType.unknown &&
              (
                  ClassMemberFinder.check_isinherits(value,slottype,classfinder)
                  ||
                  ClassMemberFinder.check_isImplements(value,slottype,classfinder)
              )
             )
             ||
             (
                 slottype > RunTimeDataType.unknown &&
                 value.rtType == RunTimeDataType.rt_null
             )
             ||
             (
                 slottype == RunTimeDataType.rt_array &&
                 value.rtType == RunTimeDataType.rt_null
             )
             ||
             (
                 slottype == RunTimeDataType.rt_function &&
                 value.rtType == RunTimeDataType.rt_null
             )
             ||
             (
                 slottype == RunTimeDataType.rt_string &&
                 value.rtType == RunTimeDataType.rt_null
             )
         )
         )
     {
         //return false;
         success = false;
         return(this);
     }
     else
     {
         success = directSet(value);
         return(this);
     }
 }
コード例 #4
0
        public override RunTimeValueBase execute(RunTimeValueBase thisObj,SLOT[] argements,object stackframe,out string errormessage,out int errorno)
        {
            errormessage = null;
            errorno      = 0;

            string name = TypeConverter.ConvertToString(argements[0].getValue(),null,null);

            if (String.IsNullOrEmpty(name))
            {
                return(ASBinCode.rtData.rtBoolean.False);
            }

            //固定实例属性 — 对象类定义的非静态变量、常量或方法;
            //继承的固定实例属性 — 对象类继承的变量、常量或方法;
            //动态属性 — 对象实例化后添加到其中的属性(在其类定义之外)。要添加动态属性,必须用 dynamic 关键字声明对象的定义类。

            //return new ASBinCode.rtData.rtString(TypeConverter.ConvertToString(thisObj, null, null));

            ASBinCode.rtData.rtObjectBase obj = (ASBinCode.rtData.rtObjectBase)thisObj;

            if (ClassMemberFinder.find(obj.value._class,name,null) != null)
            {
                return(ASBinCode.rtData.rtBoolean.True);
            }

            if (obj.value is ASBinCode.rtti.DynamicObject)
            {
                ASBinCode.rtti.DynamicObject d = (ASBinCode.rtti.DynamicObject)obj.value;

                if (d.hasproperty(name))
                {
                    return(ASBinCode.rtData.rtBoolean.True);
                }
                else
                {
                    return(ASBinCode.rtData.rtBoolean.False);
                }
            }
            return(ASBinCode.rtData.rtBoolean.False);
        }
コード例 #5
0
        public string getErrorInfo()
        {
            if (errorValue != null && swc != null)
            {
                string errinfo = errorValue.ToString();
                if (errorValue.rtType > RunTimeDataType.unknown && swc.ErrorClass != null)
                {
                    if (ClassMemberFinder.check_isinherits(errorValue, swc.ErrorClass.getRtType(), swc))
                    {
                        errinfo =
                            ((rtObjectBase)errorValue).value.memberData[1].getValue().ToString() + " #" +
                            ((rtObjectBase)errorValue).value.memberData[2].getValue().ToString() + " " +
                            ((rtObjectBase)errorValue).value.memberData[0].getValue().ToString();
                    }
                }


                return("[故障] " + "信息=" + errinfo);
            }
            else
            {
                return(message);
            }
        }
コード例 #6
0
        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();
        }
コード例 #7
0
        private static ASBinCode.rtti.Object createObject(CSWC swc,Class cls,InstanceCreator creator,
                                                          out ASBinCode.rtData.rtObjectBase rtObjectBase,
                                                          out ASBinCode.rtData.rtObjectBase linkrtobj,
                                                          out string errinfo
                                                          )
        {
            ASBinCode.rtti.Object obj = null;// = new ASBinCode.rtti.Object(cls);
            rtObjectBase = null; linkrtobj = null; errinfo = null;
            if (cls.isLink_System)
            {
                if (creator != null)
                {
                    StackSlot stackSlot = creator.objectStoreToSlot as StackSlot;
                    if (stackSlot != null)
                    {
                        rtObjectBase = stackSlot.getStackCacheObject(cls);
                        return(rtObjectBase.value);
                    }
                }


                var func = (NativeFunctionBase)swc.class_Creator[cls];

                string err; int no;
                ASBinCode.rtData.rtObjectBase rtObj =
                    func.execute(null,null,cls,out err,out no) as ASBinCode.rtData.rtObjectBase;
                linkrtobj = rtObj;
                if (rtObj == null)
                {
                    errinfo = cls.ToString() + " create linksystem object failed";
                    return(null);
                }
                else
                {
                    return(rtObj.value);
                }
            }
            else if (cls.isCrossExtend)
            {
                var scls = cls.super;
                while (!scls.isLink_System)
                {
                    scls = scls.super;
                }

                var cextend = scls.staticClass.linkObjCreator;
                var func    = swc.getNativeFunction(((ClassMethodGetter)cextend.bindField).functionId);

                if (func == null)
                {
                    errinfo = cls.ToString() + " create crossextend object failed, creator function not found";
                    return(null);
                }

                string err; int no;
                ASBinCode.rtData.rtObjectBase rtObj =
                    func.execute(null,null,cls,out err,out no) as ASBinCode.rtData.rtObjectBase;
                linkrtobj = rtObj;
                if (rtObj == null)
                {
                    errinfo = cls.ToString() + " create crossextend object failed";
                    return(null);
                }
                else
                {
                    LinkSystemObject lo = (LinkSystemObject)rtObj.value;
                    return(lo);
                }
            }
            else if (
                swc.DictionaryClass != null
                &&
                ClassMemberFinder.isInherits(cls,swc.DictionaryClass))
            {
                obj = new DictionaryObject(cls);
            }
            else if (cls.dynamic)
            {
                if (cls.isUnmanaged)
                {
                    obj = new HostedDynamicObject(cls);
                }
                else
                {
                    obj = new DynamicObject(cls);
                }
            }
            else if (cls.isUnmanaged)
            {
                obj = new HostedObject(cls);
            }
            else
            {
                obj = new ASBinCode.rtti.Object(cls);
            }

            return(obj);
        }
コード例 #8
0
ファイル: OpAssigning.cs プロジェクト: ikvm/ASTool
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        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();
            }
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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();
        }
コード例 #14
0
            public override SLOT assign(RunTimeValueBase value,out bool success)
            {
                if (vector_data.vector_type != value.rtType
                    &&
                    !
                    (
                        //***检查子类关系****
                        (vector_data.vector_type > RunTimeDataType.unknown &&
                         value.rtType > RunTimeDataType.unknown &&
                         (
                             ClassMemberFinder.check_isinherits(value,vector_data.vector_type,classfinder)
                             ||
                             ClassMemberFinder.check_isImplements(value,vector_data.vector_type,classfinder)
                         )
                        )
                        ||
                        (
                            vector_data.vector_type > RunTimeDataType.unknown &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_array &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_function &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_string &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                    )
                    )
                {
                    //return false;
                    success = false;
                    return(this);
                }
                else
                {
                    switch (value.rtType)
                    {
                    case RunTimeDataType.rt_int:
                    {
                        ((rtInt)vector_data.innnerList[idx]).value = ((rtInt)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_uint:
                    {
                        ((rtUInt)vector_data.innnerList[idx]).value = ((rtUInt)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_number:
                    {
                        ((rtNumber)vector_data.innnerList[idx]).value = ((rtNumber)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_string:
                    {
                        ((rtString)vector_data.innnerList[idx]).value = ((rtString)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_function:
                    {
                        ((rtFunction)vector_data.innnerList[idx]).CopyFrom((rtFunction)value);
                        success = true;
                        return(this);
                    }

                    default:
                        break;
                    }

                    if (value.rtType > RunTimeDataType.unknown)
                    {
                        var vd = vector_data.innnerList[idx];
                        if (vd != null)
                        {
                            var cls = classfinder.getClassByRunTimeDataType(value.rtType);
                            if (cls.isLink_System)
                            {
                                ASBinCode.rtti.LinkSystemObject link = (ASBinCode.rtti.LinkSystemObject)((rtObjectBase)vd).value;

                                if (cls.isStruct)
                                {
                                    link.CopyStructData((ASBinCode.rtti.LinkSystemObject)((rtObjectBase)value).value);
                                }
                                else
                                {
                                    ((rtObjectBase)vd).value = ((rtObjectBase)value).value;
                                }
                                success = true;
                                return(this);
                            }
                        }
                    }

                    vector_data.innnerList[idx] = (RunTimeValueBase)value.Clone();                     //对容器的直接赋值,需要Clone																				   //return true;
                    success = true;
                    return(this);
                }
            }
コード例 #15
0
        public static ASBinCode.IMember find(string name, CompileEnv env, bool isStaticMember, Builder builder, ASTool.Token token)
        {
            //List<IScope> findpath = new List<IScope>();
            //List<IScope> outscopes = new List<IScope>();//查找顺序,最后查找包外代码

            //Dictionary<IScope, ASBinCode.rtti.Class> finderclass = new Dictionary<IScope, ASBinCode.rtti.Class>();



            //{
            //    ASBinCode.rtti.Class defineClass = null;
            //    IScope s = env.block.scope;
            //    while (s !=null)
            //    {
            //        if (s is ASBinCode.scopes.ObjectInstanceScope)
            //        {
            //            ASBinCode.rtti.Class cls = ((ASBinCode.scopes.ObjectInstanceScope)s)._class;
            //            if (isStaticMember && cls.staticClass != null)
            //            {
            //                cls = cls.staticClass;
            //            }
            //            if (defineClass == null)
            //            {
            //                defineClass = cls;
            //                if (cls.mainClass != null)
            //                {
            //                    defineClass = cls.mainClass;
            //                }

            //            }
            //        }
            //        finderclass.Add(s,defineClass);

            //        if (s is ASBinCode.scopes.OutPackageMemberScope && !(ReferenceEquals(s,env.block.scope)))
            //        {
            //            outscopes.Add(s);

            //        }
            //        else
            //        {
            //            findpath.Add(s);
            //        }

            //        s = s.parentScope;
            //    }

            //    findpath.AddRange(outscopes);
            //}



            //ASBinCode.IScope scope = null;
            //for (int j = 0; j < findpath.Count; j++)
            //{
            //    scope = findpath[j];

            //    if (scope is ASBinCode.scopes.ObjectInstanceScope)
            //    {
            //        //查找类方法
            //        ASBinCode.rtti.Class cls = ((ASBinCode.scopes.ObjectInstanceScope)scope)._class;

            //        var fm = ASBinCode.ClassMemberFinder.find(cls, name, finderclass[scope]);
            //        if (fm != null)
            //        {
            //            return fm.bindField;
            //        }

            //    }

            //    if (!(scope is ASBinCode.scopes.OutPackageMemberScope)
            //        ||
            //        (
            //            finderclass[scope] == null
            //            ||
            //            ((ASBinCode.scopes.OutPackageMemberScope)scope).mainclass == finderclass[scope]
            //        )
            //        )
            //    {
            //        //从后往前找。可解决catch块同名变量e问题
            //        for (int i = scope.members.Count - 1; i >= 0; i--)
            //        {
            //            if (scope.members[i].name == name
            //                )
            //            {
            //                return scope.members[i].clone();
            //            }
            //        }
            //    }


            //}
            bool skipoutpackagescope = false;

            ASBinCode.rtti.Class defineClass = null;

            ASBinCode.IScope scope = env.block.scope;

            while (scope != null)
            {
                if (scope is ASBinCode.scopes.ObjectInstanceScope)
                {
                    //查找类方法
                    ASBinCode.rtti.Class cls = ((ASBinCode.scopes.ObjectInstanceScope)scope)._class;

                    if (defineClass == null)
                    {
                        defineClass = cls;
                    }

                    if (!isStaticMember && cls.staticClass == null)
                    {
                        defineClass         = defineClass.instanceClass;
                        skipoutpackagescope = true;
                        break;
                    }
                    else
                    {
                        var fm = ASBinCode.ClassMemberFinder.find(cls, name, defineClass);
                        if (fm != null)
                        {
                            return(fm.bindField);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                if (!(scope is ASBinCode.scopes.OutPackageMemberScope)
                    ||
                    (
                        defineClass == null
                        ||
                        ((ASBinCode.scopes.OutPackageMemberScope)scope).mainclass == defineClass
                    )
                    )
                {
                    //从后往前找。可解决catch块同名变量e问题
                    for (int i = scope.members.Count - 1; i >= 0; i--)
                    {
                        if (scope.members[i].name == name
                            )
                        {
                            return(scope.members[i].clone());
                        }
                    }
                }
                scope = scope.parentScope;
            }

            //***如果成员未找到,查找@__buildin__//
            if (!env.isEval)
            {
                var buildin = TypeReader.findClassFromImports("@__buildin__", builder, token);
                if (buildin.Count == 1)
                {
                    var bi = buildin[0].staticClass;

                    var member = ClassMemberFinder.find(bi, name, bi);
                    if (member != null && !(member.bindField is ClassPropertyGetter) && member.inheritFrom == null
                        &&
                        member.name != "Object"
                        )
                    {
                        FindStaticMember sm = new FindStaticMember();
                        sm.classMember  = member;
                        sm.static_class = new StaticClassDataGetter(bi);

                        return(sm);
                        //return member.bindField;
                    }
                }
            }

            //***在静态成员中查找***
            var findstaticclass = defineClass;


            while (findstaticclass != null && findstaticclass.staticClass != null)
            {
                var bi     = findstaticclass.staticClass;
                var member = ClassMemberFinder.find(bi, name, defineClass.staticClass);
                if (member != null)
                {
                    if (member != null && member.bindField is ClassPropertyGetter && name == "prototype")
                    {
                        throw new BuildException(token.line, token.ptr, token.sourceFile, "Access of possibly undefined property prototype.");
                    }

                    FindStaticMember sm = new FindStaticMember();
                    sm.classMember  = member;
                    sm.static_class = new StaticClassDataGetter(bi);


                    return(sm);
                    //return member.bindField;
                }
                findstaticclass = findstaticclass.super;
            }

            if (skipoutpackagescope)
            {
                return(null);
            }


            if (defineClass != null && defineClass.mainClass != null)
            {
                defineClass = defineClass.mainClass;
            }

            //***在包外代码中查找****
            if (defineClass != null && defineClass.staticClass != null)
            {
                IScope outpackagescope = null;

                if (defineClass.mainClass == null)
                {
                    outpackagescope =
                        builder._class_outScopeBlock[defineClass].scope;
                }
                else
                {
                    outpackagescope =
                        builder._class_outScopeBlock[defineClass.mainClass].scope;
                }

                for (int i = outpackagescope.members.Count - 1; i >= 0; i--)
                {
                    if (outpackagescope.members[i].name == name
                        )
                    {
                        //return outpackagescope.members[i].clone();
                        FindOutPackageScopeMember fo = new FindOutPackageScopeMember();
                        fo.member = outpackagescope.members[i].clone();


                        fo.outscopeclass = ((ASBinCode.scopes.OutPackageMemberScope)outpackagescope).mainclass;

                        return(fo);
                        //return fo;
                    }
                }
            }



            return(null);
        }
コード例 #16
0
ファイル: OpVector.cs プロジェクト: ikvm/ASTool
            public override SLOT assign(RunTimeValueBase value,out bool success)
            {
                if (vector_data.vector_type != value.rtType
                    &&
                    !
                    (
                        //***检查子类关系****
                        (vector_data.vector_type > RunTimeDataType.unknown &&
                         value.rtType > RunTimeDataType.unknown &&
                         (
                             ClassMemberFinder.check_isinherits(value,vector_data.vector_type,classfinder)
                             ||
                             ClassMemberFinder.check_isImplements(value,vector_data.vector_type,classfinder)
                         )
                        )
                        ||
                        (
                            vector_data.vector_type > RunTimeDataType.unknown &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_array &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_function &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                        ||
                        (
                            vector_data.vector_type == RunTimeDataType.rt_string &&
                            value.rtType == RunTimeDataType.rt_null
                        )
                    )
                    )
                {
                    //return false;
                    success = false;
                    return(this);
                }
                else
                {
                    switch (value.rtType)
                    {
                    case RunTimeDataType.rt_int:
                    {
                        ((rtInt)vector_data.innnerList[idx]).value = ((rtInt)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_uint:
                    {
                        ((rtUInt)vector_data.innnerList[idx]).value = ((rtUInt)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_number:
                    {
                        ((rtNumber)vector_data.innnerList[idx]).value = ((rtNumber)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_string:
                    {
                        ((rtString)vector_data.innnerList[idx]).value = ((rtString)value).value;
                        success = true;
                        return(this);
                    }

                    case RunTimeDataType.rt_function:
                    {
                        ((rtFunction)vector_data.innnerList[idx]).CopyFrom((rtFunction)value);
                        success = true;
                        return(this);
                    }

                    default:
                        break;
                    }

                    vector_data.innnerList[idx] = (RunTimeValueBase)value.Clone();                     //对容器的直接赋值,需要Clone																				   //return true;
                    success = true;
                    return(this);
                }
            }