diff --git a/build.sh b/build.sh index d27e97c50..b8b8fda10 100755 --- a/build.sh +++ b/build.sh @@ -2,8 +2,8 @@ release_mode=0 -warnings_to_disable="-std=c11 -Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined" -libraries="-pthread -ldl -lm" +warnings_to_disable="-std=c++11 -g -Wno-switch -Wno-pointer-sign -Wno-tautological-constant-out-of-range-compare -Wno-tautological-compare -Wno-macro-redefined" +libraries="-pthread -ldl -lm -lstdc++" other_args="" compiler="clang" @@ -19,6 +19,6 @@ if [[ "$(uname)" == "Darwin" ]]; then other_args="${other_args} -liconv" fi -${compiler} src/main.c ${warnings_to_disable} ${libraries} ${other_args} -o odin +${compiler} src/main.cpp ${warnings_to_disable} ${libraries} ${other_args} -o odin ./odin run code/demo.odin diff --git a/code/demo.odin b/code/demo.odin index 0db3e0b55..e42429953 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,4 +1,6 @@ -import "fmt.odin"; +import ( + "fmt.odin"; +) proc main() { let program = "+ + * - /"; diff --git a/core/_preload.odin b/core/_preload.odin index a8344b2b8..df6b2e79d 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, @@ -163,8 +163,8 @@ type { Resize, } AllocatorProc proc(allocator_data: rawptr, mode: AllocatorMode, - size, alignment: int, - old_memory: rawptr, old_size: int, flags: u64) -> rawptr; + size, alignment: int, + old_memory: rawptr, old_size: int, flags: u64 = 0) -> rawptr; Allocator struct #ordered { procedure: AllocatorProc, data: rawptr, @@ -172,14 +172,14 @@ type { Context struct #ordered { - thread_id: int, + thread_id: int, - allocator: Allocator, + allocator: Allocator, user_data: rawptr, user_index: int, } -} +) #thread_local var __context: Context; @@ -198,9 +198,7 @@ proc __check_context() { } } -proc alloc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_ALIGNMENT); } - -proc alloc_align(size, alignment: int) -> rawptr #inline { +proc alloc(size: int, alignment: int = DEFAULT_ALIGNMENT) -> rawptr #inline { __check_context(); var a = context.allocator; return a.procedure(a.data, AllocatorMode.Alloc, size, alignment, nil, 0, 0); @@ -228,8 +226,7 @@ proc free_all() #inline { } -proc resize (ptr: rawptr, old_size, new_size: int) -> rawptr #inline { return resize_align(ptr, old_size, new_size, DEFAULT_ALIGNMENT); } -proc resize_align(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #inline { +proc resize(ptr: rawptr, old_size, new_size: int, alignment: int = DEFAULT_ALIGNMENT) -> rawptr #inline { __check_context(); var a = context.allocator; return a.procedure(a.data, AllocatorMode.Resize, new_size, alignment, ptr, old_size, 0); @@ -239,7 +236,7 @@ proc resize_align(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #in proc default_resize_align(old_memory: rawptr, old_size, new_size, alignment: int) -> rawptr { if old_memory == nil { - return alloc_align(new_size, alignment); + return alloc(new_size, alignment); } if new_size == 0 { @@ -251,7 +248,7 @@ proc default_resize_align(old_memory: rawptr, old_size, new_size, alignment: int return old_memory; } - var new_memory = alloc_align(new_size, alignment); + var new_memory = alloc(new_size, alignment); if new_memory == nil { return nil; } @@ -263,8 +260,8 @@ proc default_resize_align(old_memory: rawptr, old_size, new_size, alignment: int proc default_allocator_proc(allocator_data: rawptr, mode: AllocatorMode, - size, alignment: int, - old_memory: rawptr, old_size: int, flags: u64) -> rawptr { + size, alignment: int, + old_memory: rawptr, old_size: int, flags: u64) -> rawptr { using AllocatorMode; match mode { @@ -561,7 +558,7 @@ proc __default_hash_string(s: string) -> u128 { const __INITIAL_MAP_CAP = 16; -type { +type ( __MapKey struct #ordered { hash: u128, str: string, @@ -589,7 +586,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 c993c72eb..e65135018 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 babe46306..9c982003c 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 8a8608a18..4d0ea9e98 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 6b5cb4a83..336a7bfde 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 48848c79b..8a6c492ee 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 5b89624b6..dd40fb006 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 94f9f6b67..2be7b05cc 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 4f3037037..eff1fd8b6 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 6e69b090d..cf326d48d 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 584a7578d..059e53a79 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,24 +23,24 @@ const { O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; -} +) -const { +const ( SEEK_SET = 0; SEEK_CUR = 1; SEEK_END = 2; SEEK_DATA = 3; SEEK_HOLE = 4; SEEK_MAX = SEEK_HOLE; -} -const { +) +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(); @@ -80,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 @@ -112,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; } @@ -122,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"; @@ -165,7 +165,7 @@ proc open_simple(path: string, mode: int) -> (Handle, Errno) { return handle, 0; } // NOTE(zangent): This is here for compatability reasons. Should this be here? -proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) { +proc open(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errno) { return open_simple(path, mode); } @@ -197,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 d73966895..f97af646f 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; -} +) const INVALID_HANDLE: Handle = -1; -const { +const ( O_RDONLY = 0x00000; O_WRONLY = 0x00001; O_RDWR = 0x00002; @@ -21,10 +21,10 @@ const { O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; -} +) type Errno int; -const { +const ( ERROR_NONE: Errno = 0; ERROR_FILE_NOT_FOUND = 2; ERROR_PATH_NOT_FOUND = 3; @@ -51,13 +51,13 @@ const { // Windows reserves errors >= 1<<29 for application use ERROR_FILE_IS_PIPE = 1<<29 + 0; -} +) // "Argv" arguments converted to Odin strings let args = _alloc_command_line_arguments(); -proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) { +proc open(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errno) { if len(path) == 0 { return INVALID_HANDLE, ERROR_FILE_NOT_FOUND; } diff --git a/core/os_x.odin b/core/os_x.odin index 48b3780ae..a70dd25df 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,17 +26,17 @@ const { O_SYNC = 0x01000; O_ASYNC = 0x02000; O_CLOEXEC = 0x80000; -} -const { +) +const ( SEEK_SET = 0; SEEK_CUR = 1; SEEK_END = 2; SEEK_DATA = 3; SEEK_HOLE = 4; SEEK_MAX = SEEK_HOLE; -} +) -const { +const ( // NOTE(zangent): These are OS specific! // Do not mix these up! RTLD_LAZY = 0x1; @@ -46,7 +46,7 @@ const { RTLD_NODELETE = 0x80; RTLD_NOLOAD = 0x10; RTLD_FIRST = 0x100; -} +) var args: [dynamic]string; @@ -80,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 @@ -112,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; } @@ -122,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"; @@ -167,7 +167,7 @@ proc open_simple(path: string, mode: int) -> (Handle, Errno) { } // NOTE(zangent): This is here for compatability reasons. Should this be here? -proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) { +proc open(path: string, mode: int = O_RDONLY, perm: u32 = 0) -> (Handle, Errno) { return open_simple(path, mode); } @@ -215,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 e264dab3c..e3384daf6 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 b0d280ae2..9800823f2 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 63200fda6..ad08f0b18 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 3daa526fb..c3fc649b9 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 524124d36..353fb755f 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 c02bd3805..a668790d5 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 91ec9bc1b..0b9c07d11 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; @@ -22,13 +22,13 @@ type { Lparam int; Lresult int; WndProc proc(Hwnd, u32, Wparam, Lparam) -> Lresult #cc_c; -} +) type Bool i32; -const { +const ( FALSE: Bool = 0; TRUE = 1; -} +) type Point struct #ordered { x, y: i32, @@ -151,19 +151,19 @@ type PixelFormatDescriptor struct #ordered { type Proc proc() #cc_c; -const { - MAPVK_VK_TO_CHAR = 2; +const ( MAPVK_VK_TO_VSC = 0; MAPVK_VSC_TO_VK = 1; + MAPVK_VK_TO_CHAR = 2; MAPVK_VSC_TO_VK_EX = 3; -} +) const INVALID_HANDLE = Handle(~int(0)); -const { +const ( CS_VREDRAW = 0x0001; CS_HREDRAW = 0x0002; CS_OWNDC = 0x0020; @@ -221,7 +221,7 @@ const { SM_CYSCREEN = 1; SW_SHOW = 5; -} +) const COLOR_BACKGROUND = Hbrush(int(1)); @@ -235,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; @@ -274,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"; @@ -463,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; @@ -513,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 0168ff71a..a996a334b 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 855a5279c..b6bd7fbab 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/build_settings.cpp b/src/build_settings.cpp index 68e8ec372..8d397705e 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -88,7 +88,7 @@ String odin_root_dir(void) { String odin_root_dir(void) { String path = global_module_path; - Array(char) path_buf; + Array path_buf; isize len, i; gbTempArenaMemory tmp; wchar_t *text; diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 6a391f00c..8759f9f09 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -5162,7 +5162,7 @@ Type *check_call_arguments(Checker *c, Operand *operand, Type *proc_type, AstNod Entity *proc = procs[valids[i].index]; TokenPos pos = proc->token.pos; gbString pt = type_to_string(proc->type); - gb_printf_err("\t%.*s :: %s at %.*s(%td:%td) with score %lld\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, valids[i].score); + gb_printf_err("\t%.*s of type %s at %.*s(%td:%td) with score %lld\n", LIT(name), pt, LIT(pos.file), pos.line, pos.column, cast(long long)valids[i].score); gb_string_free(pt); } proc_type = t_invalid; diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index fbf301878..318239b25 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1593,7 +1593,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { found = current_scope_lookup_entity(c->context.scope, str); } if (found == NULL) { - entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, (gd->flags&VarDeclFlag_immutable) != 0); + entity = make_entity_variable(c->allocator, c->context.scope, token, NULL, gd->token.kind == Token_let); entity->identifier = name; AstNode *fl = c->context.curr_foreign_library; diff --git a/src/checker.cpp b/src/checker.cpp index 0f8c2606a..c76c908d9 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1585,7 +1585,7 @@ void check_collect_entities(Checker *c, Array nodes, bool is_file_sco error_node(name, "A declaration's name must be an identifier, got %.*s", LIT(ast_node_strings[name->kind])); continue; } - Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, (gd->flags&VarDeclFlag_immutable) != 0); + Entity *e = make_entity_variable(c->allocator, c->context.scope, name->Ident, NULL, gd->token.kind == Token_let); e->Variable.is_thread_local = (gd->flags & VarDeclFlag_thread_local) != 0; e->identifier = name; @@ -2005,7 +2005,7 @@ void check_import_entities(Checker *c, Map *file_scopes) { continue; } if (operand.value.kind == ExactValue_Bool && - !operand.value.value_bool) { + operand.value.value_bool == false) { continue; } } diff --git a/src/ir.cpp b/src/ir.cpp index 75f9b8153..c585c99df 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2144,9 +2144,9 @@ irValue *ir_emit_arith(irProcedure *proc, TokenKind op, irValue *left, irValue * bool is_unsigned = is_type_unsigned(type); char *name = NULL; if (op == Token_Quo) { - name = is_unsigned ? "__udivti3" : "__divti3"; + name = cast(char *)(is_unsigned ? "__udivti3" : "__divti3"); } else if (op == Token_Mod) { - name = is_unsigned ? "__umodti3" : "__modti3"; + name = cast(char *)(is_unsigned ? "__umodti3" : "__modti3"); } if (name != NULL) { irValue **args = gb_alloc_array(proc->module->allocator, irValue *, 2); @@ -3698,7 +3698,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv case BuiltinProc_new: { ir_emit_comment(proc, str_lit("new")); - // new :: proc(Type) -> ^Type + // proc new(Type) -> ^Type gbAllocator a = proc->module->allocator; Type *type = type_of_expr(proc->module->info, ce->args[0]); @@ -3720,7 +3720,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv irValue **args = gb_alloc_array(a, irValue *, 2); args[0] = ir_const_int(a, size); args[1] = ir_const_int(a, align); - irValue *call = ir_emit_global_call(proc, "alloc_align", args, 2); + irValue *call = ir_emit_global_call(proc, "alloc", args, 2); irValue *v = ir_emit_conv(proc, call, ptr_type); if (type != allocation_type) { Type *u = base_type(allocation_type); @@ -3758,7 +3758,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv irValue **args = gb_alloc_array(a, irValue *, 2); args[0] = slice_size; args[1] = elem_align; - irValue *call = ir_emit_global_call(proc, "alloc_align", args, 2); + irValue *call = ir_emit_global_call(proc, "alloc", args, 2); irValue *ptr = ir_emit_conv(proc, call, elem_ptr_type); irValue *slice = ir_add_local_generated(proc, type); @@ -4128,7 +4128,7 @@ irValue *ir_build_builtin_proc(irProcedure *proc, AstNode *expr, TypeAndValue tv case BuiltinProc_copy: { ir_emit_comment(proc, str_lit("copy")); - // copy :: proc(dst, src: []Type) -> int + // proc copy(dst, src: []Type) -> int AstNode *dst_node = ce->args[0]; AstNode *src_node = ce->args[1]; irValue *dst_slice = ir_build_expr(proc, dst_node); @@ -7321,7 +7321,7 @@ void ir_gen_tree(irGen *s) { #if defined(GB_SYSTEM_WINDOWS) if (build_context.is_dll && !has_dll_main) { - // DllMain :: proc(inst: rawptr, reason: u32, reserved: rawptr) -> i32 + // proc DllMain(inst: rawptr, reason: u32, reserved: rawptr) -> i32 String name = str_lit("DllMain"); Type *proc_params = make_type_tuple(a); Type *proc_results = make_type_tuple(a); @@ -7389,7 +7389,7 @@ void ir_gen_tree(irGen *s) { #endif #if 0 && defined(GB_SYSTEM_WINDOWS) if (!m->build_context->is_dll && !has_win_main) { - // WinMain :: proc(inst, prev: rawptr, cmd_line: ^byte, cmd_show: i32) -> i32 + // proc WinMain(inst, prev: rawptr, cmd_line: ^byte, cmd_show: i32) -> i32 String name = str_lit("WinMain"); Type *proc_params = make_type_tuple(a); Type *proc_results = make_type_tuple(a); diff --git a/src/parser.cpp b/src/parser.cpp index 8aadba765..44f46150e 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -89,8 +89,7 @@ enum ProcCallingConvention { enum VarDeclFlag { VarDeclFlag_using = 1<<0, - VarDeclFlag_immutable = 1<<1, - VarDeclFlag_thread_local = 1<<2, + VarDeclFlag_thread_local = 1<<1, }; enum StmtStateFlag { @@ -2590,17 +2589,24 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) { Token open = {}; Token close = {}; - if (f->curr_token.kind == Token_OpenBrace) { + if (f->curr_token.kind == Token_OpenParen) { specs = make_ast_node_array(f); - open = expect_token(f, Token_OpenBrace); - while (f->curr_token.kind != Token_CloseBrace && + open = expect_token(f, Token_OpenParen); + bool require_semicolon_after_paren = false; + while (f->curr_token.kind != Token_CloseParen && f->curr_token.kind != Token_EOF) { AstNode *spec = func(f, token); array_add(&specs, spec); - expect_semicolon(f, spec); + if (f->curr_token.kind == Token_CloseParen && + f->curr_token.pos.line == f->prev_token.pos.line) { + require_semicolon_after_paren = true; + } else { + expect_semicolon(f, spec); + } } - close = expect_token(f, Token_CloseBrace); - if (f->curr_token.pos.line == close.pos.line || + close = expect_token(f, Token_CloseParen); + if (require_semicolon_after_paren || + f->curr_token.pos.line == close.pos.line || open.pos.line == close.pos.line) { expect_semicolon(f, NULL); } @@ -2614,11 +2620,7 @@ AstNode *parse_gen_decl(AstFile *f, Token token, ParseSpecFunc *func) { syntax_error(token, "Empty %.*s declaration list", LIT(token_strings[token.kind])); } - AstNode *decl = ast_gen_decl(f, token, open, close, specs); - if (token.kind == Token_let) { - decl->GenDecl.flags |= VarDeclFlag_immutable; - } - return decl; + return ast_gen_decl(f, token, open, close, specs); } PARSE_SPEC_FUNC(parse_value_spec) { @@ -3247,7 +3249,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } if (allow_token(f, Token_Eq)) { // TODO(bill): Should this be true==lhs or false==rhs? - default_value = parse_expr(f, true); + default_value = parse_expr(f, false); if (!is_procedure) { syntax_error(f->curr_token, "Default parameters are only allowed for procedures"); } @@ -3281,7 +3283,7 @@ AstNode *parse_field_list(AstFile *f, isize *name_count_, u32 allowed_flags, Tok } if (allow_token(f, Token_Eq)) { // TODO(bill): Should this be true==lhs or false==rhs? - default_value = parse_expr(f, true); + default_value = parse_expr(f, false); if (!is_procedure) { syntax_error(f->curr_token, "Default parameters are only allowed for procedures"); } diff --git a/src/ssa.cpp b/src/ssa.cpp index 06da0afa1..6168b025f 100644 --- a/src/ssa.cpp +++ b/src/ssa.cpp @@ -7,9 +7,6 @@ struct ssaProc; struct ssaEdge; struct ssaRegister; struct ssaTargetList; -enum ssaBlockKind; -enum ssaBranchPrediction; -enum ssaDeferExitKind; String ssa_mangle_name(ssaModule *m, String path, Entity *e); diff --git a/src/types.cpp b/src/types.cpp index 94d4cf7c8..ca74a1b77 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -2445,7 +2445,7 @@ gbString write_type_to_string(gbString str, Type *type) { break; case Type_BitFieldValue: - str = gb_string_appendc(str, gb_bprintf("(bit field value with %lld bits)", cast(int)type->BitFieldValue.bits)); + str = gb_string_appendc(str, gb_bprintf("(bit field value with %d bits)", cast(int)type->BitFieldValue.bits)); break; }