diff --git a/core/_preload.odin b/core/_preload.odin index 6986b0e72..a8344b2b8 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -1,11 +1,11 @@ #shared_global_scope; -import ( +import { "os.odin"; "fmt.odin"; "utf8.odin"; "raw.odin"; -) +} // Naming Conventions: // In general, PascalCase for types and snake_case for values // @@ -25,7 +25,7 @@ import ( // IMPORTANT NOTE(bill): Do not change the order of any of this data // The compiler relies upon this _exact_ order -type ( +type { TypeInfoEnumValue raw_union { f: f64, i: i128, @@ -107,16 +107,16 @@ type ( offsets: []i32, }, } -) +} // NOTE(bill): only the ones that are needed (not all types) // This will be set by the compiler -var ( +var { __type_table: []TypeInfo; __argv__: ^^u8; __argc__: i32; -) +} proc type_info_base(info: ^TypeInfo) -> ^TypeInfo { if info == nil { @@ -155,7 +155,7 @@ foreign __llvm_core { } // IMPORTANT NOTE(bill): Must be in this order (as the compiler relies upon it) -type ( +type { AllocatorMode enum u8 { Alloc, Free, @@ -179,7 +179,7 @@ type ( user_data: rawptr, user_index: int, } -) +} #thread_local var __context: Context; @@ -561,7 +561,7 @@ proc __default_hash_string(s: string) -> u128 { const __INITIAL_MAP_CAP = 16; -type ( +type { __MapKey struct #ordered { hash: u128, str: string, @@ -589,7 +589,7 @@ type ( value_offset: int, value_size: int, } -) +} proc __dynamic_map_reserve(using header: __MapHeader, cap: int) { __dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap); diff --git a/core/bits.odin b/core/bits.odin index e65135018..c993c72eb 100644 --- a/core/bits.odin +++ b/core/bits.odin @@ -1,4 +1,4 @@ -const ( +const { U8_MIN = u8(0); U16_MIN = u16(0); U32_MIN = u32(0); @@ -22,7 +22,7 @@ const ( I32_MAX = i32(0x7fff_ffff); I64_MAX = i64(0x7fff_ffff_ffff_ffff); I128_MAX = i128(0x7fff_ffff_ffff_ffff_ffff_ffff_ffff_ffff); -) +} proc count_ones(i: u8) -> u8 { foreign __llvm_core proc __llvm_ctpop(u8) -> u8 #link_name "llvm.ctpop.i8"; return __llvm_ctpop(i); } proc count_ones(i: i8) -> i8 { foreign __llvm_core proc __llvm_ctpop(i8) -> i8 #link_name "llvm.ctpop.i8"; return __llvm_ctpop(i); } diff --git a/core/decimal.odin b/core/decimal.odin index 9c982003c..babe46306 100644 --- a/core/decimal.odin +++ b/core/decimal.odin @@ -170,10 +170,10 @@ proc shift_left(a: ^Decimal, k: uint) { } proc shift(a: ^Decimal, k: int) { - const ( + const { uint_size = 8*size_of(uint); max_shift = uint_size-4; - ) + } match { case a.count == 0: diff --git a/core/fmt.odin b/core/fmt.odin index 4d0ea9e98..8a8608a18 100644 --- a/core/fmt.odin +++ b/core/fmt.odin @@ -1,11 +1,11 @@ -import ( +import { "os.odin"; "mem.odin"; "utf8.odin"; "types.odin"; "strconv.odin"; "raw.odin"; -) +} const _BUFFER_SIZE = 1<<12; @@ -583,10 +583,10 @@ proc _fmt_int(fi: ^FmtInfo, u: u128, base: int, is_signed: bool, bit_size: int, _pad(fi, s); } -let ( +let { __DIGITS_LOWER = "0123456789abcdefx"; __DIGITS_UPPER = "0123456789ABCDEFX"; -) +} proc fmt_rune(fi: ^FmtInfo, r: rune, verb: rune) { match verb { @@ -734,12 +734,12 @@ proc fmt_enum(fi: ^FmtInfo, v: any, verb: rune) { case 'd', 'f': fmt_arg(fi, any{v.data, type_info_base(e.base)}, verb); case 's', 'v': - var ( + var { i: i128; f: f64; ok: bool; a: any; - ) + } a = any{v.data, type_info_base(e.base)}; match v in a { case rune: i = i128(v); @@ -898,13 +898,13 @@ proc fmt_value(fi: ^FmtInfo, v: any, verb: rune) { write_string(fi.buf, "map["); defer write_byte(fi.buf, ']'); - var ( + var { entries = &(^raw.DynamicMap(v.data).entries); gs = type_info_base(info.generated_struct).(^Struct); ed = type_info_base(gs.types[1]).(^DynamicArray); entry_type = ed.elem.(^Struct); entry_size = ed.elem_size; - ) + } for i in 0.. 0 { write_string(fi.buf, ", "); @@ -1081,12 +1081,12 @@ proc sbprintln(buf: ^StringBuffer, args: ..any) -> string { } proc sbprintf(b: ^StringBuffer, fmt: string, args: ..any) -> string { - var ( + var { end = len(fmt); arg_index: int = 0; was_prev_index = false; fi: FmtInfo; - ) + } for var i = 0; i < end; /**/ { fi = FmtInfo{buf = b, good_arg_index = true}; diff --git a/core/hash.odin b/core/hash.odin index 336a7bfde..6b5cb4a83 100644 --- a/core/hash.odin +++ b/core/hash.odin @@ -46,17 +46,17 @@ proc fnv64a(data: []u8) -> u64 { } proc murmur32(data: []u8) -> u32 { - const ( + const { c1_32: u32 = 0xcc9e2d51; c2_32: u32 = 0x1b873593; - ) + } - var ( + var { h1: u32 = 0; nblocks = len(data)/4; p = &data[0]; p1 = p + 4*nblocks; - ) + } for ; p < p1; p += 4 { var k1 = ^u32(p)^; @@ -102,10 +102,10 @@ proc murmur64(data: []u8) -> u64 { const SEED = 0x9747b28c; when size_of(int) == 8 { - const ( + const { m = 0xc6a4a7935bd1e995; r = 47; - ) + } var h: u64 = SEED ~ (u64(len(data)) * m); var data64 = slice_ptr(^u64(&data[0]), len(data)/size_of(u64)); @@ -139,18 +139,18 @@ proc murmur64(data: []u8) -> u64 { return h; } else { - const ( + const { m = 0x5bd1e995; r = 24; - ) + } - var ( + var { h1 = u32(SEED) ~ u32(len(data)); h2 = u32(SEED) >> 32; data32 = slice_ptr(^u32(&data[0]), len(data)/size_of(u32)); len = len(data); i = 0; - ) + } for len >= 8 { var k1, k2: u32; diff --git a/core/math.odin b/core/math.odin index 8a6c492ee..48848c79b 100644 --- a/core/math.odin +++ b/core/math.odin @@ -1,4 +1,4 @@ -const ( +const { TAU = 6.28318530717958647692528676655900576; PI = 3.14159265358979323846264338327950288; ONE_OVER_TAU = 0.636619772367581343075535053490057448; @@ -16,8 +16,8 @@ const ( τ = TAU; π = PI; -) -type ( +} +type { Vec2 [vector 2]f32; Vec3 [vector 3]f32; Vec4 [vector 4]f32; @@ -28,7 +28,7 @@ type ( Mat4 [4][4]f32; Complex complex64; -) +} foreign __llvm_core { proc sqrt(x: f32) -> f32 #link_name "llvm.sqrt.f32"; @@ -203,7 +203,7 @@ proc mul(m: Mat4, v: Vec4) -> Vec4 { proc inverse(m: Mat4) -> Mat4 { var o: Mat4; - var ( + var { sf00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; sf01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; sf02 = m[2][1] * m[3][2] - m[3][1] * m[2][2]; @@ -223,7 +223,7 @@ proc inverse(m: Mat4) -> Mat4 { sf16 = m[1][0] * m[2][3] - m[2][0] * m[1][3]; sf17 = m[1][0] * m[2][2] - m[2][0] * m[1][2]; sf18 = m[1][0] * m[2][1] - m[2][0] * m[1][1]; - ) + } o[0][0] = +(m[1][1] * sf00 - m[1][2] * sf01 + m[1][3] * sf02); o[0][1] = -(m[1][0] * sf00 - m[1][2] * sf03 + m[1][3] * sf04); @@ -281,7 +281,7 @@ proc mat4_translate(v: Vec3) -> Mat4 { } proc mat4_rotate(v: Vec3, angle_radians: f32) -> Mat4 { - var ( + var { c = cos(angle_radians); s = sin(angle_radians); @@ -289,7 +289,7 @@ proc mat4_rotate(v: Vec3, angle_radians: f32) -> Mat4 { t = a * (1-c); rot = mat4_identity(); - ) + } rot[0][0] = c + t.x*a.x; rot[0][1] = 0 + t.x*a.y + s*a.z; @@ -325,11 +325,11 @@ proc scale(m: Mat4, s: f32) -> Mat4 { proc look_at(eye, centre, up: Vec3) -> Mat4 { - var ( + var { f = norm(centre - eye); s = norm(cross(f, up)); u = cross(s, f); - ) + } return Mat4{ {+s.x, +u.x, -f.x, 0}, @@ -340,10 +340,10 @@ proc look_at(eye, centre, up: Vec3) -> Mat4 { } proc perspective(fovy, aspect, near, far: f32) -> Mat4 { - var ( + var { m: Mat4; tan_half_fovy = tan(0.5 * fovy); - ) + } m[0][0] = 1.0 / (aspect*tan_half_fovy); m[1][1] = 1.0 / (tan_half_fovy); m[2][2] = -(far + near) / (far - near); @@ -367,7 +367,7 @@ proc ortho3d(left, right, bottom, top, near, far: f32) -> Mat4 { -const ( +const { F32_DIG = 6; F32_EPSILON = 1.192092896e-07; F32_GUARD = 0; @@ -393,4 +393,4 @@ const ( F64_MIN_EXP = -1021; // min binary exponent F64_RADIX = 2; // exponent radix F64_ROUNDS = 1; // addition rounding: near -) +} diff --git a/core/mem.odin b/core/mem.odin index dd40fb006..5b89624b6 100644 --- a/core/mem.odin +++ b/core/mem.odin @@ -1,7 +1,7 @@ -import ( +import { "fmt.odin"; "os.odin"; -) +} foreign __llvm_core { proc swap(b: u16) -> u16 #link_name "llvm.bswap.i16"; proc swap(b: u32) -> u32 #link_name "llvm.bswap.i32"; @@ -80,7 +80,7 @@ proc allocation_header(data: rawptr) -> ^AllocationHeader { // Custom allocators -type ( +type { Arena struct { backing: Allocator, offset: int, @@ -92,7 +92,7 @@ type ( arena: ^Arena, original_count: int, } -) +} diff --git a/core/opengl.odin b/core/opengl.odin index 2be7b05cc..94f9f6b67 100644 --- a/core/opengl.odin +++ b/core/opengl.odin @@ -1,11 +1,11 @@ -foreign_system_library ( +foreign_system_library { lib "opengl32.lib" when ODIN_OS == "windows"; lib "gl" when ODIN_OS == "linux"; -) -import ( +} +import { win32 "sys/windows.odin" when ODIN_OS == "windows"; "sys/wgl.odin" when ODIN_OS == "windows"; -) +} import_load "opengl_constants.odin"; foreign lib { @@ -54,7 +54,7 @@ proc get_proc_address(name: string) -> proc() #cc_c { return res; } -var ( +var { GenBuffers: proc(count: i32, buffers: ^u32) #cc_c; GenVertexArrays: proc(count: i32, buffers: ^u32) #cc_c; GenSamplers: proc(count: i32, buffers: ^u32) #cc_c; @@ -114,7 +114,7 @@ var ( UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32) #cc_c; GetUniformLocation: proc(program: u32, name: ^u8) -> i32 #cc_c; -) +} proc init() { proc set_proc_address(p: rawptr, name: string) #inline { diff --git a/core/opengl_constants.odin b/core/opengl_constants.odin index eff1fd8b6..4f3037037 100644 --- a/core/opengl_constants.odin +++ b/core/opengl_constants.odin @@ -1,4 +1,4 @@ -const ( +const { FALSE = 0; TRUE = 1; @@ -1382,4 +1382,4 @@ const ( DEBUG_SEVERITY_HIGH_ARB = 0x9146; DEBUG_SEVERITY_MEDIUM_ARB = 0x9147; DEBUG_SEVERITY_LOW_ARB = 0x9148; -) +} diff --git a/core/os.odin b/core/os.odin index cf326d48d..6e69b090d 100644 --- a/core/os.odin +++ b/core/os.odin @@ -1,8 +1,8 @@ -import_load ( +import_load { "os_windows.odin" when ODIN_OS == "windows"; "os_x.odin" when ODIN_OS == "osx"; "os_linux.odin" when ODIN_OS == "linux"; -) +} proc write_string(fd: Handle, str: string) -> (int, Errno) { return write(fd, []u8(str)); diff --git a/core/os_linux.odin b/core/os_linux.odin index dd0e6049f..584a7578d 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -1,16 +1,16 @@ -foreign_system_library ( +foreign_system_library { dl "dl"; libc "c"; -) +} import "strings.odin"; -type ( +type { Handle i32; FileTime u64; Errno i32; -) +} -const ( +const { O_RDONLY = 0x00000; O_WRONLY = 0x00001; O_RDWR = 0x00002; @@ -23,20 +23,24 @@ const ( O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; +} + +const { SEEK_SET = 0; SEEK_CUR = 1; SEEK_END = 2; SEEK_DATA = 3; SEEK_HOLE = 4; SEEK_MAX = SEEK_HOLE; - +} +const { // NOTE(zangent): These are OS specific! // Do not mix these up! RTLD_LAZY = 0x001; RTLD_NOW = 0x002; RTLD_BINDING_MASK = 0x3; RTLD_GLOBAL = 0x100; -) +} // "Argv" arguments converted to Odin strings let args = _alloc_command_line_arguments(); @@ -76,7 +80,7 @@ type Stat struct #ordered { }; // File type -const ( +const { S_IFMT = 0170000; // Type of file mask S_IFIFO = 0010000; // Named pipe (fifo) S_IFCHR = 0020000; // Character special @@ -108,7 +112,7 @@ const ( S_ISUID = 0004000; // Set user id on execution S_ISGID = 0002000; // Set group id on execution S_ISVTX = 0001000; // Directory restrcted delete -) +} proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; } proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; } @@ -118,12 +122,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; } proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; } proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;} -const ( +const { R_OK = 4; // Test for read permission W_OK = 2; // Test for write permission X_OK = 1; // Test for execute permission F_OK = 0; // Test for file existance -) +} foreign libc { proc _unix_open (path: ^u8, mode: int) -> Handle #link_name "open"; @@ -193,11 +197,11 @@ proc file_size(fd: Handle) -> (i64, Errno) { // NOTE(bill): Uses startup to initialize it -var ( +var { stdin: Handle = 0; stdout: Handle = 1; stderr: Handle = 2; -) +} /* TODO(zangent): Implement these! proc last_write_time(fd: Handle) -> FileTime {} proc last_write_time_by_name(name: string) -> FileTime {} diff --git a/core/os_windows.odin b/core/os_windows.odin index ab5e676e3..d73966895 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -1,14 +1,14 @@ import win32 "sys/windows.odin"; -type ( +type { Handle int; FileTime u64; - Errno int; -) +} -const ( - INVALID_HANDLE: Handle = -1; +const INVALID_HANDLE: Handle = -1; + +const { O_RDONLY = 0x00000; O_WRONLY = 0x00001; O_RDWR = 0x00002; @@ -21,34 +21,37 @@ const ( O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; +} - ERROR_NONE: Errno = 0; - ERROR_FILE_NOT_FOUND: Errno = 2; - ERROR_PATH_NOT_FOUND: Errno = 3; - ERROR_ACCESS_DENIED: Errno = 5; - ERROR_NO_MORE_FILES: Errno = 18; - ERROR_HANDLE_EOF: Errno = 38; - ERROR_NETNAME_DELETED: Errno = 64; - ERROR_FILE_EXISTS: Errno = 80; - ERROR_BROKEN_PIPE: Errno = 109; - ERROR_BUFFER_OVERFLOW: Errno = 111; - ERROR_INSUFFICIENT_BUFFER: Errno = 122; - ERROR_MOD_NOT_FOUND: Errno = 126; - ERROR_PROC_NOT_FOUND: Errno = 127; - ERROR_DIR_NOT_EMPTY: Errno = 145; - ERROR_ALREADY_EXISTS: Errno = 183; - ERROR_ENVVAR_NOT_FOUND: Errno = 203; - ERROR_MORE_DATA: Errno = 234; - ERROR_OPERATION_ABORTED: Errno = 995; - ERROR_IO_PENDING: Errno = 997; - ERROR_NOT_FOUND: Errno = 1168; - ERROR_PRIVILEGE_NOT_HELD: Errno = 1314; - WSAEACCES: Errno = 10013; - WSAECONNRESET: Errno = 10054; +type Errno int; +const { + ERROR_NONE: Errno = 0; + ERROR_FILE_NOT_FOUND = 2; + ERROR_PATH_NOT_FOUND = 3; + ERROR_ACCESS_DENIED = 5; + ERROR_NO_MORE_FILES = 18; + ERROR_HANDLE_EOF = 38; + ERROR_NETNAME_DELETED = 64; + ERROR_FILE_EXISTS = 80; + ERROR_BROKEN_PIPE = 109; + ERROR_BUFFER_OVERFLOW = 111; + ERROR_INSUFFICIENT_BUFFER = 122; + ERROR_MOD_NOT_FOUND = 126; + ERROR_PROC_NOT_FOUND = 127; + ERROR_DIR_NOT_EMPTY = 145; + ERROR_ALREADY_EXISTS = 183; + ERROR_ENVVAR_NOT_FOUND = 203; + ERROR_MORE_DATA = 234; + ERROR_OPERATION_ABORTED = 995; + ERROR_IO_PENDING = 997; + ERROR_NOT_FOUND = 1168; + ERROR_PRIVILEGE_NOT_HELD = 1314; + WSAEACCES = 10013; + WSAECONNRESET = 10054; // Windows reserves errors >= 1<<29 for application use - ERROR_FILE_IS_PIPE: Errno = 1<<29 + 0; -) + ERROR_FILE_IS_PIPE = 1<<29 + 0; +} // "Argv" arguments converted to Odin strings let args = _alloc_command_line_arguments(); diff --git a/core/os_x.odin b/core/os_x.odin index 8a9ab8488..48b3780ae 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -1,19 +1,19 @@ -foreign_system_library ( +foreign_system_library { dl "dl"; libc "c"; -) +} import "strings.odin"; -type ( +type { Handle i32; FileTime u64; Errno int; AddressSize int; -) +} -const ( +const { O_RDONLY = 0x00000; O_WRONLY = 0x00001; O_RDWR = 0x00002; @@ -26,13 +26,17 @@ const ( O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; +} +const { SEEK_SET = 0; SEEK_CUR = 1; SEEK_END = 2; SEEK_DATA = 3; SEEK_HOLE = 4; SEEK_MAX = SEEK_HOLE; +} +const { // NOTE(zangent): These are OS specific! // Do not mix these up! RTLD_LAZY = 0x1; @@ -42,7 +46,7 @@ const ( RTLD_NODELETE = 0x80; RTLD_NOLOAD = 0x10; RTLD_FIRST = 0x100; -) +} var args: [dynamic]string; @@ -76,7 +80,7 @@ type Stat struct #ordered { }; // File type -const ( +const { S_IFMT = 0170000; // Type of file mask S_IFIFO = 0010000; // Named pipe (fifo) S_IFCHR = 0020000; // Character special @@ -108,7 +112,7 @@ const ( S_ISUID = 0004000; // Set user id on execution S_ISGID = 0002000; // Set group id on execution S_ISVTX = 0001000; // Directory restrcted delete -) +} proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; } proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; } @@ -118,12 +122,12 @@ proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; } proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; } proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;} -const ( +const { R_OK = 4; // Test for read permission W_OK = 2; // Test for write permission X_OK = 1; // Test for execute permission F_OK = 0; // Test for file existance -) +} foreign libc { proc unix_open (path: ^u8, mode: int) -> Handle #link_name "open"; @@ -211,11 +215,11 @@ proc file_size(fd: Handle) -> (i64, Errno) { // NOTE(bill): Uses startup to initialize it -var ( +var { stdin: Handle = 0; // get_std_handle(win32.STD_INPUT_HANDLE); stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE); stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE); -) +} /* TODO(zangent): Implement these! proc last_write_time(fd: Handle) -> FileTime {} proc last_write_time_by_name(name: string) -> FileTime {} diff --git a/core/raw.odin b/core/raw.odin index e3384daf6..e264dab3c 100644 --- a/core/raw.odin +++ b/core/raw.odin @@ -1,4 +1,4 @@ -type ( +type { Any struct #ordered { data: rawptr, type_info: ^TypeInfo, @@ -26,4 +26,4 @@ type ( hashes: [dynamic]int, entries: DynamicArray, }; -) +} diff --git a/core/strconv.odin b/core/strconv.odin index 9800823f2..b0d280ae2 100644 --- a/core/strconv.odin +++ b/core/strconv.odin @@ -223,11 +223,11 @@ type Float_Info struct { bias: int, } -var ( +var { _f16_info = Float_Info{10, 5, -15}; _f32_info = Float_Info{23, 8, -127}; _f64_info = Float_Info{52, 11, -1023}; -) +} proc generic_ftoa(buf: []u8, val: f64, fmt: u8, prec, bit_size: int) -> []u8 { var bits: u64; diff --git a/core/sync.odin b/core/sync.odin index ad08f0b18..63200fda6 100644 --- a/core/sync.odin +++ b/core/sync.odin @@ -1,4 +1,4 @@ -import_load ( +import_load { "sync_windows.odin" when ODIN_OS == "windows"; "sync_linux.odin" when ODIN_OS == "linux"; -) +} diff --git a/core/sync_linux.odin b/core/sync_linux.odin index c3fc649b9..3daa526fb 100644 --- a/core/sync_linux.odin +++ b/core/sync_linux.odin @@ -1,7 +1,7 @@ -import ( +import { "atomics.odin"; "os.odin"; -) +} type Semaphore struct { // _handle: win32.Handle, diff --git a/core/sync_windows.odin b/core/sync_windows.odin index 353fb755f..524124d36 100644 --- a/core/sync_windows.odin +++ b/core/sync_windows.odin @@ -1,7 +1,7 @@ -import ( +import { win32 "sys/windows.odin" when ODIN_OS == "windows"; "atomics.odin"; -) +} type Semaphore struct { _handle: win32.Handle, diff --git a/core/sys/wgl.odin b/core/sys/wgl.odin index a668790d5..c02bd3805 100644 --- a/core/sys/wgl.odin +++ b/core/sys/wgl.odin @@ -1,7 +1,7 @@ foreign_system_library "opengl32.lib" when ODIN_OS == "windows"; import . "windows.odin"; -const ( +const { CONTEXT_MAJOR_VERSION_ARB = 0x2091; CONTEXT_MINOR_VERSION_ARB = 0x2092; CONTEXT_FLAGS_ARB = 0x2094; @@ -9,9 +9,9 @@ const ( CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002; CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001; CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002; -) +} -type ( +type { Hglrc Handle; ColorRef u32; @@ -53,21 +53,21 @@ type ( cell_inc_x: f32, cell_inc_y: f32, } -) +} -type ( +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; -) +} -var ( +var { create_context_attribs_arb: CreateContextAttribsARBType; choose_pixel_format_arb: ChoosePixelFormatARBType; swap_interval_ext: SwapIntervalEXTType; get_extensions_string_arb: GetExtensionsStringARBType; -) +} foreign opengl32 { diff --git a/core/sys/windows.odin b/core/sys/windows.odin index a6b758e5c..91ec9bc1b 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -1,12 +1,12 @@ -foreign_system_library ( +foreign_system_library { "kernel32.lib" when ODIN_OS == "windows"; "user32.lib" when ODIN_OS == "windows"; "gdi32.lib" when ODIN_OS == "windows"; "winmm.lib" when ODIN_OS == "windows"; "shell32.lib" when ODIN_OS == "windows"; -) +} -type ( +type { Handle rawptr; Hwnd Handle; Hdc Handle; @@ -21,10 +21,14 @@ type ( Wparam uint; Lparam int; Lresult int; - Bool i32; WndProc proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c; +} -) +type Bool i32; +const { + FALSE: Bool = 0; + TRUE = 1; +} type Point struct #ordered { x, y: i32, @@ -147,22 +151,19 @@ type PixelFormatDescriptor struct #ordered { type Proc proc() #cc_c; -const ( +const { MAPVK_VK_TO_CHAR = 2; MAPVK_VK_TO_VSC = 0; MAPVK_VSC_TO_VK = 1; MAPVK_VSC_TO_VK_EX = 3; -) +} const INVALID_HANDLE = Handle(~int(0)); -const ( - FALSE: Bool = 0; - TRUE = 1; -) -const ( + +const { CS_VREDRAW = 0x0001; CS_HREDRAW = 0x0002; CS_OWNDC = 0x0020; @@ -220,7 +221,7 @@ const ( SM_CYSCREEN = 1; SW_SHOW = 5; -) +} const COLOR_BACKGROUND = Hbrush(int(1)); @@ -234,24 +235,24 @@ const BI_RGB = 0; const DIB_RGB_COLORS = 0x00; const SRCCOPY: u32 = 0x00cc0020; -const ( +const { MONITOR_DEFAULTTONULL = 0x00000000; MONITOR_DEFAULTTOPRIMARY = 0x00000001; MONITOR_DEFAULTTONEAREST = 0x00000002; -) -const ( +} +const { SWP_FRAMECHANGED = 0x0020; SWP_NOOWNERZORDER = 0x0200; SWP_NOZORDER = 0x0004; SWP_NOSIZE = 0x0001; SWP_NOMOVE = 0x0002; -) +} // Windows OpenGL -const ( +const { PFD_TYPE_RGBA = 0; PFD_TYPE_COLORINDEX = 1; PFD_MAIN_PLANE = 0; @@ -273,15 +274,15 @@ const ( PFD_DEPTH_DONTCARE = 0x20000000; PFD_DOUBLEBUFFER_DONTCARE = 0x40000000; PFD_STEREO_DONTCARE = 0x80000000; -) +} type GET_FILEEX_INFO_LEVELS i32; -const ( +const { GetFileExInfoStandard: GET_FILEEX_INFO_LEVELS = 0; GetFileExMaxInfoLevel = 1; -) +} foreign kernel32 { proc get_last_error () -> i32 #link_name "GetLastError"; @@ -462,7 +463,7 @@ proc is_key_down(key: KeyCode) -> bool #inline { return get_async_key_state(i32( -const ( +const { MAX_PATH = 0x00000104; HANDLE_FLAG_INHERIT = 1; @@ -512,7 +513,7 @@ const ( FILE_TYPE_DISK = 0x0001; FILE_TYPE_CHAR = 0x0002; FILE_TYPE_PIPE = 0x0003; -) +} type MonitorInfo struct #ordered { diff --git a/core/utf16.odin b/core/utf16.odin index a996a334b..0168ff71a 100644 --- a/core/utf16.odin +++ b/core/utf16.odin @@ -1,4 +1,4 @@ -const ( +const { REPLACEMENT_CHAR = '\uFFFD'; MAX_RUNE = '\U0010FFFF'; @@ -6,7 +6,7 @@ const ( _surr2 = 0xdc00; _surr3 = 0xe000; _surr_self = 0x10000; -) +} proc is_surrogate(r: rune) -> bool { return _surr1 <= r && r < _surr3; diff --git a/core/utf8.odin b/core/utf8.odin index b6bd7fbab..855a5279c 100644 --- a/core/utf8.odin +++ b/core/utf8.odin @@ -1,4 +1,4 @@ -const ( +const { RUNE_ERROR = '\ufffd'; RUNE_SELF = 0x80; RUNE_BOM = 0xfeff; @@ -28,11 +28,11 @@ const ( // The default lowest and highest continuation byte. LOCB = 0b1000_0000; HICB = 0b1011_1111; -) +} type AcceptRange struct { lo, hi: u8 } -let ( +let { accept_ranges = [5]AcceptRange{ {0x80, 0xbf}, {0xa0, 0xbf}, @@ -60,7 +60,7 @@ let ( 0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef 0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff }; -) +} proc encode_rune(r: rune) -> ([4]u8, int) { var buf: [4]u8; diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 18c76dd5d..60da85d0e 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -349,7 +349,6 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) { } e->Procedure.is_foreign = true; - e->Procedure.foreign_name = name; e->Procedure.link_name = name; HashKey key = hash_string(name); diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 2d0c94438..5a227ebce 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1545,11 +1545,6 @@ Entity *check_ident(Checker *c, Operand *o, AstNode *n, Type *named_type, Type * } break; - case Entity_TypeAlias: - case Entity_TypeName: - o->mode = Addressing_Type; - break; - case Entity_Procedure: o->mode = Addressing_Value; break; @@ -3530,7 +3525,6 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h operand->mode = Addressing_Value; } break; - case Entity_TypeAlias: case Entity_TypeName: operand->mode = Addressing_Type; break; diff --git a/src/checker.cpp b/src/checker.cpp index df41c9f86..1647ceaee 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -609,10 +609,6 @@ void add_global_string_constant(gbAllocator a, String name, String value) { } -Type *add_global_type_alias(gbAllocator a, String name, Type *t) { - Entity *e = add_global_entity(make_entity_type_alias(a, NULL, make_token_ident(name), t)); - return e->type; -} void init_universal_scope(void) { diff --git a/src/entity.cpp b/src/entity.cpp index 32bd3210f..6fa89d652 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -14,8 +14,6 @@ struct DeclInfo; ENTITY_KIND(Builtin) \ ENTITY_KIND(ImportName) \ ENTITY_KIND(LibraryName) \ - ENTITY_KIND(TypeAlias) \ - ENTITY_KIND(ProcedureAlias) \ ENTITY_KIND(Nil) \ ENTITY_KIND(Label) @@ -92,13 +90,12 @@ struct Entity { bool is_type_alias; } TypeName; struct { - bool is_foreign; - String foreign_name; - Entity * foreign_library; - AstNode * foreign_library_ident; + OverloadKind overload_kind; String link_name; u64 tags; - OverloadKind overload_kind; + bool is_foreign; + Entity * foreign_library; + AstNode * foreign_library_ident; } Procedure; struct { i32 id; @@ -114,10 +111,6 @@ struct Entity { String name; bool used; } LibraryName; - i32 TypeAlias; - struct { - Entity *original; - } ProcedureAlias; i32 Nil; struct { String name; @@ -248,16 +241,6 @@ Entity *make_entity_library_name(gbAllocator a, Scope *scope, Token token, Type return entity; } -Entity *make_entity_type_alias(gbAllocator a, Scope *scope, Token token, Type *type) { - Entity *entity = alloc_entity(a, Entity_TypeAlias, scope, token, type); - return entity; -} -Entity *make_entity_procedure_alias(gbAllocator a, Scope *scope, Token token, Entity *original) { - GB_ASSERT(original != NULL); - Entity *entity = alloc_entity(a, Entity_ProcedureAlias, scope, token, original->type); - entity->ProcedureAlias.original = original; - return entity; -} diff --git a/src/parser.cpp b/src/parser.cpp index cd0e78c2a..8d7af3188 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2553,16 +2553,16 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) { Token open = {}; Token close = {}; - if (f->curr_token.kind == Token_OpenParen) { + if (f->curr_token.kind == Token_OpenBrace) { specs = make_ast_node_array(f); - open = expect_token(f, Token_OpenParen); - while (f->curr_token.kind != Token_CloseParen && + open = expect_token(f, Token_OpenBrace); + while (f->curr_token.kind != Token_CloseBrace && f->curr_token.kind != Token_EOF) { AstNode *spec = func(f, token); array_add(&specs, spec); expect_semicolon(f, spec); } - close = expect_token(f, Token_CloseParen); + close = expect_token(f, Token_CloseBrace); if (f->curr_token.pos.line == close.pos.line || open.pos.line == close.pos.line) { expect_semicolon(f, NULL);