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); }
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); }
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); }
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); }
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); }
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(); }
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); }