Exemplo n.º 1
0
        public static void Getter(IMethod method, AbcCode code)
        {
            var prop = method.Association as IProperty;

            if (prop == null)
            {
                throw new InvalidOperationException();
            }
            if (prop.Parameters.Count > 0)             //indexer
            {
                if (IsTypedVector(method))
                {
                    code.GetProperty(code.Abc.NameArrayIndexer);
                    code.Coerce(method.Type, true);
                }
                else
                {
                    code.GetNativeArrayItem();
                }
            }
            else
            {
                code.GetProperty(prop.Name);
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 3
0
        public IEnumerable <IInstruction> LoadFunction(IMethod method)
        {
            EnsureMethod(method);
            var code = new AbcCode(_abc);
            var name = GetMethodName(method);

            code.GetProperty(name);
            code.CoerceFunction();
            return(code);
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        public IEnumerable <IInstruction> LoadField(IField field)
        {
            var prop = GetFieldName(field);

            var code = new AbcCode(_abc);

            CallStaticCtor(code, field);

            if (LoadStaticFieldTarget && field.IsStatic)
            {
                LoadStaticInstance(code, field.DeclaringType);
            }

            code.GetProperty(prop);

            return(code);
        }
Exemplo n.º 6
0
 public static void op_Implicit(AbcCode code)
 {
     code.GetProperty("Class");
 }
Exemplo n.º 7
0
        private AbcMethod BuildCtorImpl(IMethod method, AbcInstance instance)
        {
            if (!method.IsConstructor)
            {
                return(null);
            }
            if (method.IsStatic)
            {
                return(null);
            }
            var type = method.DeclaringType;

            if (!type.IsArray)
            {
                return(null);
            }

            var ctor = new AbcMethod
            {
                ReturnType = Abc.BuiltinTypes.Void
            };

            _generator.MethodBuilder.BuildParameters(ctor, method);

            string name1 = "arrctor_" + type.GetSigName();
            var    name  = Abc.DefineName(QName.Global(name1));
            var    trait = AbcTrait.CreateMethod(ctor, name);

            instance.Traits.Add(trait);

            var body = new AbcMethodBody(ctor);

            Abc.AddMethod(ctor);

            var code = new AbcCode(Abc);

            code.PushThisScope();
            code.ConstructSuper();

            //check arguments
            int n = method.Parameters.Count;

            for (int i = 0; i < n; ++i)
            {
                code.GetLocal(i + 1);
                code.PushInt(0);
                var br            = code.If(BranchOperator.GreaterThanOrEqual);
                var exceptionType = _generator.Corlib.GetType(CorlibTypeId.ArgumentOutOfRangeException);
                code.ThrowException(exceptionType);
                br.BranchTarget = code.Label();
            }

            //m_rank = n
            code.LoadThis();
            code.PushInt(n);
            code.SetProperty(Const.Array.Rank);

            int varSize = n + 1;

            for (int i = 0; i < n; ++i)
            {
                code.GetLocal(i + 1);
            }
            for (int i = 1; i < n; ++i)
            {
                code.Add(InstructionCode.Multiply_i);
            }
            code.SetLocal(varSize);

            //init m_value
            code.LoadThis();
            code.CreateArrayVarSize(varSize);
            code.SetProperty(Const.Array.Value);

            //init m_lengths
            code.LoadThis();
            for (int i = 0; i < n; ++i)
            {
                code.GetLocal(i + 1);
            }
            code.Add(InstructionCode.Newarray, n);
            code.SetProperty(Const.Array.Lengths);

            int varDimArr = varSize + 1;

            //init m_dims
            code.CreateArray(n - 1);
            code.SetLocal(varDimArr);

            //1, n, n * (n-1), ..., n * (n-1) * ... * n0
            for (int i = n - 2; i >= 0; --i)
            {
                int leni = i + 2;
                code.GetLocal(varDimArr);
                code.PushInt(i);

                if (i != n - 2)
                {
                    code.GetLocal(varDimArr);
                    code.PushInt(i + 1);
                    code.GetNativeArrayItem();
                    code.CoerceInt32();                     //prev

                    code.GetLocal(leni);
                    code.Add(InstructionCode.Multiply_i);                     //prev * leni
                }
                else
                {
                    code.GetLocal(leni);
                }

                code.SetNativeArrayItem();
            }

            code.LoadThis();
            code.GetLocal(varDimArr);
            code.SetProperty(Const.Array.Dims);

            var elemType = type.GetElementType();

            InitFields(code, type, elemType, 0);

            if (InternalTypeExtensions.IsInitArray(elemType))
            {
                code.InitArray(elemType,
                               () =>
                {
                    code.LoadThis();
                    code.GetProperty(Const.Array.Value);
                }, varSize);
            }

            code.ReturnVoid();

            body.Finish(code);

            return(ctor);
        }
Exemplo n.º 8
0
 private static void GetCurrentAppDomain(AbcCode code)
 {
     code.Getlex("flash.system", "ApplicationDomain");
     code.GetProperty("currentDomain");
 }