public static string GetIntName(ES_IntSize size, bool unsigned) { return(size switch { ES_IntSize.Int8 => unsigned ? UInt8 : Int8, ES_IntSize.Int16 => unsigned ? UInt16 : Int16, ES_IntSize.Int32 => unsigned ? UInt32 : Int32, ES_IntSize.Int64 => unsigned ? UInt64 : Int64, _ => throw new NotImplementedException("Size not implemented."), });
private static TypeSyntax GetIntType(ES_IntSize size, bool unsigned) { return(size switch { ES_IntSize.Int8 => PredefinedType(Token(!unsigned ? SyntaxKind.SByteKeyword : SyntaxKind.ByteKeyword)), ES_IntSize.Int16 => PredefinedType(Token(!unsigned ? SyntaxKind.ShortKeyword : SyntaxKind.UShortKeyword)), ES_IntSize.Int32 => PredefinedType(Token(!unsigned ? SyntaxKind.IntKeyword : SyntaxKind.UIntKeyword)), ES_IntSize.Int64 => PredefinedType(Token(!unsigned ? SyntaxKind.LongKeyword : SyntaxKind.ULongKeyword)), _ => throw new NotImplementedException("Size not implemented."), });
private Pointer <ES_TypeInfo> GenerateBuiltinTypes_Int(ES_IntSize size, bool unsigned) { var intDataPtr = EnvironmentBuilder !.MemoryManager.GetMemory <ES_IntTypeData> (); var namePtr = Environment !.IdPool.GetIdentifier(ES_PrimitiveTypes.GetIntName(size, unsigned)); var fqn = new ES_FullyQualifiedName(Environment.GlobalTypesNamespace, namePtr); *intDataPtr = new ES_IntTypeData(ES_AccessModifier.Public, ArrayPointer <byte> .Null, fqn, size, unsigned); return(new Pointer <ES_TypeInfo> (&intDataPtr->TypeInfo)); }
public static EchelonScriptErrorMessage GenIntLitTooBig(bool sign, ES_IntSize size, EchelonScriptToken errorToken) { var signStr = sign ? "a signed" : "an unsigned"; var sizeStr = size switch { ES_IntSize.Int8 => "8", ES_IntSize.Int16 => "16", ES_IntSize.Int32 => "32", ES_IntSize.Int64 => "64", _ => throw new NotImplementedException("Int size not implemented."), }; var errorMessage = IntLitTooBigForSize.Replace("{sign}", signStr).Replace("{size}", sizeStr); return(new EchelonScriptErrorMessage(errorToken, errorMessage)); }
public ES_IntTypeData( ES_AccessModifier accessMod, ArrayPointer <byte> sourceUnit, ES_FullyQualifiedName fullyQualifiedName, ES_IntSize size, bool unsigned ) { TypeInfo = new ES_TypeInfo(ES_TypeTag.Int, accessMod, ES_TypeFlag.NoRefs, sourceUnit, fullyQualifiedName); IntSize = size; Unsigned = unsigned; TypeInfo.RuntimeSize = size switch { ES_IntSize.Int8 => 1, ES_IntSize.Int16 => 2, ES_IntSize.Int32 => 4, ES_IntSize.Int64 => 8, _ => throw new NotImplementedException("Size not implemented."), }; }