diff --git a/core/_preload.odin b/core/_preload.odin index f1d921b6b..414c95da5 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -25,91 +25,89 @@ import ( // IMPORTANT NOTE(bill): Do not change the order of any of this data // The compiler relies upon this _exact_ order -type ( - TypeInfoEnumValue raw_union { - f: f64, - i: i128, - } - // NOTE(bill): This must match the compiler's - CallingConvention enum { - Invalid = 0, - Odin = 1, - Contextless = 2, - C = 3, - Std = 4, - Fast = 5, - } +TypeInfoEnumValue :: raw_union { + f: f64, + i: i128, +} +// NOTE(bill): This must match the compiler's +CallingConvention :: enum { + Invalid = 0, + Odin = 1, + Contextless = 2, + C = 3, + Std = 4, + Fast = 5, +} - TypeInfoRecord struct #ordered { - types: []^TypeInfo, - names: []string, - offsets: []int, // offsets may not be used in tuples - usings: []bool, // usings may not be used in tuples - packed: bool, - ordered: bool, - custom_align: bool, - } +TypeInfoRecord :: struct #ordered { + types: []^TypeInfo, + names: []string, + offsets: []int, // offsets may not be used in tuples + usings: []bool, // usings may not be used in tuples + packed: bool, + ordered: bool, + custom_align: bool, +} - TypeInfo union { - size: int, - align: int, +TypeInfo :: union { + size: int, + align: int, - Named{name: string, base: ^TypeInfo}, - Integer{signed: bool}, - Rune{}, - Float{}, - Complex{}, - String{}, - Boolean{}, - Any{}, - Pointer{ - elem: ^TypeInfo, // nil -> rawptr + Named{name: string, base: ^TypeInfo}, + Integer{signed: bool}, + Rune{}, + Float{}, + Complex{}, + String{}, + Boolean{}, + Any{}, + Pointer{ + elem: ^TypeInfo, // nil -> rawptr + }, + Atomic{elem: ^TypeInfo}, + Procedure{ + params: ^TypeInfo, // TypeInfo.Tuple + results: ^TypeInfo, // TypeInfo.Tuple + variadic: bool, + convention: CallingConvention, + }, + Array{ + elem: ^TypeInfo, + elem_size: int, + count: int, + }, + DynamicArray{elem: ^TypeInfo, elem_size: int}, + Slice {elem: ^TypeInfo, elem_size: int}, + Vector {elem: ^TypeInfo, elem_size, count: int}, + Tuple {using record: TypeInfoRecord}, // Only really used for procedures + Struct {using record: TypeInfoRecord}, + RawUnion {using record: TypeInfoRecord}, + Union{ + common_fields: struct { + types: []^TypeInfo, + names: []string, + offsets: []int, // offsets may not be used in tuples }, - Atomic{elem: ^TypeInfo}, - Procedure{ - params: ^TypeInfo, // TypeInfo.Tuple - results: ^TypeInfo, // TypeInfo.Tuple - variadic: bool, - convention: CallingConvention, - }, - Array{ - elem: ^TypeInfo, - elem_size: int, - count: int, - }, - DynamicArray{elem: ^TypeInfo, elem_size: int}, - Slice {elem: ^TypeInfo, elem_size: int}, - Vector {elem: ^TypeInfo, elem_size, count: int}, - Tuple {using record: TypeInfoRecord}, // Only really used for procedures - Struct {using record: TypeInfoRecord}, - RawUnion {using record: TypeInfoRecord}, - Union{ - common_fields: struct { - types: []^TypeInfo, - names: []string, - offsets: []int, // offsets may not be used in tuples - }, - variant_names: []string, - variant_types: []^TypeInfo, - }, - Enum{ - base: ^TypeInfo, - names: []string, - values: []TypeInfoEnumValue, - }, - Map{ - key: ^TypeInfo, - value: ^TypeInfo, - generated_struct: ^TypeInfo, - count: int, // == 0 if dynamic - }, - BitField{ - names: []string, - bits: []i32, - offsets: []i32, - }, - } -) + variant_names: []string, + variant_types: []^TypeInfo, + }, + Enum{ + base: ^TypeInfo, + names: []string, + values: []TypeInfoEnumValue, + }, + Map{ + key: ^TypeInfo, + value: ^TypeInfo, + generated_struct: ^TypeInfo, + count: int, // == 0 if dynamic + }, + BitField{ + names: []string, + bits: []i32, + offsets: []i32, + }, +} // NOTE(bill): only the ones that are needed (not all types) // This will be set by the compiler @@ -154,37 +152,35 @@ foreign __llvm_core { } // IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it) -type ( - AllocatorMode enum u8 { - Alloc, - Free, - FreeAll, - Resize, - } - AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode, - size, alignment: int, - old_memory: rawptr, old_size: int, flags: u64 = 0) -> rawptr; - Allocator struct #ordered { - procedure: AllocatorProc, - data: rawptr, - } +AllocatorMode :: enum u8 { + Alloc, + Free, + FreeAll, + Resize, +} +AllocatorProc :: proc(allocator_data: rawptr, mode: AllocatorMode, + size, alignment: int, + old_memory: rawptr, old_size: int, flags: u64 = 0) -> rawptr; +Allocator :: struct #ordered { + procedure: AllocatorProc, + data: rawptr, +} - Context struct #ordered { - thread_id: int, +Context :: struct #ordered { + thread_id: int, - allocator: Allocator, + allocator: Allocator, - user_data: rawptr, - user_index: int, - } -) + user_data: rawptr, + user_index: int, +} // #thread_local var __context: Context; -type SourceCodeLocation struct { +SourceCodeLocation :: struct { fully_pathed_filename: string, line, column: i64, procedure: string, diff --git a/core/_soft_numbers.odin b/core/_soft_numbers.odin index 536b3a090..7f6e6c058 100644 --- a/core/_soft_numbers.odin +++ b/core/_soft_numbers.odin @@ -6,12 +6,12 @@ proc __multi3(a, b: u128) -> u128 #cc_c #link_name "__multi3" { when ODIN_ENDIAN == "bit" { - type TWords raw_union { + TWords :: raw_union { all: u128, using _: struct {lo, hi: u64}, }; } else { - type TWords raw_union { + TWords :: raw_union { all: u128, using _: struct {hi, lo: u64}, }; diff --git a/core/decimal.odin b/core/decimal.odin index cbae13e36..e387bf652 100644 --- a/core/decimal.odin +++ b/core/decimal.odin @@ -2,7 +2,7 @@ // Multiple precision decimal numbers // NOTE: This is only for floating point printing and nothing else -type Decimal struct { +Decimal :: struct { digits: [384]u8, // big-endian digits count: int, decimal_point: int, diff --git a/core/fmt.odin b/core/fmt.odin index 004c470c9..1b91865f7 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -9,12 +9,12 @@ import ( _BUFFER_SIZE :: 1<<12; -type StringBuffer union { +StringBuffer :: union { Static {buf: []u8}, Dynamic{buf: [dynamic]u8}, } -type FmtInfo struct { +FmtInfo :: struct { minus: bool, plus: bool, space: bool, diff --git a/core/math.odin b/core/math.odin index 783c8f033..96ed28c69 100644 --- a/core/math.odin +++ b/core/math.odin @@ -16,18 +16,16 @@ EPSILON :: 1.19209290e-7; τ :: TAU; π :: PI; -type ( - Vec2 [vector 2]f32; - Vec3 [vector 3]f32; - Vec4 [vector 4]f32; +Vec2 :: [vector 2]f32; +Vec3 :: [vector 3]f32; +Vec4 :: [vector 4]f32; - // Column major - Mat2 [2][2]f32; - Mat3 [3][3]f32; - Mat4 [4][4]f32; +// Column major +Mat2 :: [2][2]f32; +Mat3 :: [3][3]f32; +Mat4 :: [4][4]f32; - Complex complex64; -) +Complex :: complex64; foreign __llvm_core { proc sqrt(x: f32) -> f32 #link_name "llvm.sqrt.f32"; diff --git a/core/mem.odin b/core/mem.odin index 7e42c0d5f..164caa4c5 100644 --- a/core/mem.odin +++ b/core/mem.odin @@ -52,7 +52,7 @@ proc align_forward(ptr: rawptr, align: int) -> rawptr { -type AllocationHeader struct { +AllocationHeader :: struct { size: int, } @@ -80,19 +80,19 @@ proc allocation_header(data: rawptr) -> ^AllocationHeader { // Custom allocators -type ( - Arena struct { - backing: Allocator, - offset: int, - memory: []u8, - temp_count: int, - } - ArenaTempMemory struct { - arena: ^Arena, - original_count: int, - } -) +Arena :: struct { + backing: Allocator, + offset: int, + memory: []u8, + temp_count: int, +} + +ArenaTempMemory :: struct { + arena: ^Arena, + original_count: int, +} + diff --git a/core/os_linux.odin b/core/os_linux.odin index 9aa89bf71..d3c77943f 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -4,11 +4,9 @@ foreign_system_library ( ) import "strings.odin"; -type ( - Handle i32; - FileTime u64; - Errno i32; -) +Handle :: i32; +FileTime :: u64; +Errno :: i32; O_RDONLY :: 0x00000; @@ -42,7 +40,7 @@ RTLD_GLOBAL :: 0x100; // "Argv" arguments converted to Odin strings args := _alloc_command_line_arguments(); -type _FileTime struct #ordered { +_FileTime :: struct #ordered { seconds: i64, nanoseconds: i32, reserved: i32, @@ -52,7 +50,7 @@ type _FileTime struct #ordered { // https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/jb-dev/sysroot/usr/include/bits/stat.h // Validity is not guaranteed. -type Stat struct #ordered { +Stat :: struct #ordered { device_id: u64, // ID of device containing file serial: u64, // File serial number nlink: u32, // Number of hard links diff --git a/core/os_windows.odin b/core/os_windows.odin index ec7b56df0..6bdfa1806 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -1,9 +1,8 @@ import win32 "sys/windows.odin"; -type ( - Handle int; - FileTime u64; -) +Handle :: int; +FileTime :: u64; + INVALID_HANDLE: Handle : -1; @@ -22,7 +21,7 @@ O_SYNC :: 0x01000; O_ASYNC :: 0x02000; O_CLOEXEC :: 0x80000; -type Errno int; +Errno :: int; ERROR_NONE: Errno : 0; ERROR_FILE_NOT_FOUND: Errno : 2; diff --git a/core/os_x.odin b/core/os_x.odin index 640f63b95..2ac307657 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -5,13 +5,10 @@ foreign_system_library ( import "strings.odin"; -type ( - Handle i32; - FileTime u64; - Errno int; - - AddressSize int; -) +Handle :: i32; +FileTime :: u64; +Errno :: int; +AddressSize :: int; O_RDONLY :: 0x00000; @@ -50,12 +47,12 @@ RTLD_FIRST :: 0x100; args: [dynamic]string; -type _FileTime struct #ordered { +_FileTime :: struct #ordered { seconds: i64, nanoseconds: i64 } -type Stat struct #ordered { +Stat :: struct #ordered { device_id : i32, // ID of device containing file mode : u16, // Mode of the file nlink : u16, // Number of hard links diff --git a/core/raw.odin b/core/raw.odin index e3384daf6..433fde18f 100644 --- a/core/raw.odin +++ b/core/raw.odin @@ -1,29 +1,28 @@ -type ( - Any struct #ordered { - data: rawptr, - type_info: ^TypeInfo, - }; +Any :: struct #ordered { + data: rawptr, + type_info: ^TypeInfo, +}; - String struct #ordered { - data: ^u8, - len: int, - }; +String :: struct #ordered { + data: ^u8, + len: int, +}; - Slice struct #ordered { - data: rawptr, - len: int, - cap: int, - }; +Slice :: struct #ordered { + data: rawptr, + len: int, + cap: int, +}; - DynamicArray struct #ordered { - data: rawptr, - len: int, - cap: int, - allocator: Allocator, - }; +DynamicArray :: struct #ordered { + data: rawptr, + len: int, + cap: int, + allocator: Allocator, +}; + +DynamicMap :: struct #ordered { + hashes: [dynamic]int, + entries: DynamicArray, +}; - DynamicMap struct #ordered { - hashes: [dynamic]int, - entries: DynamicArray, - }; -) diff --git a/core/strconv.odin b/core/strconv.odin index 707d15993..db0e07a2f 100644 --- a/core/strconv.odin +++ b/core/strconv.odin @@ -1,6 +1,6 @@ import . "decimal.odin"; -type IntFlag enum { +IntFlag :: enum { Prefix = 1<<0, Plus = 1<<1, Space = 1<<2, diff --git a/core/sync_linux.odin b/core/sync_linux.odin index 387c0164d..2ceb9520e 100644 --- a/core/sync_linux.odin +++ b/core/sync_linux.odin @@ -3,11 +3,11 @@ import ( "os.odin"; ) -type Semaphore struct { +Semaphore :: struct { // _handle: win32.Handle, } -type Mutex struct { +Mutex :: struct { _semaphore: Semaphore, _counter: i32, _owner: i32, diff --git a/core/sync_windows.odin b/core/sync_windows.odin index f4877b7a1..63bb50f4d 100644 --- a/core/sync_windows.odin +++ b/core/sync_windows.odin @@ -3,11 +3,11 @@ import ( "atomics.odin"; ) -type Semaphore struct { +Semaphore :: struct { _handle: win32.Handle, } -type Mutex struct { +Mutex :: struct { _semaphore: Semaphore, _counter: i32, _owner: i32, diff --git a/core/sys/wgl.odin b/core/sys/wgl.odin index b827e9ee1..f7d9d2ec0 100644 --- a/core/sys/wgl.odin +++ b/core/sys/wgl.odin @@ -10,56 +10,52 @@ CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002; CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001; CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002; -type ( - Hglrc Handle; - ColorRef u32; +Hglrc :: Handle; +ColorRef :: u32; - LayerPlaneDescriptor struct { - size: u16, - version: u16, - flags: u32, - pixel_type: u8, - color_bits: u8, - red_bits: u8, - red_shift: u8, - green_bits: u8, - green_shift: u8, - blue_bits: u8, - blue_shift: u8, - alpha_bits: u8, - alpha_shift: u8, - accum_bits: u8, - accum_red_bits: u8, - accum_green_bits: u8, - accum_blue_bits: u8, - accum_alpha_bits: u8, - depth_bits: u8, - stencil_bits: u8, - aux_buffers: u8, - layer_type: u8, - reserved: u8, - transparent: ColorRef, - } +LayerPlaneDescriptor :: struct { + size: u16, + version: u16, + flags: u32, + pixel_type: u8, + color_bits: u8, + red_bits: u8, + red_shift: u8, + green_bits: u8, + green_shift: u8, + blue_bits: u8, + blue_shift: u8, + alpha_bits: u8, + alpha_shift: u8, + accum_bits: u8, + accum_red_bits: u8, + accum_green_bits: u8, + accum_blue_bits: u8, + accum_alpha_bits: u8, + depth_bits: u8, + stencil_bits: u8, + aux_buffers: u8, + layer_type: u8, + reserved: u8, + transparent: ColorRef, +} - PointFloat struct { - x, y: f32, - } +PointFloat :: struct { + x, y: f32, +} - Glyph_MetricsFloat struct { - black_box_x: f32, - black_box_y: f32, - glyph_origin: PointFloat, - cell_inc_x: f32, - cell_inc_y: f32, - } -) +Glyph_MetricsFloat :: struct { + black_box_x: f32, + black_box_y: f32, + glyph_origin: PointFloat, + cell_inc_x: f32, + cell_inc_y: f32, +} -type ( - CreateContextAttribsARBType proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc; - ChoosePixelFormatARBType proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c; - SwapIntervalEXTType proc(interval: i32) -> bool #cc_c; - GetExtensionsStringARBType proc(Hdc) -> ^u8 #cc_c; -) +CreateContextAttribsARBType :: proc(hdc: Hdc, h_share_context: rawptr, attribList: ^i32) -> Hglrc; +ChoosePixelFormatARBType :: proc(hdc: Hdc, attrib_i_list: ^i32, attrib_f_list: ^f32, max_formats: u32, formats: ^i32, num_formats : ^u32) -> Bool #cc_c; +SwapIntervalEXTType :: proc(interval: i32) -> bool #cc_c; +GetExtensionsStringARBType :: proc(Hdc) -> ^u8 #cc_c; // Procedures create_context_attribs_arb: CreateContextAttribsARBType; diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 6258b9480..406cb0fb4 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -6,25 +6,23 @@ foreign_system_library ( "shell32.lib" when ODIN_OS == "windows"; ) -type ( - Handle rawptr; - Hwnd Handle; - Hdc Handle; - Hinstance Handle; - Hicon Handle; - Hcursor Handle; - Hmenu Handle; - Hbrush Handle; - Hgdiobj Handle; - Hmodule Handle; - Hmonitor Handle; - Wparam uint; - Lparam int; - Lresult int; - WndProc proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c; -) +Handle :: rawptr; +Hwnd :: Handle; +Hdc :: Handle; +Hinstance :: Handle; +Hicon :: Handle; +Hcursor :: Handle; +Hmenu :: Handle; +Hbrush :: Handle; +Hgdiobj :: Handle; +Hmodule :: Handle; +Hmonitor :: Handle; +Wparam :: uint; +Lparam :: int; +Lresult :: int; +WndProc :: proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c; -type Bool i32; +Bool :: i32; FALSE: Bool : 0; TRUE: Bool : 1; @@ -147,7 +145,7 @@ PixelFormatDescriptor :: struct #ordered { -type Proc proc() #cc_c; +Proc :: proc() #cc_c; MAPVK_VK_TO_VSC :: 0; MAPVK_VSC_TO_VK :: 1; @@ -268,7 +266,7 @@ PFD_DEPTH_DONTCARE :: 0x20000000; PFD_DOUBLEBUFFER_DONTCARE :: 0x40000000; PFD_STEREO_DONTCARE :: 0x80000000; -type GET_FILEEX_INFO_LEVELS i32; +GET_FILEEX_INFO_LEVELS :: i32; GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS : 0; GetFileExMaxInfoLevel: GET_FILEEX_INFO_LEVELS : 1; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 8d375d548..6bd05986a 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -194,7 +194,7 @@ void check_const_decl(Checker *c, Entity *e, AstNode *type_expr, AstNode *init, if (init != NULL) { check_expr_or_type(c, &operand, init); } -#if 0 +#if 1 if (operand.mode == Addressing_Type) { e->kind = Entity_TypeName; diff --git a/src/parser.cpp b/src/parser.cpp index 0931dba1c..0d0692202 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3033,10 +3033,12 @@ void parse_foreign_block_decl(AstFile *f, Array *decls) { case AstNode_BadDecl: return; + case AstNode_ValueDecl: case AstNode_ProcDecl: array_add(decls, decl); return; + case AstNode_GenDecl: switch (decl->GenDecl.token.kind) { case Token_var: @@ -3170,12 +3172,6 @@ AstNode *parse_value_decl(AstFile *f, Array names, CommentGroup docs) AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) { Token token = f->curr_token; - switch (f->curr_token.kind) { - case Token_var: - case Token_const: - return parse_decl(f); - } - CommentGroup docs = f->lead_comment; Array lhs = parse_lhs_expr_list(f); @@ -4333,7 +4329,7 @@ AstNode *parse_stmt(AstFile *f) { // case Token_var: // case Token_const: case Token_proc: - case Token_type: + // case Token_type: case Token_import: case Token_import_load: case Token_foreign: