Exemplo n.º 1
0
        private void DefineFlexAppInitializer(AbcInstance instance)
        {
            Debug.Assert(instance.Initializer == null);

            instance.Initializer = Abc.DefineMethod(
                Sig.@global(null),
                code =>
            {
                code.PushThisScope();
                code.ConstructSuper();

                code.Trace("PFC: calling App.initializer");

                CtorAfterSuperCall(code);

                if (!IsFlex4)
                {
                    var ctor = instance.FindParameterlessConstructor();
                    if (ctor != null)
                    {
                        var ctorMethod = _generator.MethodBuilder.BuildAbcMethod(ctor);
                        AddEventListener(code, ctorMethod, FlexAppEvents.Initialize);
                    }
                }

                code.ReturnVoid();
            });
        }
Exemplo n.º 2
0
 private AbcMethod DefineString_GetTypeId()
 {
     return(Abc.DefineMethod(
                Sig.@global(AvmTypeCode.Int32),
                code =>
     {
         code.PushTypeId(SystemTypes.String);
         code.ReturnValue();
     }));
 }
Exemplo n.º 3
0
 public static AbcMethod BuildDefaultInitializer(AbcFile abc, IType type)
 {
     return(abc.DefineMethod(
                Sig.@global(null),
                code =>
     {
         code.PushThisScope();
         code.InitFields(type, false, false);
         code.ConstructSuper();
         code.ReturnVoid();
     }));
 }
Exemplo n.º 4
0
        private void ConvertImpl(IMethod method)
        {
            var m = method.AbcMethod();

            if (m == null)
            {
                return;
            }

            string name = method.Name;

            if (name == "ToString")
            {
                var impl = Abc.DefineMethod(
                    Sig.@global(AvmTypeCode.String),
                    code => code.ReturnThis());

                _generator.NewApi.SetProtoFunction(AvmTypeCode.String, m.TraitName, impl);
                return;
            }

            if (name == "GetTypeCode")
            {
                Impl(method,
                     code =>
                {
                    code.PushInt(18);
                    code.ReturnValue();
                });
                return;
            }

            Impl(method,
                 code =>
            {
                var convertInstance = _generator.Corlib.Convert.Instance;
                var convertMethod   = FindConvertImpl(method);
                var impl            = _generator.MethodBuilder.BuildAbcMethod(convertMethod);

                code.Getlex(convertInstance);
                code.GetLocals(0, method.Parameters.Count);
                code.Call(impl);
                code.ReturnValue();
            });
        }
Exemplo n.º 5
0
        public AbcMethod GetProperty(AbcMultiname prop)
        {
            if (prop == null)
            {
                throw new ArgumentNullException("prop");
            }

            var m = _abc.DefineMethod(
                Sig.@global(AvmTypeCode.Object),
                code =>
            {
                code.Getlex(prop);
                code.ReturnValue();
            });

#if DEBUG
            m.Name = _abc.DefineString("get_" + prop.NameString);
#endif

            return(m);
        }
Exemplo n.º 6
0
        private static AbcMethod BuildClassInitializer(AbcClass klass, InitInfo info)
        {
            var abc       = klass.Abc;
            var generator = abc.Generator;

            var assetTraits = new List <AbcTrait>();

            foreach (var f in info.Assets)
            {
                generator.FieldBuilder.Build(f);
                var t = f.Data as AbcTrait;
                if (t == null)
                {
                    throw new InvalidOperationException();
                }
                Debug.Assert(t.AssetInstance != null);
                assetTraits.Add(t);
            }

            var type = klass.Type;

            return(abc.DefineMethod(Sig.@global(null), code =>
            {
                code.PushThisScope();

                code.InitFields(type, true, false);

                foreach (var t in assetTraits)
                {
                    code.LoadThis();
                    code.Getlex(t.AssetInstance.Name);
                    code.SetProperty(t.Name);
                }

                code.ReturnVoid();
            }));
        }
Exemplo n.º 7
0
        private void DefineRootSprite()
        {
            if (!_generator.IsSwf)
            {
                return;
            }
            if (_generator.IsSwc)
            {
                return;
            }

            //NOTE: In Flex Root sprite is SystemManager.
            if (_generator.IsFlexApplication)
            {
                return;
            }
            if (Instance != null)
            {
                return;
            }

            var rootStageField = DefineRootStageHolder();

            IsGenerated = true;
            const string rootName = "$ROOTSPRITE$";

            Instance = new AbcInstance(true)
            {
                Name  = Abc.DefineName(QName.Package(_generator.RootNamespace, rootName)),
                Flags = (AbcClassFlags.Sealed | AbcClassFlags.ProtectedNamespace),
                ProtectedNamespace = Abc.DefineProtectedNamespace(rootName)
            };

            const string superTypeName = "flash.display.Sprite";
            var          superType     = _generator.FindInstanceDefOrRef(superTypeName);

            if (superType == null)
            {
                throw Errors.Type.UnableToFind.CreateException(superTypeName);
            }

            Instance.BaseTypeName = Abc.ImportConst(superType.Name);
            Instance.BaseInstance = superType;

            Instance.Class.Initializer = Abc.DefineEmptyMethod();

            Abc.AddInstance(Instance);

            Instance.Initializer = Abc.DefineMethod(
                Sig.@global(null),
                code =>
            {
                code.PushThisScope();
                code.ConstructSuper();

                if (rootStageField != null)
                {
                    code.SetStaticProperty(rootStageField,
                                           () =>
                    {
                        code.LoadThis();
                        code.GetProperty("stage");
                    });
                }

                _generator.NUnit.Main(code);

                _generator.Scripts.CallEntryPoint(code);
            });
        }