Exemplo n.º 1
0
        public static IChelaType GetPrimitiveType(uint id)
        {
            switch ((PrimitiveTypeId)id)
            {
            case PrimitiveTypeId.Void:
                return(ChelaType.GetVoidType());

            case PrimitiveTypeId.UInt8:
                return(ChelaType.GetByteType());

            case PrimitiveTypeId.Int8:
                return(ChelaType.GetSByteType());

            case PrimitiveTypeId.UInt16:
                return(ChelaType.GetUShortType());

            case PrimitiveTypeId.Int16:
                return(ChelaType.GetShortType());

            case PrimitiveTypeId.UInt32:
                return(ChelaType.GetUIntType());

            case PrimitiveTypeId.Int32:
                return(ChelaType.GetIntType());

            case PrimitiveTypeId.UInt64:
                return(ChelaType.GetULongType());

            case PrimitiveTypeId.Int64:
                return(ChelaType.GetLongType());

            case PrimitiveTypeId.Fp32:
                return(ChelaType.GetFloatType());

            case PrimitiveTypeId.Fp64:
                return(ChelaType.GetDoubleType());

            case PrimitiveTypeId.Bool:
                return(ChelaType.GetBoolType());

            case PrimitiveTypeId.Size:
                return(ChelaType.GetSizeType());

            case PrimitiveTypeId.PtrDiff:
                return(ChelaType.GetPtrDiffType());

            case PrimitiveTypeId.Char:
                return(ChelaType.GetCharType());

            default:
                throw new System.NotImplementedException();
            }
        }
Exemplo n.º 2
0
        private void CreateDefaultConstructor(StructDefinition node)
        {
            // Get the structure.
            Structure building = node.GetStructure();

            // Check for an user defined constructor.
            if (building.GetConstructor() != null)
            {
                return;
            }

            // Instance the building.
            GenericPrototype contGenProto = building.GetGenericPrototype();
            int       templateArgs        = contGenProto.GetPlaceHolderCount();
            Structure buildingInstance    = building;

            if (templateArgs != 0)
            {
                IChelaType[] thisArgs = new IChelaType[templateArgs];
                for (int i = 0; i < templateArgs; ++i)
                {
                    thisArgs[i] = contGenProto.GetPlaceHolder(i);
                }
                buildingInstance = (Structure)building.InstanceGeneric(
                    new GenericInstance(contGenProto, thisArgs), currentModule);
            }

            // Create the default constructor function type.
            List <IChelaType> arguments = new List <IChelaType> ();

            arguments.Add(ReferenceType.Create(buildingInstance));
            FunctionType ctorType = FunctionType.Create(ChelaType.GetVoidType(), arguments);

            // Create the constructor method.
            MemberFlags flags       = MemberFlags.Public | MemberFlags.Constructor;
            Method      constructor = new Method(building.GetName(), flags, building);

            constructor.SetFunctionType(ctorType);

            // Store it.
            building.AddFunction("<ctor>", constructor);
            node.SetDefaultConstructor(constructor);
        }
Exemplo n.º 3
0
        public ModuleTypeDeclaration()
        {
            typeMaps = new Dictionary <string, IChelaType> ();
            typeMaps.Add("Chela.Lang.Object", ChelaType.GetObjectType());
            typeMaps.Add("Chela.Lang.String", ChelaType.GetStringType());

            assocClasses = new Dictionary <string, IChelaType> ();
            assocClasses.Add("Chela.Lang.Boolean", ChelaType.GetBoolType());
            assocClasses.Add("Chela.Lang.Char", ChelaType.GetCharType());
            assocClasses.Add("Chela.Lang.SByte", ChelaType.GetSByteType());
            assocClasses.Add("Chela.Lang.Byte", ChelaType.GetByteType());
            assocClasses.Add("Chela.Lang.Int16", ChelaType.GetShortType());
            assocClasses.Add("Chela.Lang.UInt16", ChelaType.GetUShortType());
            assocClasses.Add("Chela.Lang.Int32", ChelaType.GetIntType());
            assocClasses.Add("Chela.Lang.UInt32", ChelaType.GetUIntType());
            assocClasses.Add("Chela.Lang.Int64", ChelaType.GetLongType());
            assocClasses.Add("Chela.Lang.UInt64", ChelaType.GetULongType());
            assocClasses.Add("Chela.Lang.IntPtr", ChelaType.GetPtrDiffType());
            assocClasses.Add("Chela.Lang.UIntPtr", ChelaType.GetSizeType());
            assocClasses.Add("Chela.Lang.Single", ChelaType.GetFloatType());
            assocClasses.Add("Chela.Lang.Double", ChelaType.GetDoubleType());

            // Vector associated classes
            assocClasses.Add("Chela.Lang.Single2", VectorType.Create(ChelaType.GetFloatType(), 2));
            assocClasses.Add("Chela.Lang.Single3", VectorType.Create(ChelaType.GetFloatType(), 3));
            assocClasses.Add("Chela.Lang.Single4", VectorType.Create(ChelaType.GetFloatType(), 4));
            assocClasses.Add("Chela.Lang.Double2", VectorType.Create(ChelaType.GetDoubleType(), 2));
            assocClasses.Add("Chela.Lang.Double3", VectorType.Create(ChelaType.GetDoubleType(), 3));
            assocClasses.Add("Chela.Lang.Double4", VectorType.Create(ChelaType.GetDoubleType(), 4));
            assocClasses.Add("Chela.Lang.Int32x2", VectorType.Create(ChelaType.GetIntType(), 2));
            assocClasses.Add("Chela.Lang.Int32x3", VectorType.Create(ChelaType.GetIntType(), 3));
            assocClasses.Add("Chela.Lang.Int32x4", VectorType.Create(ChelaType.GetIntType(), 4));
            assocClasses.Add("Chela.Lang.Boolean2", VectorType.Create(ChelaType.GetBoolType(), 2));
            assocClasses.Add("Chela.Lang.Boolean3", VectorType.Create(ChelaType.GetBoolType(), 3));
            assocClasses.Add("Chela.Lang.Boolean4", VectorType.Create(ChelaType.GetBoolType(), 4));
        }
Exemplo n.º 4
0
 public ByteConstant(byte value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetByteType()));
     this.value = value;
 }
Exemplo n.º 5
0
 public ULongConstant(ulong value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetULongType()));
     this.value = value;
 }
Exemplo n.º 6
0
 public UShortConstant(ushort value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetUShortType()));
     this.value = value;
 }
Exemplo n.º 7
0
 public UIntegerConstant(uint value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetUIntType()));
     this.value = value;
 }
Exemplo n.º 8
0
 public DoubleConstant(double value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetDoubleType()));
     this.value = value;
 }
Exemplo n.º 9
0
 public CharacterConstant(char value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetCharType()));
     this.value = value;
 }
Exemplo n.º 10
0
 public NullConstant(TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetNullType()));
 }
Exemplo n.º 11
0
 public FloatConstant(float value, TokenPosition position)
     : base(position)
 {
     SetNodeType(ConstantType.Create(ChelaType.GetFloatType()));
     this.value = value;
 }