public void TestBuiltinTypes() { var abc = new AbcFile(); foreach (AvmTypeCode type in Enum.GetValues(typeof(AvmTypeCode))) { TestBuiltinType(abc, type); } Assert.IsTrue(ReferenceEquals(abc.BuiltinTypes[AvmTypeCode.Void], abc.DefineName(QName.Global("void")))); Assert.IsTrue(ReferenceEquals(abc.BuiltinTypes[AvmTypeCode.Int32], abc.DefineName(QName.Global("int")))); Assert.IsTrue(ReferenceEquals(abc.BuiltinTypes[AvmTypeCode.UInt32], abc.DefineName(QName.Global("uint")))); Assert.IsTrue(ReferenceEquals(abc.BuiltinTypes[AvmTypeCode.String], abc.DefineName(QName.Global("String")))); }
public void TestQNames() { var abc = new AbcFile(); for (int i = 0; i < 10; ++i) { string name = "name" + i; var c1 = abc.DefineName(QName.Global(name)); string name1 = "name" + i; var c2 = abc.DefineName(QName.Global(name1)); Assert.IsTrue(ReferenceEquals(c1, c2)); c1 = abc.ImportConst(c1); c2 = abc.ImportConst(c2); Assert.IsTrue(ReferenceEquals(c1, c2)); } }
public AbcMultiname this[AvmTypeCode code] { get { int i = (int)code; return(_types[i] ?? (_types[i] = _abc.DefineName(Names[i]))); } }
private void OverrideFlexAppInitialize(AbcInstance instance) { var name = Abc.DefineName(QName.Global("initialize")); instance.DefineMethod( Sig.@virtual(name, AvmTypeCode.Void).@override(), code => { code.LoadThis(); code.Add(InstructionCode.Callsupervoid, name, 0); code.Trace("PFC: calling App.initialize"); //Alert(code, "App Initialize!!!"); code.ReturnVoid(); }); }
public void ImportQName1() { var abc1 = new AbcFile(); var c1 = abc1.DefineName(QName.Package("ns", "name")); var abc2 = new AbcFile(); var c2 = abc2.ImportConst(c1); Assert.AreEqual(c1.Index, c2.Index, "#1"); Assert.AreEqual(c1.Namespace.Index, c2.Namespace.Index, "#2"); Assert.AreEqual(c1.Namespace.NameString, c2.Namespace.NameString, "#2"); }
private static void RegisterInheritStyles(AbcFile app, AbcCode code, Action pushStyleManager, bool flex4) { var registerInheritingStyle = app.DefineName(QName.Global("registerInheritingStyle")); var styles = new List <string>(CommonInheritStyles); styles.AddRange(flex4 ? Flex4InheritStyles : Flex3InheritStyles); styles.Sort(StringComparer.Ordinal); foreach (var style in styles) { pushStyleManager(); code.PushString(style); code.CallVoid(registerInheritingStyle, 1); } }
private void RegisterRemoteClasses(AbcFile app, AbcCode code) { if (_remoteClasses.Count == 0) { return; } var registerClassAlias = app.DefineName(QName.Package("flash.net", "registerClassAlias")); foreach (var pair in _remoteClasses) { code.FindPropertyStrict(registerClassAlias); code.PushString(pair.Key); code.Getlex(pair.Value); code.CallVoid(registerClassAlias, 2); } }
private void RegisterEffectTriggers(AbcFile app, AbcCode code) { if (_effects.Count == 0) { return; } var effectManager = _compiler.ImportType(app, "mx.effects.EffectManager"); var mn = app.DefineName(QName.MxInternal("registerEffectTrigger")); foreach (var pair in _effects) { code.Getlex(effectManager); code.PushString(pair.Key); code.PushString(pair.Value); code.CallVoid(mn, 2); } }
private AbcInstance Build() { var instanceName = _abc.DefineName(QName.PfxPackage("prop_ptr")); var instance = _abc.DefineEmptyInstance(instanceName, false); var obj = instance.CreatePrivateSlot("_obj", AvmTypeCode.Object); var ns = instance.CreatePrivateSlot("_ns", AvmTypeCode.Namespace); var name = instance.CreatePrivateSlot("_name", AvmTypeCode.String); instance.Initializer = _abc.DefineTraitsInitializer(obj, ns, name); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(obj); code.LoadThis(); code.GetProperty(ns); code.LoadThis(); code.GetProperty(name); code.GetRuntimeProperty(); code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(obj); code.LoadThis(); code.GetProperty(ns); code.LoadThis(); code.GetProperty(name); code.GetLocal(1); //value code.SetRuntimeProperty(); code.ReturnVoid(); }); return(instance); }
private AbcInstance Build() { var name = _abc.DefineName(QName.PfxPackage("func_ptr")); var instance = _abc.DefineEmptyInstance(name, false); var getter = instance.CreatePrivateSlot("_getter", AvmTypeCode.Function); var setter = instance.CreatePrivateSlot("_setter", AvmTypeCode.Function); instance.Initializer = _abc.DefineTraitsInitializer(getter, setter); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(getter); code.PushNull(); code.CallFunction(1); //this code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(setter); code.PushNull(); code.GetLocal(1); //value code.CallFunction(2); //this + value code.Pop(); code.ReturnVoid(); }); return(instance); }
internal AbcInstance DefineFlexInitMixin(AbcFile app) { var flexModuleFactoryInterface = FlexTypes.GetFlexModuleFactoryInterface(app); var childManagerInstance = FlexTypes.GetChildManagerInstance(app); var flex4 = childManagerInstance != null; string name = "_FlexInit_" + _compiler.FlexAppPrefix; string ns = _compiler.RootNamespace; var instance = new AbcInstance(true) { Name = app.DefineName(QName.Package(ns, name)), BaseTypeName = app.BuiltinTypes.Object, IsMixin = true, IsFlexInitMixin = true, Initializer = app.DefineMethod( Sig.@this(null, AvmTypeCode.Void), code => { code.ConstructSuper(); code.ReturnVoid(); }), Class = { Initializer = app.DefineEmptyMethod() } }; app.AddInstance(instance); instance.DefineMethod( Sig.@static("init", AvmTypeCode.Void, flexModuleFactoryInterface, "f"), code => { code.PushThisScope(); const int moduleFactoryArg = 1; const int styleManagerVar = 2; if (flex4) { CreateInstance(code, childManagerInstance, moduleFactoryArg); code.Pop(); var styleManager2 = FlexTypes.GetStyleManager2Interface(app); var styleManagerImpl = FlexTypes.GetStyleManagerImpl(app); CreateInstance(code, styleManagerImpl, moduleFactoryArg); code.Coerce(styleManager2); code.SetLocal(styleManagerVar); } RegisterEffectTriggers(app, code); RegisterRemoteClasses(app, code); Action pushStyleManager; if (flex4) { pushStyleManager = () => code.GetLocal(styleManagerVar); } else { pushStyleManager = () => code.Getlex(FlexTypes.GetStyleManagerInstance(app)); } RegisterInheritStyles(app, code, pushStyleManager, flex4); //NOTE: Uncomment to add forward refernce to Flex Application //var appInstance = app.generator.MainInstance; //code.Trace(string.Format("PFC: forward reference to FlexApp class {0}", appInstance.FullName)); //code.Getlex(appInstance); //code.Pop(); code.ReturnVoid(); }); return(instance); }
private AbcMultiname DefineSystemManagerName(AbcFile abc) { string ns = _compiler.RootNamespace; return(abc.DefineName(QName.Package(ns, _sysManagerName))); }
/* Base Method Code * public function create(... params):Object * { * var mainClassName:String = info()["mainClassName"]; * * if (mainClassName == null) * { * var url:String = loaderInfo.loaderURL; * var dot:int = url.lastIndexOf("."); * var slash:int = url.lastIndexOf("/"); * mainClassName = url.substring(slash + 1, dot); * } * * var mainClass:Class = Class(getDefinitionByName(mainClassName)); * * return mainClass ? new mainClass() : null; * } */ /* Flex Auto Generated Code * public override function create(... params):Object * { * if (params.length > 0 && !(params[0] is String)) * return super.create.apply(this, params); * * var mainClassName:String = params.length == 0 ? "AppName" : String(params[0]); * var mainClass:Class = Class(getDefinitionByName(mainClassName)); * if (!mainClass) * return null; * * var instance:Object = new mainClass(); * if (instance is IFlexModule) * (IFlexModule(instance)).moduleFactory = this; * return instance; * } */ void BuildSystemManagerCreate(AbcFile abc, AbcInstance instance) { var method = instance.DefineMethod( Sig.@virtual("create", AvmTypeCode.Object).@override(), code => { var typeString = abc.DefineName(QName.Global("String")); var typeClass = abc.DefineName(QName.Global("Class")); //NOTE: getDefinitionByName is method of mx.core.SystemManager var getDefByName = abc.DefineName(QName.Global("getDefinitionByName")); const int argParams = 1; const int varClassName = 2; const int varClass = 3; const int varInstance = 4; code.PushThisScope(); code.GetLocal(argParams); code.GetArrayLengthInt(); code.PushInt(0); var gotoCheckString = code.If(BranchOperator.GreaterThan); code.PushString(MainClassName); code.SetLocal(varClassName); var gotoCreate1 = code.Goto(); //check string block var checkString = code.Label(); gotoCheckString.BranchTarget = checkString; //params[0] code.GetNativeArrayItem(argParams, 0); code.Getlex(typeString); code.Add(InstructionCode.Istypelate); //if not str goto calling of super.create var ifNotStr = code.IfFalse(); code.FindPropertyStrict(typeString); code.GetNativeArrayItem(argParams, 0); code.Call(typeString, 1); code.CoerceString(); code.SetLocal(varClassName); var gotoCreate2 = code.Goto(); //super.create.apply(this, params) block var superCreate = code.Label(); ifNotStr.BranchTarget = superCreate; code.LoadThis(); code.GetSuper("create"); code.LoadThis(); code.GetLocal(argParams); code.ApplyFunction(2); code.ReturnValue(); //instance creation block gotoCreate1.BranchTarget = gotoCreate2.BranchTarget = code.Label(); // resolve class by name using SystemManager.getDefinitionByName //code.Trace("PFX_SYSMGR: try to resolve class using SystemManager.getDefinitionByName"); code.FindPropertyStrict(typeClass); code.LoadThis(); code.GetLocal(varClassName); code.Call(getDefByName, 1); code.Call(typeClass, 1); code.Coerce(typeClass); code.SetLocal(varClass); code.GetLocal(varClass); var ifClassNotNull1 = code.IfTrue(); // try to resolve class using flash.system.ApplicationDomain.currentDomain //code.Trace("PFX_SYSMGR: try to resolve class using flash.system.ApplicationDomain.currentDomain"); code.FindPropertyStrict(typeClass); GetCurrentAppDomain(code); code.GetLocal(varClassName); code.Call(abc.DefineName(QName.Global("getDefinition")), 1); code.Call(typeClass, 1); code.Coerce(typeClass); code.SetLocal(varClass); code.GetLocal(varClass); var ifClassNotNull2 = code.IfTrue(); code.Trace(string.Format("PFX_SYSMGR: unable to resolve class '{0}'", MainClassName)); code.ReturnNull(); ifClassNotNull1.BranchTarget = ifClassNotNull2.BranchTarget = code.Label(); // create instance of class was resolved succesfully code.GetLocal(varClass); code.Add(InstructionCode.Construct, 0); code.Add(InstructionCode.Coerce_o); code.SetLocal(varInstance); //if (instance is mx.core.IFlexModule) code.GetLocal(varInstance); var flexModule = _compiler.ImportType(abc, MX.IFlexModule); code.Getlex(flexModule); code.Add(InstructionCode.Istypelate); var gotoReturn = code.IfFalse(); //((IFlexModule)instance).moduleFactory = this code.FindPropertyStrict(flexModule.Name); code.GetLocal(varInstance); code.Call(flexModule.Name, 1); code.LoadThis(); code.SetPublicProperty("mx.core:IFlexModule", "moduleFactory"); gotoReturn.BranchTarget = code.Label(); code.GetLocal(varInstance); code.ReturnValue(); }); method.Flags |= AbcMethodFlags.NeedRest; }