示例#1
0
        public static void trace(IMethod method, AbcCode code)
        {
            //has global receiver
            var mn = code.DefineGlobalQName("trace");

            //code.Add(InstructionCode.Findpropstrict, mn);
            code.CallVoid(mn, method.Parameters.Count);
        }
示例#2
0
 private static void AddEventListener(AbcCode code, AbcMethod method, string eventName)
 {
     code.LoadThis();
     code.PushString(eventName);
     code.LoadThis();
     code.GetProperty(method.TraitName);
     code.CallVoid("addEventListener", 2);
 }
示例#3
0
        public static InlineCall Create(AbcFile abc, IMethod method, InlineMethodInfo info)
        {
            var code       = new AbcCode(abc);
            var targetType = info.TargetType != null?info.TargetType.Define(abc) : null;

            var name = info.Name.Define(abc);

            switch (info.Kind)
            {
            case InlineKind.Property:
                if (method.IsSetter())
                {
                    code.SetProperty(name);
                }
                else
                {
                    code.GetProperty(name);
                    code.Coerce(method.Type, true);
                }
                break;

            case InlineKind.Operator:
            {
                int n = method.Parameters.Count;
                if (n <= 1)
                {
                    throw new InvalidOperationException();
                }
                var op = info.Op;
                for (int i = 1; i < n; ++i)
                {
                    code.Add(op);
                }
                code.Coerce(method.Type, true);
            }
            break;

            default:
                if (method.IsVoid())
                {
                    code.CallVoid(name, method.Parameters.Count);
                }
                else
                {
                    code.Call(name, method.Parameters.Count);
                    code.Coerce(method.Type, true);
                }
                break;
            }

            return(new InlineCall(method, targetType, name, code));
        }
示例#4
0
        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);
            }
        }
示例#5
0
        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);
            }
        }
示例#6
0
        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);
            }
        }
示例#7
0
        private bool LinkEvent(IMethod method, AbcInstance instance)
        {
            var e = method.Association as IEvent;

            if (e == null)
            {
                return(false);
            }

            var attr = e.FindAttribute(Attrs.Event);

            if (attr == null)
            {
                return(false);
            }

            string eventName = attr.Arguments[0].Value as string;

            if (string.IsNullOrEmpty(eventName))
            {
                throw new InvalidOperationException();
            }

            if (e.Adder == method || e.Remover == method)
            {
                //stack transition: dispatcher, delegate -> ...
                var code = new AbcCode(instance.Abc);
                code.Swap();
                code.PushString(eventName);
                code.CallVoid(GetDelegateMethodName(e.Adder == method), 2);
                method.Data = new InlineCall(method, null, null, code);
                return(true);
            }

            throw new NotImplementedException();
        }