Beispiel #1
0
 public MosaMethodSignature(MosaType returnType, IList <MosaParameter> parameter)
 {
     ReturnType = returnType;
     Parameters = new List <MosaParameter>(parameter).AsReadOnly();
 }
        private static void AddArrayMethods(TypeSystem typeSystem, MosaType arrayType, MosaType.Mutator type, MosaArrayInfo info)
        {
            // Remove all methods & fields --> Since BaseType = System.Array, they're automatically inherited.
            type.Methods.Clear();
            type.Fields.Clear();

            // Add three array accessors as defined in standard (Get, Set, Address)
            // Also, constructor.

            uint rank = info.Rank;

            var methodGet = typeSystem.Controller.CreateMethod();

            using (var method = typeSystem.Controller.MutateMethod(methodGet))
            {
                method.DeclaringType   = arrayType;
                method.Name            = "Get";
                method.IsInternalCall  = true;
                method.IsRTSpecialName = method.IsSpecialName = true;
                method.IsFinal         = true;
                method.HasThis         = true;

                var parameters = new List <MosaParameter>();

                for (uint i = 0; i < rank; i++)
                {
                    var indexParam = typeSystem.Controller.CreateParameter();
                    using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam))
                    {
                        mosaParameter.Name = "index" + i;
                        mosaParameter.ParameterAttributes = MosaParameterAttributes.In;
                        mosaParameter.ParameterType       = typeSystem.BuiltIn.I4;
                        mosaParameter.DeclaringMethod     = methodGet;
                    }
                    parameters.Add(indexParam);
                }
                method.Signature = new MosaMethodSignature(arrayType.ElementType, parameters);
            }

            type.Methods.Add(methodGet);

            var methodSet = typeSystem.Controller.CreateMethod();

            using (var method = typeSystem.Controller.MutateMethod(methodSet))
            {
                method.DeclaringType   = arrayType;
                method.Name            = "Set";
                method.IsInternalCall  = true;
                method.IsRTSpecialName = method.IsSpecialName = true;
                method.IsFinal         = true;
                method.HasThis         = true;

                var parameters = new List <MosaParameter>();
                for (uint i = 0; i < rank; i++)
                {
                    var indexParam = typeSystem.Controller.CreateParameter();
                    using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam))
                    {
                        mosaParameter.Name = "index" + i;
                        mosaParameter.ParameterAttributes = MosaParameterAttributes.In;
                        mosaParameter.ParameterType       = typeSystem.BuiltIn.I4;
                        mosaParameter.DeclaringMethod     = methodSet;
                    }
                    parameters.Add(indexParam);
                }

                var valueParam = typeSystem.Controller.CreateParameter();
                using (var mosaParameter = typeSystem.Controller.MutateParameter(valueParam))
                {
                    mosaParameter.Name = "value";
                    mosaParameter.ParameterAttributes = MosaParameterAttributes.In;
                    mosaParameter.ParameterType       = arrayType.ElementType;
                    mosaParameter.DeclaringMethod     = methodSet;
                }
                parameters.Add(valueParam);

                method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters);
            }

            type.Methods.Add(methodSet);

            var methodAdrOf = typeSystem.Controller.CreateMethod();

            using (var method = typeSystem.Controller.MutateMethod(methodAdrOf))
            {
                method.DeclaringType   = arrayType;
                method.Name            = "AddressOr";
                method.IsInternalCall  = true;
                method.IsRTSpecialName = method.IsSpecialName = true;
                method.IsFinal         = true;
                method.HasThis         = true;

                var parameters = new List <MosaParameter>();
                for (uint i = 0; i < rank; i++)
                {
                    var indexParam = typeSystem.Controller.CreateParameter();
                    using (var mosaParameter = typeSystem.Controller.MutateParameter(indexParam))
                    {
                        mosaParameter.Name = "index" + i;
                        mosaParameter.ParameterAttributes = MosaParameterAttributes.In;
                        mosaParameter.ParameterType       = typeSystem.BuiltIn.I4;
                        mosaParameter.DeclaringMethod     = methodAdrOf;
                    }
                    parameters.Add(indexParam);
                }
                method.Signature = new MosaMethodSignature(arrayType.ElementType.ToManagedPointer(), parameters);
            }
            type.Methods.Add(methodAdrOf);

            var methodCtor = typeSystem.Controller.CreateMethod();

            using (var method = typeSystem.Controller.MutateMethod(methodCtor))
            {
                method.DeclaringType   = arrayType;
                method.Name            = ".ctor";
                method.IsInternalCall  = true;
                method.IsRTSpecialName = method.IsSpecialName = true;
                method.IsFinal         = true;
                method.HasThis         = true;

                var parameters = new List <MosaParameter>();
                for (uint i = 0; i < rank; i++)
                {
                    var lengthParam = typeSystem.Controller.CreateParameter();
                    using (var mosaParameter = typeSystem.Controller.MutateParameter(lengthParam))
                    {
                        mosaParameter.Name = "length" + i;
                        mosaParameter.ParameterAttributes = MosaParameterAttributes.In;
                        mosaParameter.ParameterType       = typeSystem.BuiltIn.I4;
                        mosaParameter.DeclaringMethod     = methodCtor;
                    }
                    parameters.Add(lengthParam);
                }
                method.Signature = new MosaMethodSignature(typeSystem.BuiltIn.Void, parameters);
            }
            type.Methods.Add(methodCtor);
        }
Beispiel #3
0
 public MosaMethod CreateLinkerMethod(string methodName, MosaType returnType, bool hasThis = false, IList <MosaParameter> parameters = null)
 {
     return(CreateLinkerMethod(DefaultLinkerType, methodName, returnType, hasThis, parameters));
 }
Beispiel #4
0
 public MosaType.Mutator MutateType(MosaType type)
 {
     return(new MosaType.Mutator(type));
 }
Beispiel #5
0
 public bool Equals(MosaType type)
 {
     return(ParameterType.Equals(type));
 }
Beispiel #6
0
 internal Mutator(MosaType type)
     : base(type)
 {
     this.type = type;
 }
Beispiel #7
0
 public Argument(MosaType type, object value)
 {
     Type  = type;
     Value = value;
 }
Beispiel #8
0
 public bool Equals(MosaType type)
 {
     return(Type.Equals(type));
 }
Beispiel #9
0
 public MosaLocal(string name, MosaType type, bool isPinned)
 {
     this.Name     = name;
     this.Type     = type;
     this.IsPinned = isPinned;
 }
 public Argument(MosaType type, object value)
 {
     this.Type  = type;
     this.Value = value;
 }
Beispiel #11
0
 public MosaLocal(string name, MosaType type, bool isPinned)
 {
     Name     = name;
     Type     = type;
     IsPinned = isPinned;
 }