Browse Source

Fix parsing for procedure literals expression statements; improve assert performance; other minor fixes

gingerBill 6 years ago
parent
commit
2c5c8192f8

+ 1 - 0
core/odin/parser/parser.odin

@@ -955,6 +955,7 @@ parse_stmt :: proc(p: ^Parser) -> ^ast.Stmt {
 	switch p.curr_tok.kind {
 	switch p.curr_tok.kind {
 	// Operands
 	// Operands
 	case token.Context, // Also allows for 'context = '
 	case token.Context, // Also allows for 'context = '
+	     token.Proc,
 	     token.Inline, token.No_Inline,
 	     token.Inline, token.No_Inline,
 	     token.Ident,
 	     token.Ident,
 	     token.Integer, token.Float, token.Imag,
 	     token.Integer, token.Float, token.Imag,

+ 7 - 5
core/runtime/core.odin

@@ -666,11 +666,13 @@ card :: proc(s: $S/bit_set[$E; $U]) -> int {
 @builtin
 @builtin
 assert :: proc(condition: bool, message := "", loc := #caller_location) -> bool {
 assert :: proc(condition: bool, message := "", loc := #caller_location) -> bool {
 	if !condition {
 	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;
 	return condition;
 }
 }

+ 1 - 1
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="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="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="QueryPerformanceFrequency") query_performance_frequency  :: proc(result: ^i64) -> i32 ---;
 	@(link_name="QueryPerformanceCounter")   query_performance_counter    :: 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) ---;
 	@(link_name="OutputDebugStringA")        output_debug_string_a        :: proc(c_str: cstring) ---;

+ 1 - 1
core/sys/win32/user32.odin

@@ -182,7 +182,7 @@ foreign user32 {
     @(link_name="DestroyIcon")      destroy_icon        :: proc(icon: Hicon) -> Bool ---;
     @(link_name="DestroyIcon")      destroy_icon        :: proc(icon: Hicon) -> Bool ---;
 
 
     @(link_name="LoadCursorA")      load_cursor_a       :: proc(instance: Hinstance, cursor_name: cstring) -> Hcursor ---;
     @(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="GetCursor")        get_cursor          :: proc() -> Hcursor ---;
 	@(link_name="SetCursor")        set_cursor          :: proc(cursor: Hcursor) -> Hcursor ---;
 	@(link_name="SetCursor")        set_cursor          :: proc(cursor: Hcursor) -> Hcursor ---;
 
 

+ 1 - 1
core/time/time_windows.odin

@@ -20,5 +20,5 @@ now :: proc() -> Time {
 
 
 
 
 sleep :: proc(d: Duration) {
 sleep :: proc(d: Duration) {
-	win32.sleep(i32(d/Millisecond));
+	win32.sleep(u32(d/Millisecond));
 }
 }

+ 1 - 1
src/ir.cpp

@@ -3053,7 +3053,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> args, Pro
 	if (value->kind == irValue_Proc) {
 	if (value->kind == irValue_Proc) {
 		irProcedure *the_proc = &value->Proc;
 		irProcedure *the_proc = &value->Proc;
 		Entity *e = the_proc->entity;
 		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;
 			DeferredProcedureKind kind = e->Procedure.deferred_procedure.kind;
 			Entity *deferred_entity = e->Procedure.deferred_procedure.entity;
 			Entity *deferred_entity = e->Procedure.deferred_procedure.entity;
 			irValue **deferred_found = map_get(&p->module->values, hash_entity(deferred_entity));
 			irValue **deferred_found = map_get(&p->module->values, hash_entity(deferred_entity));

+ 1 - 0
src/parser.cpp

@@ -3759,6 +3759,7 @@ Ast *parse_stmt(AstFile *f) {
 	switch (token.kind) {
 	switch (token.kind) {
 	// Operands
 	// Operands
 	case Token_context: // Also allows for `context =`
 	case Token_context: // Also allows for `context =`
+	case Token_proc:
 	case Token_inline:
 	case Token_inline:
 	case Token_no_inline:
 	case Token_no_inline:
 	case Token_Ident:
 	case Token_Ident: