diff options
| author | Ginger Bill <bill@gingerbill.org> | 2016-10-06 17:11:17 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2016-10-06 17:11:17 +0100 |
| commit | 50301557b2425fc0b4dd213ad03fb635cbd6e454 (patch) | |
| tree | bcb09c25f839099ac172529283bc7e4a147614d8 /code/old_demos | |
| parent | fee504636f9cd7633217e1877ee1b99e555bba63 (diff) | |
Untyped `nil`
Diffstat (limited to 'code/old_demos')
| -rw-r--r-- | code/old_demos/demo004.odin | 66 |
1 files changed, 66 insertions, 0 deletions
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 +} |