mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-04 12:07:45 +00:00
Untyped nil
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
66
code/old_demos/demo004.odin
Normal file
66
code/old_demos/demo004.odin
Normal file
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user