Example #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();
            }
        }
Example #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);
        }