From 968de5aae886e87f395533283c17d77f31eabd0d Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Fri, 16 Sep 2016 11:38:20 +0100 Subject: Call expression, either handle all or ignore all results. --- code/demo.odin | 24 ++++++++++++++++++------ code/game.odin | 8 ++++---- code/runtime.odin | 44 +++++++++++++++++++++++++------------------- code/win32.odin | 20 +++++++++++--------- 4 files changed, 58 insertions(+), 38 deletions(-) (limited to 'code') diff --git a/code/demo.odin b/code/demo.odin index 4fca39f63..4909a3e72 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,16 +1,28 @@ -#import "runtime.odin" as _ -#import "punity.odin" as punity +#import "punity.odin" as pn +#import "fmt.odin" as fmt +test :: proc() { + thing :: proc() { + thing :: proc() { + fmt.println("Hello1") + } + fmt.println("Hello") + } +} main :: proc() { - init :: proc() { + test() - } + init :: proc(c: ^pn.Core) { - step :: proc() { + } + step :: proc(c: ^pn.Core) { + if pn.key_down(pn.Key.ESCAPE) { + c.running = false + } } - punity.run(init, step) + pn.run(init, step) } diff --git a/code/game.odin b/code/game.odin index 2b56cb64e..dfa05750b 100644 --- a/code/game.odin +++ b/code/game.odin @@ -10,7 +10,7 @@ time_now :: proc() -> f64 { assert(win32_perf_count_freq != 0) counter: i64 - _ = win32.QueryPerformanceCounter(^counter) + win32.QueryPerformanceCounter(^counter) result := counter as f64 / win32_perf_count_freq as f64 return result } @@ -24,7 +24,7 @@ win32_print_last_error :: proc() { // Yuk! to_c_string :: proc(s: string) -> []u8 { c_str := new_slice(u8, s.count+1) - _ = copy(c_str, s as []byte) + copy(c_str, s as []byte) c_str[s.count] = 0 return c_str } @@ -157,8 +157,8 @@ run :: proc() { if msg.message == WM_QUIT { running = false } - _ = TranslateMessage(^msg) - _ = DispatchMessageA(^msg) + TranslateMessage(^msg) + DispatchMessageA(^msg) } if is_key_down(Key_Code.ESCAPE) { diff --git a/code/runtime.odin b/code/runtime.odin index 1d293b5f7..b0320beec 100644 --- a/code/runtime.odin +++ b/code/runtime.odin @@ -1,10 +1,5 @@ #shared_global_scope -// TODO(bill): Create a standard library "location" so I don't have to manually import "runtime.odin" -#import "win32.odin" as win32 -#import "os.odin" as os -#import "fmt.odin" as fmt - // IMPORTANT NOTE(bill): Do not change the order of any of this data // The compiler relies upon this _exact_ order Type_Info :: union { @@ -80,20 +75,22 @@ byte_swap16 :: proc(b: u16) -> u16 #foreign "llvm.bswap.i16" byte_swap32 :: proc(b: u32) -> u32 #foreign "llvm.bswap.i32" byte_swap64 :: proc(b: u64) -> u64 #foreign "llvm.bswap.i64" -fmuladd_f32 :: proc(a, b, c: f32) -> f32 #foreign "llvm.fmuladd.f32" -fmuladd_f64 :: proc(a, b, c: f64) -> f64 #foreign "llvm.fmuladd.f64" +fmuladd32 :: proc(a, b, c: f32) -> f32 #foreign "llvm.fmuladd.f32" +fmuladd64 :: proc(a, b, c: f64) -> f64 #foreign "llvm.fmuladd.f64" -heap_alloc :: proc(len: int) -> rawptr { - return win32.HeapAlloc(win32.GetProcessHeap(), win32.HEAP_ZERO_MEMORY, len) +heap_alloc :: proc(len: int) -> rawptr { + c_malloc :: proc(len: int) -> rawptr #foreign "malloc" + return c_malloc(len) } heap_free :: proc(ptr: rawptr) { - _ = win32.HeapFree(win32.GetProcessHeap(), 0, ptr) + c_free :: proc(ptr: rawptr) #foreign "free" + c_free(ptr) } current_thread_id :: proc() -> int { - id := win32.GetCurrentThreadId() - return id as int + GetCurrentThreadId :: proc() -> u32 #foreign #dll_import + return GetCurrentThreadId() as int } memory_zero :: proc(data: rawptr, len: int) { @@ -168,10 +165,16 @@ __string_gt :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) > __string_le :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) <= 0 } __string_ge :: proc(a, b : string) -> bool #inline { return __string_cmp(a, b) >= 0 } +__print_err_str :: proc(s: string) { + +} +__print_err_int :: proc(i: int) { +} __assert :: proc(msg: string) { - _ = os.write(os.get_standard_file(os.File_Standard.ERROR), msg as []byte) + // TODO(bill): Write message + __print_err_str(msg) __debug_trap() } @@ -180,9 +183,10 @@ __bounds_check_error :: proc(file: string, line, column: int, if 0 <= index && index < count { return } + // TODO(bill): Write message // TODO(bill): Probably reduce the need for `print` in the runtime if possible - fmt.println_err("%(%:%) Index % is out of bounds range [0, %)", - file, line, column, index, count) + // fmt.println_err("%(%:%) Index % is out of bounds range [0, %)", + // file, line, column, index, count) __debug_trap() } @@ -191,8 +195,9 @@ __slice_expr_error :: proc(file: string, line, column: int, if 0 <= low && low <= high && high <= max { return } - fmt.println_err("%(%:%) Invalid slice indices: [%:%:%]", - file, line, column, low, high, max) + // TODO(bill): Write message + // fmt.println_err("%(%:%) Invalid slice indices: [%:%:%]", + // file, line, column, low, high, max) __debug_trap() } __substring_expr_error :: proc(file: string, line, column: int, @@ -200,8 +205,9 @@ __substring_expr_error :: proc(file: string, line, column: int, if 0 <= low && low <= high { return } - fmt.println_err("%(%:%) Invalid substring indices: [%:%:%]", - file, line, column, low, high) + // TODO(bill): Write message + // fmt.println_err("%(%:%) Invalid substring indices: [%:%:%]", + // file, line, column, low, high) __debug_trap() } diff --git a/code/win32.odin b/code/win32.odin index de67784d3..0ccc934aa 100644 --- a/code/win32.odin +++ b/code/win32.odin @@ -83,14 +83,15 @@ RECT :: struct #ordered { } -GetLastError :: proc() -> i32 #foreign #dll_import -ExitProcess :: proc(exit_code: u32) #foreign #dll_import -GetDesktopWindow :: proc() -> HWND #foreign #dll_import -GetCursorPos :: proc(p: ^POINT) -> i32 #foreign #dll_import -ScreenToClient :: proc(h: HWND, p: ^POINT) -> i32 #foreign #dll_import -GetModuleHandleA :: proc(module_name: ^u8) -> HINSTANCE #foreign #dll_import -GetStockObject :: proc(fn_object: i32) -> HGDIOBJ #foreign #dll_import -PostQuitMessage :: proc(exit_code: i32) #foreign #dll_import +GetLastError :: proc() -> i32 #foreign #dll_import +ExitProcess :: proc(exit_code: u32) #foreign #dll_import +GetDesktopWindow :: proc() -> HWND #foreign #dll_import +GetCursorPos :: proc(p: ^POINT) -> i32 #foreign #dll_import +ScreenToClient :: proc(h: HWND, p: ^POINT) -> i32 #foreign #dll_import +GetModuleHandleA :: proc(module_name: ^u8) -> HINSTANCE #foreign #dll_import +GetStockObject :: proc(fn_object: i32) -> HGDIOBJ #foreign #dll_import +PostQuitMessage :: proc(exit_code: i32) #foreign #dll_import +SetWindowTextA :: proc(hwnd: HWND, c_string: ^u8) -> BOOL #foreign #dll_import QueryPerformanceFrequency :: proc(result: ^i64) -> i32 #foreign #dll_import QueryPerformanceCounter :: proc(result: ^i64) -> i32 #foreign #dll_import @@ -122,7 +123,7 @@ AdjustWindowRect :: proc(rect: ^RECT, style: u32, menu: BOOL) -> BOOL #foreign # GetQueryPerformanceFrequency :: proc() -> i64 { r: i64 - _ = QueryPerformanceFrequency(^r) + QueryPerformanceFrequency(^r) return r } @@ -287,6 +288,7 @@ wglDeleteContext :: proc(hglrc: HGLRC) -> BOOL #foreign #dll_import +GetKeyState :: proc(v_key: i32) -> i16 #foreign #dll_import GetAsyncKeyState :: proc(v_key: i32) -> i16 #foreign #dll_import is_key_down :: proc(key: Key_Code) -> bool { -- cgit v1.2.3