From 2c5c8192f8fcb40fdef183c25a8d799f23f23439 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 28 Jul 2019 22:58:56 +0100 Subject: [PATCH] Fix parsing for procedure literals expression statements; improve assert performance; other minor fixes --- core/odin/parser/parser.odin | 1 + core/runtime/core.odin | 12 +++++++----- core/sys/win32/kernel32.odin | 2 +- core/sys/win32/user32.odin | 2 +- core/time/time_windows.odin | 2 +- src/ir.cpp | 2 +- src/parser.cpp | 1 + 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 077e04cc9..0c011e07e 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -955,6 +955,7 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt { switch p.curr_tok.kind { // Operands case token.Context, // Also allows for 'context = ' + token.Proc, token.Inline, token.No_Inline, token.Ident, token.Integer, token.Float, token.Imag, diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 623f3725a..02578da3b 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -666,11 +666,13 @@ card :: proc(s: $S/bit_set[$E; $U]) -> int { @builtin assert :: proc(condition: bool, message := "", loc := #caller_location) -> bool { if !condition { - p := context.assertion_failure_proc; - if p == nil { - p = default_assertion_failure_proc; - } - p("Runtime assertion", message, loc); + proc(message: string, loc: Source_Code_Location) { + p := context.assertion_failure_proc; + if p == nil { + p = default_assertion_failure_proc; + } + p("Runtime assertion", message, loc); + }(message, loc); } return condition; } diff --git a/core/sys/win32/kernel32.odin b/core/sys/win32/kernel32.odin index 036fc016a..f647ab7e0 100644 --- a/core/sys/win32/kernel32.odin +++ b/core/sys/win32/kernel32.odin @@ -23,7 +23,7 @@ foreign kernel32 { @(link_name="GetModuleFileNameA") get_module_file_name_a :: proc(module: Hmodule, filename: cstring, size: u32) -> u32 ---; @(link_name="GetModuleFileNameW") get_module_file_name_w :: proc(module: Hmodule, filename: Wstring, size: u32) -> u32 ---; - @(link_name="Sleep") sleep :: proc(ms: i32) -> i32 ---; + @(link_name="Sleep") sleep :: proc(ms: u32) ---; @(link_name="QueryPerformanceFrequency") query_performance_frequency :: proc(result: ^i64) -> i32 ---; @(link_name="QueryPerformanceCounter") query_performance_counter :: proc(result: ^i64) -> i32 ---; @(link_name="OutputDebugStringA") output_debug_string_a :: proc(c_str: cstring) ---; diff --git a/core/sys/win32/user32.odin b/core/sys/win32/user32.odin index b8969faf3..5165d9389 100644 --- a/core/sys/win32/user32.odin +++ b/core/sys/win32/user32.odin @@ -182,7 +182,7 @@ foreign user32 { @(link_name="DestroyIcon") destroy_icon :: proc(icon: Hicon) -> Bool ---; @(link_name="LoadCursorA") load_cursor_a :: proc(instance: Hinstance, cursor_name: cstring) -> Hcursor ---; - @(link_name="LoadCursorW") load_cursor_w :: proc(instance: Hinstance, cursor_name: cstring) -> Hcursor ---; + @(link_name="LoadCursorW") load_cursor_w :: proc(instance: Hinstance, cursor_name: Wstring) -> Hcursor ---; @(link_name="GetCursor") get_cursor :: proc() -> Hcursor ---; @(link_name="SetCursor") set_cursor :: proc(cursor: Hcursor) -> Hcursor ---; diff --git a/core/time/time_windows.odin b/core/time/time_windows.odin index 31fbca769..f6bfdd678 100644 --- a/core/time/time_windows.odin +++ b/core/time/time_windows.odin @@ -20,5 +20,5 @@ now :: proc() -> Time { sleep :: proc(d: Duration) { - win32.sleep(i32(d/Millisecond)); + win32.sleep(u32(d/Millisecond)); } diff --git a/src/ir.cpp b/src/ir.cpp index 1105eac29..0a5dc7528 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3053,7 +3053,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array args, Pro if (value->kind == irValue_Proc) { irProcedure *the_proc = &value->Proc; Entity *e = the_proc->entity; - if (entity_has_deferred_procedure(e)) { + if (e != nullptr && entity_has_deferred_procedure(e)) { DeferredProcedureKind kind = e->Procedure.deferred_procedure.kind; Entity *deferred_entity = e->Procedure.deferred_procedure.entity; irValue **deferred_found = map_get(&p->module->values, hash_entity(deferred_entity)); diff --git a/src/parser.cpp b/src/parser.cpp index a377b773c..d1fd94c1d 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -3759,6 +3759,7 @@ Ast *parse_stmt(AstFile *f) { switch (token.kind) { // Operands case Token_context: // Also allows for `context =` + case Token_proc: case Token_inline: case Token_no_inline: case Token_Ident: