Beispiel #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);
            }
        }
Beispiel #2
0
        public static void GetItem1(IMethod method, AbcCode code)
        {
            var p0 = method.Parameters[0].Type;

            if (p0.Is(SystemTypeCode.Int32))
            {
                code.GetNativeArrayItem();
                code.CoerceXML();
            }
            else             //string
            {
                //TODO: It seams that any namespace can not be used with runtime qnames.
                code.PushGlobalPackage();
                code.Swap();
                code.GetRuntimeProperty();
                code.CoerceXMLList();
            }
        }
Beispiel #3
0
        public void UndelayCalls(AbcCode code, IList <AbcInstance> list, int arr)
        {
            int n = list.Count;

            for (int i = 0; i < n; ++i)
            {
                var instance = list[i];

                code.GetLocal(arr);
                code.PushInt(i);
                code.GetNativeArrayItem();
                var br = code.IfFalse();

                SetCalledFlag(code, instance, false);

                br.BranchTarget = code.Label();
            }
        }
Beispiel #4
0
 public static void GetArrayElem(AbcCode code)
 {
     code.GetNativeArrayItem();
 }
Beispiel #5
0
 public static void GetChar(AbcCode code)
 {
     code.GetNativeArrayItem();
     code.CoerceChar();
 }
Beispiel #6
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);
        }
Beispiel #7
0
 public static void GetString(AbcCode code)
 {
     code.GetNativeArrayItem();
     code.CoerceString();
 }
Beispiel #8
0
 public static void GetDouble(AbcCode code)
 {
     code.GetNativeArrayItem();
     code.CoerceDouble();
 }
Beispiel #9
0
 public static void GetUInt32(AbcCode code)
 {
     code.GetNativeArrayItem();
     code.CoerceUInt32();
 }
Beispiel #10
0
 public static void GetBool(AbcCode code)
 {
     code.GetNativeArrayItem();
     code.CoerceBool();
 }
Beispiel #11
0
 public static void get_Item(AbcCode code)
 {
     code.GetNativeArrayItem();
 }