Call expression, either handle all or ignore all results.

This commit is contained in:
Ginger Bill
2016-09-16 11:38:20 +01:00
parent 807256dea4
commit 968de5aae8
11 changed files with 226 additions and 86 deletions

View File

@@ -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)
}

View File

@@ -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) {

View File

@@ -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()
}

View File

@@ -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 {