From cbcf4b6071a55a8e80c41647e81715cf8505bdf8 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Mon, 11 Sep 2017 22:49:26 +0100 Subject: [PATCH] Fix issue #94 --- core/c.odin | 24 +++++++------ core/os_linux.odin | 4 +-- core/os_windows.odin | 2 +- core/os_x.odin | 6 ++-- core/strconv.odin | 82 ++++++++++++++++++++------------------------ core/sys/wgl.odin | 2 +- core/thread.odin | 4 ++- examples/demo.odin | 1 + src/checker.cpp | 17 ++++----- 9 files changed, 69 insertions(+), 73 deletions(-) diff --git a/core/c.odin b/core/c.odin index 614908edf..4392d979a 100644 --- a/core/c.odin +++ b/core/c.odin @@ -13,17 +13,21 @@ c_ushort :: i16; c_int :: i32; c_uint :: u32; -c_long :: ODIN_OS == "windows" ? - i32 : - (size_of(int) == 4) ? - i32 : - i64; +when ODIN_OS == "windows" { + c_long :: i32; +} else when size_of(int) == 4 { + c_long :: i32; +} else { + c_long :: i64; +} -c_ulong :: ODIN_OS == "windows" ? - u32 : - (size_of(int) == 4) ? - u32 : - u64; +when ODIN_OS == "windows" { + c_long :: u32; +} else when size_of(uint) == 4 { + c_long :: u32; +} else { + c_long :: u64; +} c_longlong :: i64; c_ulonglong :: u64; diff --git a/core/os_linux.odin b/core/os_linux.odin index ddae24e9e..bd1b32990 100644 --- a/core/os_linux.odin +++ b/core/os_linux.odin @@ -3,9 +3,9 @@ foreign_system_library libc "c"; import "core:strings.odin"; -Handle :: i32; +Handle :: i32; File_Time :: u64; -Errno :: i32; +Errno :: i32; O_RDONLY :: 0x00000; diff --git a/core/os_windows.odin b/core/os_windows.odin index 103fd6b73..cfe0e10d2 100644 --- a/core/os_windows.odin +++ b/core/os_windows.odin @@ -1,7 +1,7 @@ import win32 "core:sys/windows.odin"; import "core:mem.odin"; -Handle :: int; +Handle :: int; File_Time :: u64; diff --git a/core/os_x.odin b/core/os_x.odin index 0c5510cd2..796edd08a 100644 --- a/core/os_x.odin +++ b/core/os_x.odin @@ -3,9 +3,9 @@ foreign_system_library libc "c"; import "core:strings.odin"; -Handle :: i32; -File_Time :: u64; -Errno :: int; +Handle :: i32; +File_Time :: u64; +Errno :: int; O_RDONLY :: 0x00000; diff --git a/core/strconv.odin b/core/strconv.odin index 431b6a5ee..841d3805c 100644 --- a/core/strconv.odin +++ b/core/strconv.odin @@ -7,23 +7,23 @@ Int_Flag :: enum { } -parse_bool :: proc(s: string) -> (result: bool, ok: bool) { +parse_bool :: proc(s: string) -> (result: bool = false, ok: bool) { match s { case "1", "t", "T", "true", "TRUE", "True": return true, true; case "0", "f", "F", "false", "FALSE", "False": return false, true; } - return false, false; + return ok = false; } _digit_value :: proc(r: rune) -> int { ri := int(r); v: int = 16; match r { - case '0'..'9': v = ri-'0'; - case 'a'..'z': v = ri-'a'+10; - case 'A'..'Z': v = ri-'A'+10; + case '0'...'9': v = ri-'0'; + case 'a'...'z': v = ri-'a'+10; + case 'A'...'Z': v = ri-'A'+10; } return v; } @@ -131,7 +131,7 @@ parse_f64 :: proc(s: string) -> f64 { value += f64(v); } - if s[i] == '.' { + if i < len(s) && s[i] == '.' { pow10: f64 = 10; i += 1; @@ -149,28 +149,30 @@ parse_f64 :: proc(s: string) -> f64 { frac := false; scale: f64 = 1; - if s[i] == 'e' || s[i] == 'E' { + if i < len(s) && (s[i] == 'e' || s[i] == 'E') { i += 1; - match s[i] { - case '-': i += 1; frac = true; - case '+': i += 1; + if i < len(s) { + match s[i] { + case '-': i += 1; frac = true; + case '+': i += 1; + } + + exp: u32 = 0; + for ; i < len(s); i += 1 { + r := rune(s[i]); + if r == '_' do continue; + + d := u32(_digit_value(r)); + if d >= 10 do break; + exp = exp * 10 + d; + } + if exp > 308 { exp = 308; } + + for exp >= 50 { scale *= 1e50; exp -= 50; } + for exp >= 8 { scale *= 1e8; exp -= 8; } + for exp > 0 { scale *= 10; exp -= 1; } } - - exp: u32 = 0; - for ; i < len(s); i += 1 { - r := rune(s[i]); - if r == '_' do continue; - - d := u32(_digit_value(r)); - if d >= 10 do break; - exp = exp * 10 + d; - } - if exp > 308 { exp = 308; } - - for exp >= 50 { scale *= 1e50; exp -= 50; } - for exp >= 8 { scale *= 1e8; exp -= 8; } - for exp > 0 { scale *= 10; exp -= 1; } } if frac do return sign * (value/scale); @@ -179,11 +181,8 @@ parse_f64 :: proc(s: string) -> f64 { append_bool :: proc(buf: []u8, b: bool) -> string { - if b { - append(&buf, "true"); - } else { - append(&buf, "false"); - } + if b do append(&buf, "true"); + else do append(&buf, "false"); return string(buf); } @@ -193,7 +192,7 @@ append_uint :: proc(buf: []u8, u: u64, base: int) -> string { append_int :: proc(buf: []u8, i: i64, base: int) -> string { return append_bits(buf, u128(i), base, true, 8*size_of(int), digits, 0); } -itoa :: proc(buf: []u8, i: int) -> string { return append_int(buf, i64(i), 10); } +itoa :: proc(buf: []u8, i: int) -> string do return append_int(buf, i64(i), 10); append_float :: proc(buf: []u8, f: f64, fmt: u8, prec, bit_size: int) -> string { return string(generic_ftoa(buf, f, fmt, prec, bit_size)); @@ -389,15 +388,15 @@ round_shortest :: proc(d: ^Decimal, mant: u64, exp: int, flt: ^FloatInfo) { ok_round_down := l != m || inclusive && i+1 == lower.count; ok_round_up := m != u && (inclusive || m+1 < u || i+1 < upper.count); - if (ok_round_down && ok_round_up) { + if ok_round_down && ok_round_up { round(d, i+1); return; } - if (ok_round_down) { + if ok_round_down { round_down(d, i+1); return; } - if (ok_round_up) { + if ok_round_up { round_up(d, i+1); return; } @@ -416,28 +415,23 @@ is_integer_negative :: proc(u: u128, is_signed: bool, bit_size: int) -> (unsigne case 8: i := i8(u); neg = i < 0; - if neg { i = -i; } - u = u128(i); + u = u128(abs(i)); case 16: i := i16(u); neg = i < 0; - if neg { i = -i; } - u = u128(i); + u = u128(abs(i)); case 32: i := i32(u); neg = i < 0; - if neg { i = -i; } - u = u128(i); + u = u128(abs(i)); case 64: i := i64(u); neg = i < 0; - if neg { i = -i; } - u = u128(i); + u = u128(abs(i)); case 128: i := i128(u); neg = i < 0; - if neg { i = -i; } - u = u128(i); + u = u128(abs(i)); case: panic("is_integer_negative: Unknown integer size"); } diff --git a/core/sys/wgl.odin b/core/sys/wgl.odin index 4812a6586..a859aeb92 100644 --- a/core/sys/wgl.odin +++ b/core/sys/wgl.odin @@ -10,7 +10,7 @@ CONTEXT_FORWARD_COMPATIBLE_BIT_ARB :: 0x0002; CONTEXT_CORE_PROFILE_BIT_ARB :: 0x00000001; CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB :: 0x00000002; -Hglrc :: Handle; +Hglrc :: Handle; Color_Ref :: u32; Layer_Plane_Descriptor :: struct { diff --git a/core/thread.odin b/core/thread.odin index e6e8ce53b..e44879122 100644 --- a/core/thread.odin +++ b/core/thread.odin @@ -1,6 +1,8 @@ _ :: compile_assert(ODIN_OS == "windows"); -import win32 "core:sys/windows.odin"; +when ODIN_OS == "windows" { + import win32 "core:sys/windows.odin"; +} Thread :: struct { using specific: Os_Specific; diff --git a/examples/demo.odin b/examples/demo.odin index 8b772e883..7ab5a81a6 100644 --- a/examples/demo.odin +++ b/examples/demo.odin @@ -20,6 +20,7 @@ when ODIN_OS == "windows" { import win32 "core:sys/windows.odin"; } + general_stuff :: proc() { { // `do` for inline statmes rather than block foo :: proc() do fmt.println("Foo!"); diff --git a/src/checker.cpp b/src/checker.cpp index 7a4e1f2ce..ed9da4fee 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -264,11 +264,6 @@ i32 is_scope_an_ancestor(Scope *parent, Scope *child) { } -struct DelayedDecl { - Scope * parent; - AstNode *decl; -}; - struct EntityGraphNode; typedef PtrSet EntityGraphNodeSet; @@ -1617,7 +1612,7 @@ void init_preload(Checker *c) { bool check_arity_match(Checker *c, AstNodeValueDecl *vd, bool is_global = false); void check_collect_entities(Checker *c, Array nodes); void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws); -void check_delayed_file_import_entities(Checker *c, AstNode *decl); +void check_delayed_file_import_entity(Checker *c, AstNode *decl); bool check_is_entity_overloaded(Entity *e) { if (e->kind != Entity_Procedure) { @@ -1966,7 +1961,7 @@ void check_collect_entities(Checker *c, Array nodes) { continue; } if (c->context.allow_file_when_statement) { - check_delayed_file_import_entities(c, decl); + check_delayed_file_import_entity(c, decl); } case_end; @@ -1978,7 +1973,7 @@ void check_collect_entities(Checker *c, Array nodes) { continue; } if (c->context.allow_file_when_statement) { - check_delayed_file_import_entities(c, decl); + check_delayed_file_import_entity(c, decl); } case_end; @@ -1990,7 +1985,7 @@ void check_collect_entities(Checker *c, Array nodes) { continue; } if (c->context.allow_file_when_statement) { - check_delayed_file_import_entities(c, decl); + check_delayed_file_import_entity(c, decl); } case_end; @@ -2410,7 +2405,7 @@ Array find_import_path(Map *file_scopes, Scope *start, Scope * return empty_path; } -void check_delayed_file_import_entities(Checker *c, AstNode *decl) { +void check_delayed_file_import_entity(Checker *c, AstNode *decl) { GB_ASSERT(c->context.allow_file_when_statement); Scope *parent_scope = c->context.scope; @@ -2636,7 +2631,7 @@ void check_import_entities(Checker *c) { c->context.allow_file_when_statement = true; for_array(i, f->decls) { - check_delayed_file_import_entities(c, f->decls[i]); + check_delayed_file_import_entity(c, f->decls[i]); } } }