From 50301557b2425fc0b4dd213ad03fb635cbd6e454 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Thu, 6 Oct 2016 17:11:17 +0100 Subject: Untyped `nil` --- code/demo.odin | 16 +++++++---- code/game.odin | 10 +++---- code/old_demos/demo004.odin | 66 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 code/old_demos/demo004.odin (limited to 'code') diff --git a/code/demo.odin b/code/demo.odin index ff80f434d..0d0ed6735 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -1,9 +1,15 @@ #import "fmt.odin" -#import "utf8.odin" -#import "hash.odin" -#import "mem.odin" -#import "game.odin" + +A :: {2}f32{1, 2} +B :: {2}f32{3, 4} main :: proc() { - fmt.println("Hellope") + Fruit :: union { + A: int + B: f32 + C: struct { + x: int + } + } } + diff --git a/code/game.odin b/code/game.odin index 46940fe4f..aebf4a931 100644 --- a/code/game.odin +++ b/code/game.odin @@ -50,7 +50,7 @@ make_window :: proc(title: string, msg, height: int, window_proc: win32.WNDPROC) c_class_name := class_name.data w.c_title = to_c_string(title) - instance := GetModuleHandleA(null) + instance := GetModuleHandleA(nil) w.wc = WNDCLASSEXA{ size = size_of(WNDCLASSEXA) as u32, @@ -70,9 +70,9 @@ make_window :: proc(title: string, msg, height: int, window_proc: win32.WNDPROC) WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, w.width as i32, w.height as i32, - null, null, instance, null) + nil, nil, instance, nil) - if w.hwnd == null { + if w.hwnd == nil { win32_print_last_error() return w, false } @@ -92,7 +92,7 @@ make_window :: proc(title: string, msg, height: int, window_proc: win32.WNDPROC) layer_type = PFD_MAIN_PLANE, } - SetPixelFormat(w.dc, ChoosePixelFormat(w.dc, ^pfd), null) + SetPixelFormat(w.dc, ChoosePixelFormat(w.dc, ^pfd), nil) w.opengl_context = wglCreateContext(w.dc) wglMakeCurrent(w.dc, w.opengl_context) @@ -154,7 +154,7 @@ run :: proc() { prev_time = curr_time msg: MSG - for PeekMessageA(^msg, null, 0, 0, PM_REMOVE) > 0 { + for PeekMessageA(^msg, nil, 0, 0, PM_REMOVE) > 0 { if msg.message == WM_QUIT { running = false } diff --git a/code/old_demos/demo004.odin b/code/old_demos/demo004.odin new file mode 100644 index 000000000..80812cd18 --- /dev/null +++ b/code/old_demos/demo004.odin @@ -0,0 +1,66 @@ +#import "fmt.odin" +#import "utf8.odin" +#import "hash.odin" +#import "mem.odin" + +main :: proc() { + { // New Standard Library stuff + s := "Hello" + fmt.println(s, + utf8.valid_string(s), + hash.murmur64(s.data, s.count)) + + // utf8.odin + // hash.odin + // - crc, fnv, fnva, murmur + // mem.odin + // - Custom allocators + // - Helpers + } + + { + arena: mem.Arena + mem.init_arena_from_context(^arena, mem.megabytes(16)) // Uses default allocator + defer mem.free_arena(^arena) + + push_allocator mem.arena_allocator(^arena) { + x := new(int) + x^ = 1337 + + fmt.println(x^) + } + + /* + push_allocator x { + ... + } + + is equivalent to: + + { + prev_allocator := __context.allocator + __context.allocator = x + defer __context.allocator = prev_allocator + + ... + } + */ + + // You can also "push" a context + + c := current_context() // Create copy of the allocator + c.allocator = mem.arena_allocator(^arena) + + push_context c { + x := new(int) + x^ = 365 + + fmt.println(x^) + } + } + + // Backend improvements + // - Minimal dependency building (only build what is needed) + // - Numerous bugs fixed + // - Mild parsing recovery after bad syntax error +} -- cgit v1.2.3