From: Brendan Hansen Date: Fri, 11 Dec 2020 21:11:46 +0000 (-0600) Subject: made struct literals more package friendly and fixed scratch allocation X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=aefb96dd26651ef8db7568373923c5bda5181e5c;p=onyx.git made struct literals more package friendly and fixed scratch allocation bugs --- diff --git a/.vimspector.json b/.vimspector.json index 66190527..051f9127 100644 --- a/.vimspector.json +++ b/.vimspector.json @@ -6,7 +6,7 @@ "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/onyx", - "args": ["-verbose", "tests/i32map.onyx"], + "args": ["-verbose", "tests/hello_world.onyx"], "stopAtEntry": true, "cwd": "~/dev/c/onyx", "environment": [], diff --git a/CHANGELOG b/CHANGELOG index f9816a44..5fb62ab7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,8 +5,11 @@ Additions: Removals: Changes: +* struct literals can now have arbitrary package prefixes on them, i.e. + some.deeply.nested.packages.Struct.{ ... }; Bug fixes: +* globals that were #foreign caused several bugs, which have been squashed. diff --git a/docs/todo b/docs/todo index 4f97f492..752156df 100644 --- a/docs/todo +++ b/docs/todo @@ -44,7 +44,7 @@ Language Cohesion: of technical laziness. Cleaning up these areas will help the language feel more cohesive and put together. - [ ] Struct literals can only have 1 level of package before the struct + [X] Struct literals can only have 1 level of package before the struct name. This is because packages were not able to be nested, so having arbitrary package levels before a struct literal was not necessary. The following should work when this is patched: diff --git a/onyx b/onyx index 2248b973..e06f4f93 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/foo_test.onyx b/progs/foo_test.onyx index e372dfa3..08e0f2a9 100644 --- a/progs/foo_test.onyx +++ b/progs/foo_test.onyx @@ -2,4 +2,6 @@ package test.foo use package core +TestFoo :: struct { a: i32; } + print_foo :: proc () do println("Foo!"); diff --git a/progs/odin_example.onyx b/progs/odin_example.onyx index 9a392dab..76fb770d 100644 --- a/progs/odin_example.onyx +++ b/progs/odin_example.onyx @@ -3,6 +3,7 @@ use package core use package test { foo as foo_pkg } +use package test as test Foo :: struct { data1 : i32; @@ -11,7 +12,7 @@ Foo :: struct { Bar :: struct { use foo : Foo; - bar_data : string; + bar_data : str; // bar_data2 : cstring; } @@ -57,8 +58,10 @@ make_bar :: proc () -> Bar { return bar; } -main :: proc (args: [] cstring) { +main :: proc (args: [] cstr) { foo_pkg.print_foo(); + foo := test.foo.TestFoo.{ a = 1234 }; + printf("foo.a: %i\n", foo.a); bar := make_bar(); diff --git a/src/onyx.c b/src/onyx.c index a65e53a7..a649da20 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -522,7 +522,7 @@ static i32 onyx_compile(CompilerState* compiler_state) { int main(int argc, char *argv[]) { - bh_scratch_init(&global_scratch, bh_heap_allocator(), 16 * 1024); // NOTE: 16 KB + bh_scratch_init(&global_scratch, bh_heap_allocator(), 128 * 1024); // NOTE: 128 KB global_scratch_allocator = bh_scratch_allocator(&global_scratch); bh_managed_heap_init(&global_heap);