Esempio n. 1
0
        private void NewObject(AbcCode code, IMethod method)
        {
            var type = method.DeclaringType;

            var abcMethod = method.AbcMethod();

            if (abcMethod != null)
            {
                if (abcMethod.IsInitializer) //default ctor!
                {
                    if (type.Is(AvmTypeCode.Object))
                    {
                        code.NewObject(0);
                    }
                    else
                    {
                        code.Construct(method.Parameters.Count);
                    }
                    return;
                }

                if (type.Is(SystemTypeCode.String))
                {
                    code.Call(abcMethod);
                    return;
                }

                var ctor = _generator.TypeBuilder.DefineCtorStaticCall(method);
                code.Call(ctor);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 2
0
        public static void exit(IMethod method, AbcCode code)
        {
            var m = code.Generator.RuntimeImpl.Exit();

            code.Getlex(m);
            code.Call(m);
        }
Esempio n. 3
0
        public IEnumerable <IInstruction> GetArrayLength()
        {
            var code = new AbcCode(_abc);

            code.Call(ArrayMethodId.GetLength);
            return(code);
        }
Esempio n. 4
0
        public static void CopyArray(AbcCode code)
        {
            var prop = code.Abc.DefineName(QName.Global("concat"));

            code.Call(prop, 0);
            code.Coerce(AvmTypeCode.Array);
        }
Esempio n. 5
0
        public static void get_IsFlashPlayer(AbcCode code)
        {
            var m = code.Generator.RuntimeImpl.IsFlashPlayer();

            code.Getlex(m);
            code.Call(m);
        }
Esempio n. 6
0
 public static void CopyTo(IMethod method, AbcCode code)
 {
     code.LoadThis();
     code.GetLocal(1);
     code.GetLocal(2);
     code.Call(ArrayMethodId.CopyTo);
     code.ReturnVoid();
 }
Esempio n. 7
0
        private void CallInitStyles(AbcCode code, AbcInstance instance)
        {
            code.Trace("PFC: calling App.initStyles");
            var initStyles = DefineInitFlexAppStyles(instance);

            code.LoadThis();
            code.Call(initStyles);
        }
Esempio n. 8
0
        public static void Find_Namespace_String(AbcCode code)
        {
            //NOTE: VerifyError: Error #1078: Illegal opcode/multiname combination: 96<[]::[]>.
            //code.Getlex(code.abc.RuntimeQName);

            var m = code.Generator.RuntimeImpl.FindClass();

            code.Call(m);
        }
Esempio n. 9
0
        public static void IndexOf(IMethod method, AbcCode code)
        {
            code.LoadThis();
            var type = method.Parameters[0].Type;

            code.BoxVariable(type, 1);
            code.Call(ArrayMethodId.IndexOf);
            code.ReturnValue();
        }
Esempio n. 10
0
        public void Call(AbcCode code, AbcInstance instance)
        {
            var m = BuildCctorCaller(instance);

            if (m == null)
            {
                return;
            }
            code.Getlex(m);
            code.Call(m);
        }
Esempio n. 11
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));
        }
Esempio n. 12
0
 private static void ToFlatIndex(AbcCode code, int n, bool getter)
 {
     code.LoadThis();
     if (getter)
     {
         code.LoadArguments(n);
         code.Add(InstructionCode.Newarray, n);
     }
     else
     {
         //Last argument is a value
         code.GetLocals(1, n - 1);
         code.Add(InstructionCode.Newarray, n - 1);
     }
     code.Call(ArrayMethodId.ToFlatIndex);
 }
Esempio n. 13
0
        void CallToException(AbcCode code, int var)
        {
            var avmErrors = Assembly.Corlib().FindType("AvmErrors");

            if (avmErrors == null)
            {
                throw new InvalidOperationException(string.Format("Unable to find AvmErrors. Invalid corlib."));
            }

            EnsureType(avmErrors);

            var fromError = avmErrors.Methods.Find("ExceptionFromError", 1);
            var m         = DefineAbcMethod(fromError);

            code.Getlex(m);
            code.GetLocal(var);
            code.Call(m);
        }
Esempio n. 14
0
 private void NewAttribute(AbcCode code, ICustomAttribute attr, int varAttr)
 {
     code.NewObject(attr.Constructor,
                    () =>
     {
         foreach (var arg in attr.FixedArguments())
         {
             code.PushValue(code, arg.Value);
         }
     });
     code.SetLocal(varAttr);
     //TODO: Set fields and properties
     foreach (var arg in attr.NamedArguments())
     {
         code.GetLocal(varAttr);
         code.PushValue(code, arg.Value);
         if (arg.Kind == ArgumentKind.Field)
         {
             var field = arg.Member as IField;
             if (field == null)
             {
                 throw new InvalidOperationException();
             }
             code.SetField(field);
         }
         else
         {
             var prop = arg.Member as IProperty;
             if (prop == null)
             {
                 throw new InvalidOperationException();
             }
             var s = _generator.MethodBuilder.BuildAbcMethod(prop.Setter);
             code.Call(s);
         }
     }
     code.GetLocal(varAttr);
 }
Esempio n. 15
0
 public static void get_Count(IMethod method, AbcCode code)
 {
     code.LoadThis();
     code.Call(ArrayMethodId.GetLength);
     code.ReturnValue();
 }
Esempio n. 16
0
        private void BaseCall(AbcCode code, IType receiverType, IMethod method)
        {
            var m = DefineBaseCall(receiverType, method);

            code.Call(m);
        }
Esempio n. 17
0
        public IEnumerable <IInstruction> Branch(BranchOperator op, IType left, IType right)
        {
            if (op.IsUnary())
            {
                if (op == BranchOperator.Null)
                {
                    var code = new AbcCode(_abc);
                    //NOTE: old code - not working with nullable types
                    //code.PushNull();
                    //code.Add(InstructionCode.Ifeq);
                    code.IsNull(left, right);
                    code.Add(InstructionCode.Iftrue);
                    return(code);
                }

                if (op == BranchOperator.NotNull)
                {
                    var code = new AbcCode(_abc);
                    //NOTE: old code - not working with nullable types
                    //code.PushNull();
                    //code.Add(InstructionCode.Ifne);
                    code.IsNull(left, right);
                    code.Add(InstructionCode.Iffalse);
                    return(code);
                }

                if (left.IsDecimalOrInt64())
                {
                    var  code   = new AbcCode(_abc);
                    bool isTrue = op == BranchOperator.True;
                    var  abcOp  = _generator.Operators.BuildBoolOp(left, isTrue);
                    //TODO: Should we enshure not null value onto the stack???
                    //AbcMethod abcOp = _generator.DefineTruthOperator(left, isTrue);
                    //code.LoadStaticReceiver(abcOp);
                    //code.Swap();
                    code.Call(abcOp);
                    code.Add(isTrue ? InstructionCode.Iftrue : InstructionCode.Iffalse);
                    return(code);
                }
            }
            else if (InternalTypeExtensions.IsDecimalOrInt64(left, right))
            {
                var code = new AbcCode(_abc);
                var opm  = _generator.Operators.Build(op, left, right);
                code.Call(opm);
                code.Add(InstructionCode.Iftrue);
                return(code);
            }

            switch (op)
            {
            case BranchOperator.True:
                return(If(InstructionCode.Iftrue));

            case BranchOperator.False:
                return(If(InstructionCode.Iffalse));

            case BranchOperator.Equality:
                return(If(InstructionCode.Ifeq));

            case BranchOperator.Inequality:
                return(If(InstructionCode.Ifne));

            case BranchOperator.LessThan:
                return(If(InstructionCode.Iflt));

            case BranchOperator.LessThanOrEqual:
                return(If(InstructionCode.Ifle));

            case BranchOperator.GreaterThan:
                return(If(InstructionCode.Ifgt));

            case BranchOperator.GreaterThanOrEqual:
                return(If(InstructionCode.Ifge));

            default:
                throw new NotSupportedException();
            }
        }