From: Brendan Hansen Date: Sat, 10 Apr 2021 03:00:38 +0000 (-0500) Subject: removed 'proc's; more fun output X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=43cae769ce01fbac15b99a19a8bfc08316b59e23;p=onyx.git removed 'proc's; more fun output --- diff --git a/bin/onyx b/bin/onyx index a733f4b9..5e9795c5 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/array.onyx b/core/array.onyx index f1a52cb1..562e3602 100644 --- a/core/array.onyx +++ b/core/array.onyx @@ -156,17 +156,18 @@ sort :: (arr: ^[..] $T, cmp: (T, T) -> i32) { } } -fold :: (arr: ^[..] $T, init: $R, f: (T, R) -> R) -> R { - val := init; - for it: *arr do val = f(it, val); - return val; -} - -// CLEANUP: :slice Move this elsewhere when more slice functionality is added -fold_slice :: (arr: [] $T, init: $R, f: (T, R) -> R) -> R { - val := init; - for it: arr do val = f(it, val); - return val; +fold :: proc { + (arr: ^[..] $T, init: $R, f: (T, R) -> R) -> R { + val := init; + for it: *arr do val = f(it, val); + return val; + }, + + (arr: [] $T, init: $R, f: (T, R) -> R) -> R { + val := init; + for it: arr do val = f(it, val); + return val; + } } map :: (arr: ^[..] $T, data: $R, f: (T, R) -> T) { @@ -174,23 +175,31 @@ map :: (arr: ^[..] $T, data: $R, f: (T, R) -> T) { } #private_file -greatest_impl :: (arr: ^$T, count: i32) -> (i32, T) { - greatest_idx := 0; - greatest := arr[0]; +fold_idx_elem :: (arr: ^$T, count: i32, cmp: (T, T) -> bool) -> (i32, T) { + idx := 0; + elem := arr[0]; for i: 1 .. count { - if arr[i] > greatest { - greatest_idx = i; - greatest = arr[i]; + if cmp(arr[i], elem) { + idx = i; + elem = arr[i]; } } - return greatest_idx, greatest; + return idx, elem; } -// This pattern should be expanded on to make all kinds of folding functions. +#private_file cmp_greater :: (x: $T, y: T) -> bool do return x > y; +#private_file cmp_less :: (x: $T, y: T) -> bool do return x < y; + greatest :: proc { - (arr: [..] $T) -> (i32, T) { return greatest_impl(arr.data, arr.count); }, - (arr: [] $T) -> (i32, T) { return greatest_impl(arr.data, arr.count); }, - (arr: [$N] $T) -> (i32, T) { return greatest_impl(cast(^T) arr, N); }, + (arr: [..] $T) -> (i32, T) { return fold_idx_elem(arr.data, arr.count, cmp_greater); }, + (arr: [] $T) -> (i32, T) { return fold_idx_elem(arr.data, arr.count, cmp_greater); }, + (arr: [$N] $T) -> (i32, T) { return fold_idx_elem(cast(^T) arr, N, cmp_greater); }, +} + +least :: proc { + (arr: [..] $T) -> (i32, T) { return fold_idx_elem(arr.data, arr.count, cmp_less); }, + (arr: [] $T) -> (i32, T) { return fold_idx_elem(arr.data, arr.count, cmp_less); }, + (arr: [$N] $T) -> (i32, T) { return fold_idx_elem(cast(^T) arr, N, cmp_less); }, } diff --git a/core/builtin.onyx b/core/builtin.onyx index b15509f5..7a7fd34c 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -136,6 +136,7 @@ calloc :: (size: u32) -> rawptr do return raw_alloc(context.allocator, size); cresize :: (ptr: rawptr, size: u32) -> rawptr do return raw_resize(context.allocator, ptr, size); cfree :: (ptr: rawptr) do raw_free(context.allocator, ptr); +// CLEANUP: Does this really need to be limited to a non-custom runtime? #if runtime.Runtime != runtime.Runtime_Custom { new :: ($T: type_expr, allocator := context.allocator, initialize := true) -> ^T { res := cast(^T) raw_alloc(allocator, sizeof T); diff --git a/core/io/file.onyx b/core/io/file.onyx index 757be624..36d7b404 100644 --- a/core/io/file.onyx +++ b/core/io/file.onyx @@ -151,7 +151,7 @@ get_contents_from_file :: (file: File) -> str { get_contents :: proc { get_contents_from_file, - proc (path: str) -> str { + (path: str) -> str { tmp_file, success := file_open(path, OpenMode.Read); if !success do return .{ null, 0 }; defer file_close(tmp_file); diff --git a/core/math.onyx b/core/math.onyx index ad579b23..b7b48a57 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -249,7 +249,7 @@ clamp :: (v: $T, lo: T, hi: T) -> T { } sqrt :: proc { wasm.sqrt_f32, wasm.sqrt_f64, sqrt_poly } -sqrt_poly :: proc (x: $T) -> T { +sqrt_poly :: (x: $T) -> T { return ~~ sqrt_f64(~~ x); } diff --git a/core/runtime/js.onyx b/core/runtime/js.onyx index 2907569c..2891881d 100644 --- a/core/runtime/js.onyx +++ b/core/runtime/js.onyx @@ -10,7 +10,7 @@ __exit :: (status: i32) -> void #foreign "host" "exit" --- // The builtin _start proc. // Sets up everything needed for execution. -proc () #export "_start" { +_start :: () -> void #export "_start" { __runtime_initialize(); args: [] cstr = .{ null, 0 }; diff --git a/core/runtime/wasi.onyx b/core/runtime/wasi.onyx index 3fdb3365..a28b73cf 100644 --- a/core/runtime/wasi.onyx +++ b/core/runtime/wasi.onyx @@ -21,7 +21,7 @@ __exit :: (status: i32) do proc_exit(status); // The builtin _start proc. // Sets up everything needed for execution. -proc () #export "_start" { +_start :: () -> void #export "_start" { __runtime_initialize(); args : [] cstr; diff --git a/core/stdio.onyx b/core/stdio.onyx index 86569be3..f2721437 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -12,10 +12,12 @@ use package runtime as runtime #error "'stdio' can only be included in the 'wasi' or 'js' runtime." } +auto_flush_stdio := true + print :: proc { (x: str) { io.write(^print_writer, x); - if x[x.count - 1] == #char "\n" do __flush_stdio(); + if x[x.count - 1] == #char "\n" && auto_flush_stdio do __flush_stdio(); }, (x: $T) { io.write(^print_writer, x); }, diff --git a/examples/07_structs.onyx b/examples/07_structs.onyx index efbe9da7..b562d059 100644 --- a/examples/07_structs.onyx +++ b/examples/07_structs.onyx @@ -127,7 +127,7 @@ main :: (args: [] cstr) { // pointer conversion between two structs, A and B, if A is the first member of B, and is used. // For example, we can pass `thing` to this procedure, even though it is not a ComponentOne. // The first member is a ComponentOne and is used, so a implicit pointer conversion is always safe. - do_something_with_component_one :: proc (c: ^ComponentOne) { + do_something_with_component_one :: (c: ^ComponentOne) { printf("ComponentOne's name is %s.\n", c.name); } @@ -161,6 +161,6 @@ main :: (args: [] cstr) { - print_spacer :: proc () do println("\n==========================================="); + print_spacer :: () do println("\n==========================================="); } diff --git a/include/onyxastnodes.h b/include/onyxastnodes.h index 827072bb..5d30efbc 100644 --- a/include/onyxastnodes.h +++ b/include/onyxastnodes.h @@ -981,6 +981,8 @@ typedef struct EntityHeap { i32 state_count[Entity_State_Count]; i32 type_count[Entity_Type_Count]; + + i32 all_count[Entity_State_Count][Entity_Type_Count]; } EntityHeap; void entity_heap_init(EntityHeap* entities); diff --git a/progs/foo_test.onyx b/progs/foo_test.onyx index f395f2f5..83f13159 100644 --- a/progs/foo_test.onyx +++ b/progs/foo_test.onyx @@ -4,6 +4,6 @@ use package core TestFoo :: struct { a: i32; } -print_foo :: proc () do println("Foo!"); +print_foo :: () do println("Foo!"); SomeEnum :: enum #flags { Val1; Val2; Val3; } diff --git a/progs/odin_example.onyx b/progs/odin_example.onyx index 309f06c4..566a3d20 100644 --- a/progs/odin_example.onyx +++ b/progs/odin_example.onyx @@ -30,7 +30,7 @@ Bar :: struct { // asdf :: proc (f: Foo) -> ... // asdf(bar.foo); -print_foo :: proc (f: ^Foo) { +print_foo :: (f: ^Foo) { print("Foo: \n"); print(f.data1); print("\n"); @@ -38,7 +38,7 @@ print_foo :: proc (f: ^Foo) { print("\n"); } -print_bar :: proc (bar: ^Bar) { +print_bar :: (bar: ^Bar) { print(bar.data1); print("\n"); print(cast(i32) bar.data2); @@ -47,7 +47,7 @@ print_bar :: proc (bar: ^Bar) { print("\n"); } -make_bar :: proc () -> Bar { +make_bar :: () -> Bar { bar : Bar; bar.data1 = 1234; bar.data2 = 12.34f; @@ -56,7 +56,7 @@ make_bar :: proc () -> Bar { return bar; } -f :: proc () -> [5] [2] u32 #export "IAMTHEFUNCTION" { +f :: () -> [5] [2] u32 #export "IAMTHEFUNCTION" { // This method of returning an array will leak memory, since this is never freed. // mem := cast(^u32) calloc(sizeof [5] [2] u32); // for i: 0 .. 10 do mem[i] = 1234 + i; @@ -69,7 +69,7 @@ f :: proc () -> [5] [2] u32 #export "IAMTHEFUNCTION" { return mem; } -compress :: proc (arr: [$N] $T, f : proc (T, T) -> T) -> T { +compress :: (arr: [$N] $T, f : proc (T, T) -> T) -> T { val := arr[0]; for i: 1..N do val = f(val, arr[i]); return val; @@ -85,14 +85,14 @@ BadUnion :: struct { Vec2 :: struct { x: i32; y: i32; } Entity :: struct { use pos: Vec2; } -array_literal_optim :: proc () #export { +array_literal_optim :: () -> void #export { bar : [5] u32; bar = u32.[ 1, 2, 3, 4, 5 ]; bar[2] = 1234; for b: bar do printf("b: %i\n", b); } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { a : BadUnion; a.int = 1234; a.float = 0.5; @@ -112,7 +112,7 @@ main :: proc (args: [] cstr) { printf("%p == %p\n", cast(^u32) foo, ^foo); for ^thing: foo do for t: *thing do printf("%p %i\n", thing, t); - println(compress(f32.[ 1, 2, 3, 4, 5 ], proc (a: $T, b: T) -> T { return a + b; })); + println(compress(f32.[ 1, 2, 3, 4, 5 ], (a: $T, b: T) -> T { return a + b; })); } use package test { foo as foo_pkg } diff --git a/progs/particle_sym.onyx b/progs/particle_sym.onyx index b52eec17..fefebb4a 100644 --- a/progs/particle_sym.onyx +++ b/progs/particle_sym.onyx @@ -6,7 +6,7 @@ package main use package core use package core.intrinsics.simd -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { init_positions(); init_velocities(); @@ -24,7 +24,7 @@ OBJECT_COUNT :: 10000 positions : [OBJECT_COUNT] f32x4 velocities : [OBJECT_COUNT] f32x4 -init_positions :: proc () { +init_positions :: () { for ^p: positions { *p = f32x4_replace_lane(*p, 0, random.float(-127.0f, 127.0f)); *p = f32x4_replace_lane(*p, 1, random.float(-127.0f, 127.0f)); @@ -33,23 +33,23 @@ init_positions :: proc () { } } -init_velocities :: proc () { +init_velocities :: () { for ^v: velocities do *v = f32x4_splat(0.0f); } -horizontal_add :: proc (f: f32x4) -> f32 { +horizontal_add :: (f: f32x4) -> f32 { return f32x4_extract_lane(f, 0) + f32x4_extract_lane(f, 1) + f32x4_extract_lane(f, 2) + f32x4_extract_lane(f, 3); } -distance :: proc (x: f32x4, y: f32x4) -> f32 { +distance :: (x: f32x4, y: f32x4) -> f32 { d := f32x4_sub(x, y); return horizontal_add(f32x4_mul(d, d)); } -update :: proc () { +update :: () { for i: 0 .. OBJECT_COUNT { for j: 0 .. OBJECT_COUNT { dist := distance(positions[i], positions[j]); @@ -64,7 +64,7 @@ update :: proc () { } } -avg_motion :: proc () -> f32 { +avg_motion :: () -> f32 { avg_motion := f32x4_splat(0.0f); obj_vec := f32x4_splat(cast(f32) OBJECT_COUNT); for v: velocities { diff --git a/progs/poly_solidify.onyx b/progs/poly_solidify.onyx index 931c5e7e..4c623768 100644 --- a/progs/poly_solidify.onyx +++ b/progs/poly_solidify.onyx @@ -4,13 +4,13 @@ use package core max_f32 :: #solidify math.max_poly { T = f32 }; -compose :: proc (a: $A, f: proc (A) -> $B, g: proc (B) -> $C) -> C do return g(f(a)); +compose :: (a: $A, f: (A) -> $B, g: (B) -> $C) -> C do return g(f(a)); specific_compose_0 :: #solidify compose { B = f32 }; specific_compose_1 :: #solidify specific_compose_0 { A = f32 }; specific_compose_2 :: #solidify specific_compose_1 { C = f64 }; -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { use package runtime println(Runtime); println("=================================================="); @@ -22,8 +22,8 @@ main :: proc (args: [] cstr) { println(specific_compose_2( 2, - proc (a: f32) -> f32 { return ~~(a * 2); }, - proc (b: f32) -> f64 { return ~~(b + 6); })); + (a: f32) -> f32 { return ~~(a * 2); }, + (b: f32) -> f64 { return ~~(b + 6); })); arr1 := array.make(f32); @@ -42,7 +42,7 @@ main :: proc (args: [] cstr) { print_arrays(arr1, arr2); - print_arrays :: proc (arr1: [..] $T, arr2: [..] $R) { + print_arrays :: (arr1: [..] $T, arr2: [..] $R) { println("=================================================="); print_array(arr1); print_array(arr2); @@ -50,7 +50,7 @@ main :: proc (args: [] cstr) { } } -array_map :: proc (arr: [..] $T, f: proc (T) -> T) { +array_map :: (arr: [..] $T, f: (T) -> T) { foo := #solidify math.max_poly { T = T }; is := (#type InternalStruct(T)).{ foo = foo(6, 2) }; printf("%i\n", is.foo); @@ -60,7 +60,7 @@ array_map :: proc (arr: [..] $T, f: proc (T) -> T) { { test2(); - test2 :: proc () { + test2 :: () { test(); is : InternalStruct([] u32); @@ -68,7 +68,7 @@ array_map :: proc (arr: [..] $T, f: proc (T) -> T) { println("WORLD!!!!"); } - test :: proc () { + test :: () { println("HELLO!!!"); } } @@ -78,4 +78,4 @@ array_map :: proc (arr: [..] $T, f: proc (T) -> T) { } } -double :: proc (v: $V) -> V do return v * 2; +double :: (v: $V) -> V do return v * 2; diff --git a/progs/simd_test.onyx b/progs/simd_test.onyx index c3ea8149..c0a90514 100644 --- a/progs/simd_test.onyx +++ b/progs/simd_test.onyx @@ -6,7 +6,7 @@ package main use package core use package core.intrinsics.simd -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { x := f32x4_const(10.0f, 20.0f, 30.0f, 40.0f); y := f32x4_splat(100.0f); diff --git a/progs/vararg_test.onyx b/progs/vararg_test.onyx index 14759e38..ada9a3df 100644 --- a/progs/vararg_test.onyx +++ b/progs/vararg_test.onyx @@ -4,7 +4,7 @@ package main use package core; -old_va_test :: proc (fix: Fixes, va: ..i32) { +old_va_test :: (fix: Fixes, va: ..i32) { println(fix.prefix); for v: va do println(v); println(fix.suffix); @@ -12,7 +12,7 @@ old_va_test :: proc (fix: Fixes, va: ..i32) { Fixes :: struct { prefix: str; suffix: str; } -new_va_test :: proc (fix: Fixes, va: ...) { +new_va_test :: (fix: Fixes, va: ...) { println(fix.prefix); for i: 0 .. va.count { @@ -24,7 +24,7 @@ new_va_test :: proc (fix: Fixes, va: ...) { println(fix.suffix); } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { new_va_test(Fixes.{ "foo", "foozle" }, 1, 2, 3.0f, 5.0f); old_va_test(Fixes.{ "bar", "barzle" }, 1); diff --git a/progs/wasi_test.onyx b/progs/wasi_test.onyx index 40f48b0f..64cc6513 100644 --- a/progs/wasi_test.onyx +++ b/progs/wasi_test.onyx @@ -8,7 +8,7 @@ use package core use package core_file use package wasi -// print_rights :: proc (rights: Rights) { +// print_rights :: (rights: Rights) { // print(cast(u32) rights, 2); // print("\n"); // @@ -43,7 +43,7 @@ use package wasi // if rights & Rights.SockShutdown != cast(Rights) 0 do print("SockShutdown\n"); // } -readline :: proc (buf: ^u8, bufsize: u32) -> u32 { +readline :: (buf: ^u8, bufsize: u32) -> u32 { iov := IOVec.{ buf, bufsize }; nread : Size; fd_pread(0, IOVecArray.{ ^iov, 1 }, 0, ^nread); @@ -51,7 +51,7 @@ readline :: proc (buf: ^u8, bufsize: u32) -> u32 { return nread; } -readdir :: proc (fd: FileDescriptor) { +readdir :: (fd: FileDescriptor) { buf : [1024] u8; bufused : Size; @@ -79,19 +79,19 @@ readdir :: proc (fd: FileDescriptor) { } } -timer_start :: proc () -> Timestamp { +timer_start :: () -> Timestamp { curr_time: Timestamp; clock_time_get(ClockID.Realtime, cast(Timestamp) 1, ^curr_time); return curr_time; } -timer_end :: proc (start_time: Timestamp) -> Timestamp { +timer_end :: (start_time: Timestamp) -> Timestamp { curr_time: Timestamp; clock_time_get(ClockID.Realtime, cast(Timestamp) 1, ^curr_time); return (curr_time - start_time) / 1000000; } -is_prime :: proc (n := 0) -> bool { +is_prime :: (n := 0) -> bool { sqrt :: cast(i32) (sqrt_f32(cast(f32) n)); for i: 2 .. sqrt + 1 do if n % i == 0 do return false; return true; @@ -109,7 +109,7 @@ S :: struct { pos: Vec3; } -output_s :: proc (sb: ^StringBuilder, s: ^S) -> ^StringBuilder { +output_s :: (sb: ^StringBuilder, s: ^S) -> ^StringBuilder { sb |> sba("Hello, I'm ") |> sba(s.name) |> sba(". I am ") @@ -122,7 +122,7 @@ output_s :: proc (sb: ^StringBuilder, s: ^S) -> ^StringBuilder { return sb; } -print_arr :: proc (sb: ^StringBuilder, arr: [] $T) { +print_arr :: (sb: ^StringBuilder, arr: [] $T) { sb |> string_builder_clear(); for i: 0 .. arr.count { @@ -132,12 +132,12 @@ print_arr :: proc (sb: ^StringBuilder, arr: [] $T) { sb |> sba("\n") |> string_builder_to_string() |> print(); } -make_i32_arr :: proc (a := context.allocator, len := 10) -> [] i32 { +make_i32_arr :: (a := context.allocator, len := 10) -> [] i32 { arr := cast(^i32) alloc(a, sizeof i32 * len); return arr[0 .. len]; } -main :: proc (args: []cstring) { +main :: (args: []cstring) { now : Timestamp; clock_time_get(ClockID.Realtime, cast(Timestamp) 1, ^now); @@ -297,7 +297,7 @@ main :: proc (args: []cstring) { print(dynarr.count, 10); } -foobar :: proc (a: i32, b := 1, c: i64 = 5) { +foobar :: (a: i32, b := 1, c: i64 = 5) { print_i64(cast(u64) a); print("\n"); print_i64(cast(u64) b, 16); @@ -306,7 +306,7 @@ foobar :: proc (a: i32, b := 1, c: i64 = 5) { print("\n"); } -fib :: proc (n: i32) -> i32 { +fib :: (n: i32) -> i32 { switch n { case 0 do return 1; case 1 do return 1; @@ -318,16 +318,16 @@ fib :: proc (n: i32) -> i32 { return 0; } -add :: proc (a: $T, b: T) -> T { +add :: (a: $T, b: T) -> T { return a + b; } -multi_poly :: proc (a: $T, b: $R) -> R { +multi_poly :: (a: $T, b: $R) -> R { return cast(R) (a + cast(T) b); } -make_slice :: proc (ptr: ^$T, count: u32) -> [] T { +make_slice :: (ptr: ^$T, count: u32) -> [] T { return ptr[4 .. count]; } -get_slice_length :: proc (s: ^[] $T) -> u32 do return s.count; +get_slice_length :: (s: ^[] $T) -> u32 do return s.count; diff --git a/src/onyx.c b/src/onyx.c index c0969323..5030c3f1 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -369,12 +369,50 @@ static void output_dummy_progress_bar() { EntityHeap* eh = &context.entities; if (bh_arr_length(eh->entities) == 0) return; + static const char* state_colors[] = { + "\e[91m", + "\e[93m", + "\e[97m", + "\e[93m", + "\e[94m", + "\e[95m", + "\e[94m", + "\e[95m", + "\e[96m", + "\e[92m", + }; + printf("\e[2;1H"); + for (i32 i = 0; i < Entity_State_Count - 1; i++) { - printf("%25s (%4d) | ", entity_state_strings[i], eh->state_count[i]); - + if (i % 4 == 0) printf("\n"); + printf("%s \xe2\x96\x88 %s", state_colors[i], entity_state_strings[i]); + } + + printf("\n\n"); + + for (i32 i = 0; i < Entity_Type_Count; i++) { + if (eh->type_count[i] == 0) { + printf("\e[90m"); + } else { + printf("\e[97m"); + } + + printf("%25s (%4d) | ", entity_type_strings[i], eh->type_count[i]); + printf("\e[0K"); - for (i32 c = 0; c < eh->state_count[i] * 50 / bh_arr_length(eh->entities); c++) printf("\xe2\x96\x88"); + for (i32 j = 0; j < Entity_State_Count; j++) { + if (eh->all_count[j][i] == 0) continue; + + printf(state_colors[j]); + + i32 count = (eh->all_count[j][i] >> 5) + 1; + for (i32 c = 0; c < count * 2; c++) { + printf("\xe2\x96\x88"); + } + + printf("\e[0m"); + } printf("\n"); } } diff --git a/src/onyxdoc.c b/src/onyxdoc.c index cbb5893d..b6015d41 100644 --- a/src/onyxdoc.c +++ b/src/onyxdoc.c @@ -25,7 +25,7 @@ static char* node_to_doc_def(const char* sym, AstNode *node, bh_allocator a) { switch (node->kind) { case Ast_Kind_Function: { - strncat(buf, "proc (", 1023); + strncat(buf, "(", 1023); AstFunction *func = (AstFunction *) node; bh_arr_each(AstParam, param, func->params) { diff --git a/src/onyxentities.c b/src/onyxentities.c index d415b62d..ce4112c0 100644 --- a/src/onyxentities.c +++ b/src/onyxentities.c @@ -91,8 +91,9 @@ void entity_heap_insert_existing(EntityHeap* entities, Entity* e) { eh_shift_up(entities, bh_arr_length(entities->entities) - 1); e->entered_in_queue = 1; - entities->state_count[e->state]++; + entities->state_count[e->state]++; entities->type_count[e->type]++; + entities->all_count[e->state][e->type]++; } // nocheckin @@ -107,12 +108,14 @@ Entity* entity_heap_top(EntityHeap* entities) { } void entity_heap_change_top(EntityHeap* entities, Entity* new_top) { - entities->state_count[entities->entities[0]->state]--; - entities->state_count[new_top->state]--; + entities->state_count[entities->entities[0]->state]--; + entities->state_count[new_top->state]++; - // CLEANUP: I don't think both of these should be --? entities->type_count[entities->entities[0]->type]--; - entities->type_count[new_top->type]--; + entities->type_count[new_top->type]++; + + entities->all_count[entities->entities[0]->state][entities->entities[0]->type]--; + entities->all_count[new_top->state][new_top->type]++; entities->entities[0] = new_top; eh_shift_down(entities, 0); @@ -121,6 +124,7 @@ void entity_heap_change_top(EntityHeap* entities, Entity* new_top) { void entity_heap_remove_top(EntityHeap* entities) { entities->state_count[entities->entities[0]->state]--; entities->type_count[entities->entities[0]->type]--; + entities->all_count[entities->entities[0]->state][entities->entities[0]->type]--; entities->entities[0]->entered_in_queue = 0; entities->entities[0] = entities->entities[bh_arr_length(entities->entities) - 1]; diff --git a/src/onyxtypes.c b/src/onyxtypes.c index 42eab6b2..778b3897 100644 --- a/src/onyxtypes.c +++ b/src/onyxtypes.c @@ -46,9 +46,7 @@ b32 types_are_compatible_(Type* t1, Type* t2, b32 recurse_pointers) { switch (t1->kind) { case Type_Kind_Basic: if (t2->kind == Type_Kind_Basic) { - // HACK: Not sure if this is right way to check this? - if (t1 == t2) return 1; - + // Signedness of an integer doesn't matter. if ((t1->Basic.flags & Basic_Flag_Integer) && (t2->Basic.flags & Basic_Flag_Integer)) { return t1->Basic.size == t2->Basic.size; } @@ -660,7 +658,7 @@ const char* type_get_unique_name(Type* type) { char buf[512]; fori (i, 0, 512) buf[i] = 0; - strncat(buf, "proc (", 511); + strncat(buf, "(", 511); fori (i, 0, type->Function.param_count) { strncat(buf, type_get_unique_name(type->Function.params[i]), 511); if (i != type->Function.param_count - 1) @@ -703,7 +701,7 @@ const char* type_get_name(Type* type) { char buf[512]; fori (i, 0, 512) buf[i] = 0; - strncat(buf, "proc (", 511); + strncat(buf, "(", 511); fori (i, 0, type->Function.param_count) { strncat(buf, type_get_name(type->Function.params[i]), 511); if (i != type->Function.param_count - 1) diff --git a/src/onyxutils.c b/src/onyxutils.c index 84f07092..b7d219fd 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -1023,7 +1023,7 @@ void report_unable_to_match_overload(AstCall* call) { } } - onyx_report_error(call->token->pos, "unable to match overloaded function with provided argument types: (%s)", arg_str); + onyx_report_error(call->token->pos, "Unable to match overloaded function with provided argument types: (%s)", arg_str); bh_free(global_scratch_allocator, arg_str); } diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 7dc355de..ac679c83 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -2165,7 +2165,7 @@ EMIT_FUNC(expression, AstTyped* expr) { // // I think a more general case of accessing fields on r-values is better. For example, // - // returns_foo :: proc () -> Foo { ... } + // returns_foo :: () -> Foo { ... } // // value := returns_foo().foo_member; // diff --git a/tests/aoc-2020/day10.onyx b/tests/aoc-2020/day10.onyx index 13420ee7..2eb0cca0 100644 --- a/tests/aoc-2020/day10.onyx +++ b/tests/aoc-2020/day10.onyx @@ -39,7 +39,7 @@ main :: (args: [] cstr) { // Slight hack, but having 0 in the array makes both parts easier array.push(^nums, 0); - cmp_asc :: proc (a: $T, b: T) -> i32 do return ~~(a - b); + cmp_asc :: (a: $T, b: T) -> i32 do return ~~(a - b); array.sort(^nums, cmp_asc); diffs: [3] u32; diff --git a/tests/aoc-2020/day11.onyx b/tests/aoc-2020/day11.onyx index 5375be4b..dccf8765 100644 --- a/tests/aoc-2020/day11.onyx +++ b/tests/aoc-2020/day11.onyx @@ -65,7 +65,7 @@ gos_iter :: (use gos: ^GameOfSeats) -> bool { return changed; } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { contents := #file_contents "./tests/aoc-2020/input/day11.txt"; file := reader.make(contents); diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index 6d8e833a..ea22356b 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -36,7 +36,7 @@ get_neighbor_count :: (cubes: ^map.Map(CubePos, CubeState), pos: CubePos) -> u32 return count; } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { contents := #file_contents "./tests/aoc-2020/input/day17.txt"; file := reader.make(contents); diff --git a/tests/aoc-2020/day5.onyx b/tests/aoc-2020/day5.onyx index 2348531f..d1898aa2 100644 --- a/tests/aoc-2020/day5.onyx +++ b/tests/aoc-2020/day5.onyx @@ -35,4 +35,4 @@ main :: (args: [] cstr) { printf("Your seat: %i\n", missing); } -cmp_asc :: proc (a: $T, b: T) -> i32 do return ~~(a - b); +cmp_asc :: (a: $T, b: T) -> i32 do return ~~(a - b); diff --git a/tests/aoc-2020/day9.onyx b/tests/aoc-2020/day9.onyx index 967dbb33..10d5e1da 100644 --- a/tests/aoc-2020/day9.onyx +++ b/tests/aoc-2020/day9.onyx @@ -64,8 +64,8 @@ main :: (args: [] cstr) { start, end := find_contiguous_subarray_with_sum(nums, invalid); - max := array.fold_slice(nums.data[start .. end + 1], cast(u64) 0, math.max_poly); - min := array.fold_slice(nums.data[start .. end + 1], cast(u64) max, math.min_poly); + max := array.fold(nums.data[start .. end + 1], cast(u64) 0, math.max_poly); + min := array.fold(nums.data[start .. end + 1], cast(u64) max, math.min_poly); printf("Extrema sum: %l\n", min + max); } diff --git a/tests/array_struct_robustness.onyx b/tests/array_struct_robustness.onyx index e001f9d5..806b8656 100644 --- a/tests/array_struct_robustness.onyx +++ b/tests/array_struct_robustness.onyx @@ -14,7 +14,7 @@ EntityStore :: struct { velocities : [4] Vec2; } -calc_vecs :: proc (n := 0) -> [4] Vec2 { +calc_vecs :: (n := 0) -> [4] Vec2 { vecs : [4] Vec2; i := n; @@ -27,7 +27,7 @@ calc_vecs :: proc (n := 0) -> [4] Vec2 { return vecs; } -main :: proc (args: [] cstr) #export "MAIN" { +main :: (args: [] cstr) { // Array of structs on stack { println("Array of structs on the stack."); @@ -95,4 +95,4 @@ main :: proc (args: [] cstr) #export "MAIN" { println(nums[50]); } -} \ No newline at end of file +} diff --git a/tests/baked_parameters.onyx b/tests/baked_parameters.onyx index 01feb48d..461466a6 100644 --- a/tests/baked_parameters.onyx +++ b/tests/baked_parameters.onyx @@ -2,19 +2,19 @@ use package core -count_to :: proc ($N: i32) { +count_to :: ($N: i32) { for i: 0 .. N do printf("%i ", i); print("\n"); } -alloc_slice :: proc ($T: type_expr, N: i32) -> [] T { +alloc_slice :: ($T: type_expr, N: i32) -> [] T { data := cast(^T) calloc(sizeof T * N); return <[] T>.{ data, N }; } count_to_30 :: #solidify count_to { N = #value 30 }; -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { count_to(5); count_to(10); count_to(10); @@ -38,7 +38,7 @@ main :: proc (args: [] cstr) { map.put(^ages, "Jim", 25); map.put(^ages, "Pam", 24); - print_age :: proc (ages: ^map.Map(str, u32), name: str) { + print_age :: (ages: ^map.Map(str, u32), name: str) { age := map.get(ages, name); printf("%s's age is %i.\n", name, age); } diff --git a/tests/compile_time_procedures.onyx b/tests/compile_time_procedures.onyx index eca82416..abc2cdae 100644 --- a/tests/compile_time_procedures.onyx +++ b/tests/compile_time_procedures.onyx @@ -3,20 +3,20 @@ use package core Test_VTable :: struct { - first : proc (i32) -> i32; - second : proc (i32) -> i32; + first : (i32) -> i32; + second : (i32) -> i32; - third : proc (i32, i32) -> i32 = null_proc; + third : (i32, i32) -> i32 = null_proc; } test_vtable1 := Test_VTable.{ - first = proc (a: i32) -> i32 { return a * 2; }, - second = proc (a: i32) -> i32 { return a + 2; }, + first = (a: i32) -> i32 { return a * 2; }, + second = (a: i32) -> i32 { return a + 2; }, } test_vtable2 := Test_VTable.{ - first = proc (a: i32) -> i32 { return a / 2; }, - second = proc (a: i32) -> i32 { return a - 2; }, + first = (a: i32) -> i32 { return a / 2; }, + second = (a: i32) -> i32 { return a - 2; }, } @@ -27,10 +27,10 @@ Test_Thing :: struct { } // because of the work i did above, this also works now. -dummy := proc () { println("hello world!"); } +dummy := () { println("hello world!"); } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { dummy(); t := Test_Thing.{ ^test_vtable1, 10 }; @@ -45,7 +45,7 @@ main :: proc (args: [] cstr) { println(t.vt.first == test_vtable1.second); - do_a_thing :: proc (use t: ^Test_Thing) -> i32 { + do_a_thing :: (use t: ^Test_Thing) -> i32 { if vt.second == null_proc || vt.first == null_proc do return data; res := data |> vt.second() |> vt.first(); @@ -53,4 +53,4 @@ main :: proc (args: [] cstr) { return res; } -} \ No newline at end of file +} diff --git a/tests/defer_with_continue.onyx b/tests/defer_with_continue.onyx index 7e390ce7..1c076ae7 100644 --- a/tests/defer_with_continue.onyx +++ b/tests/defer_with_continue.onyx @@ -2,7 +2,7 @@ use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { defer println("At the end!"); i := 0; while i < 10 { diff --git a/tests/hello_world.onyx b/tests/hello_world.onyx index aa793d3b..88198e4f 100644 --- a/tests/hello_world.onyx +++ b/tests/hello_world.onyx @@ -4,6 +4,6 @@ package main use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { println("Hello, World!"); } diff --git a/tests/i32map.onyx b/tests/i32map.onyx index c83cb05f..2a55f776 100644 --- a/tests/i32map.onyx +++ b/tests/i32map.onyx @@ -4,7 +4,7 @@ package main use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { imap : map.Map(i32, str); map.init(^imap, ""); defer { diff --git a/tests/multiple_returns_robustness.onyx b/tests/multiple_returns_robustness.onyx index 27790819..0021d167 100644 --- a/tests/multiple_returns_robustness.onyx +++ b/tests/multiple_returns_robustness.onyx @@ -2,16 +2,16 @@ use package core -foo :: proc () -> (i32, i32) { +foo :: () -> (i32, i32) { return 50, 60; } -something :: proc (f: proc () -> ($T, T)) -> T { +something :: (f: () -> ($T, T)) -> T { a, b := f(); return a + b; } -get_extrema :: proc (arr: [$N] $T) -> (T, T) { +get_extrema :: (arr: [$N] $T) -> (T, T) { min := arr[0]; max := arr[0]; @@ -23,13 +23,13 @@ get_extrema :: proc (arr: [$N] $T) -> (T, T) { return min, max; } -return_multiple_arrays :: proc () -> ([3] i32, [3] f32) { +return_multiple_arrays :: () -> ([3] i32, [3] f32) { iarr := i32.[ 0, 1, 2 ]; farr := f32.[ 3, 4, 5 ]; return iarr, farr; } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { a, b := foo(); a, b = b, a; @@ -47,7 +47,7 @@ main :: proc (args: [] cstr) { array_print(iarr); array_print(farr); - array_print :: proc (arr: [$N] $T) { + array_print :: (arr: [$N] $T) { for ^e: arr { print(*e); print(" "); diff --git a/tests/named_arguments_test.onyx b/tests/named_arguments_test.onyx index a43ae642..d369d294 100644 --- a/tests/named_arguments_test.onyx +++ b/tests/named_arguments_test.onyx @@ -2,8 +2,8 @@ use package core -main :: proc (args: [] cstr) { - foo :: proc (x: i32, y: f32) { +main :: (args: [] cstr) { + foo :: (x: i32, y: f32) { printf("x is %i\n", x); printf("y is %f\n", y); } @@ -14,7 +14,7 @@ main :: proc (args: [] cstr) { println("\n\n========================="); - poly_named :: proc (x: $T, y: [$N] T) { + poly_named :: (x: $T, y: [$N] T) { println(x); print_array(y); } @@ -26,9 +26,9 @@ main :: proc (args: [] cstr) { println("\n\n========================="); poly_overloaded :: proc { - proc (y: [$N] $T) { print("MATCHED Y: "); print_array(y); }, - proc (x: $T) { print("MATCHED X: "); println(x); }, - proc (z: $T) { print("MATCHED Z: "); println(z); }, + (y: [$N] $T) { print("MATCHED Y: "); print_array(y); }, + (x: $T) { print("MATCHED X: "); println(x); }, + (z: $T) { print("MATCHED Z: "); println(z); }, } poly_overloaded(u32.[ 10, 20 ]); @@ -38,7 +38,7 @@ main :: proc (args: [] cstr) { println("\n\n========================="); - overload_with_varargs :: proc (x: i32, y: i32, z: ..f32) { + overload_with_varargs :: (x: i32, y: i32, z: ..f32) { println(x); println(y); @@ -52,7 +52,7 @@ main :: proc (args: [] cstr) { println("\n\n========================="); - lotza_options :: proc ( + lotza_options :: ( options_a : bool, options_b := false, options_c := true, @@ -74,12 +74,12 @@ main :: proc (args: [] cstr) { // This currently does not work and would require a lot of rewriting of compiler internals to make work. // named_baked_overloaded_parameters :: proc { - // proc ($T: type_expr, x: T) do { println("MATCHED X"); }, - // proc ($T: type_expr, y: [$N] T) do { println("MATCHED X"); }, - // proc ($T: type_expr, z: T) do { println("MATCHED X"); }, + // ($T: type_expr, x: T) do { println("MATCHED X"); }, + // ($T: type_expr, y: [$N] T) do { println("MATCHED X"); }, + // ($T: type_expr, z: T) do { println("MATCHED X"); }, // } // named_baked_overloaded_parameters(i32, 10); // named_baked_overloaded_parameters(i32, u32.[ 10, 20, 30 ]); // named_baked_overloaded_parameters(i32, z = u32.[ 10, 20, 30 ]); -} \ No newline at end of file +} diff --git a/tests/operator_overload.onyx b/tests/operator_overload.onyx index 41e6b3e4..e5b58f55 100644 --- a/tests/operator_overload.onyx +++ b/tests/operator_overload.onyx @@ -19,7 +19,7 @@ proc (a: Complex, b: Complex) -> Complex #operator* { return Complex.{ a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re }; } -C :: proc (re: f32, im: f32) -> Complex do return Complex.{ re, im }; +C :: (re: f32, im: f32) -> Complex do return Complex.{ re, im }; @@ -52,18 +52,18 @@ proc (a: Vec($T, $N), b: Vec(T, N)) -> T #operator* { return res; } -join :: proc (a: Vec($T, $N), b: Vec(T, $M)) -> Vec(T, #value N + M) { +join :: (a: Vec($T, $N), b: Vec(T, $M)) -> Vec(T, #value N + M) { out : Vec(T, #value N + M); for i: 0 .. N do out.data[i] = a.data[i]; for i: 0 .. M do out.data[i + N] = b.data[i]; return out; } -make_vec :: proc (data: [$N] $T) -> Vec(T, N) { +make_vec :: (data: [$N] $T) -> Vec(T, N) { return .{ data }; } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { { a := C(2, 3); b := C(0, 1); @@ -101,6 +101,6 @@ main :: proc (args: [] cstr) { } test_overload :: proc { - proc (x: $T, y: T) -> T { return x; }, - proc (x: $T, y: $R) -> R { return y; }, + (x: $T, y: T) -> T { return x; }, + (x: $T, y: $R) -> R { return y; }, } diff --git a/tests/overload_with_autocast.onyx b/tests/overload_with_autocast.onyx index e790ac62..1dcef3d3 100644 --- a/tests/overload_with_autocast.onyx +++ b/tests/overload_with_autocast.onyx @@ -3,12 +3,12 @@ use package core overloaded :: proc { - proc (x: str, y: i32) do println("Called str, i32"); , - proc (x: f32, y: str) do println("Called f32, str"); , - proc (x: i32, y: i32) do println("Called i32, i32"); , + (x: str, y: i32) do println("Called str, i32"); , + (x: f32, y: str) do println("Called f32, str"); , + (x: i32, y: i32) do println("Called i32, i32"); , } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { x: i32 = 1234; overloaded(~~x, 4); diff --git a/tests/poly_structs_with_values.onyx b/tests/poly_structs_with_values.onyx index d49957f9..3fd00534 100644 --- a/tests/poly_structs_with_values.onyx +++ b/tests/poly_structs_with_values.onyx @@ -2,7 +2,7 @@ use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { NewPolyStruct :: struct (T: type_expr, N: i32) { x : [N] T; y : [N] f32; @@ -29,5 +29,5 @@ main :: proc (args: [] cstr) { println(swd.str_member); poly_match(swd); - poly_match :: proc (swd: SimpleWithDefault($T, $D)) do println(D); -} \ No newline at end of file + poly_match :: (swd: SimpleWithDefault($T, $D)) do println(D); +} diff --git a/tests/polymorphic_array_lengths.onyx b/tests/polymorphic_array_lengths.onyx index 822b2faf..7f88e2b3 100644 --- a/tests/polymorphic_array_lengths.onyx +++ b/tests/polymorphic_array_lengths.onyx @@ -2,7 +2,7 @@ use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { arr := u32.[ 1, 2, 3, 4, 5 ]; for elem: array_to_slice(arr) do printf("%i ", elem); @@ -11,13 +11,13 @@ main :: proc (args: [] cstr) { for root: roots do println(root); - array_to_slice :: proc (arr: [$N] $T) -> [] T { + array_to_slice :: (arr: [$N] $T) -> [] T { return (#type [] T).{ ~~arr, N }; } - compute_roots :: proc (arr: [$N] f32) { + compute_roots :: (arr: [$N] f32) { for i: 0 .. N { arr[i] = math.sqrt(cast(f32) i); } } -} \ No newline at end of file +} diff --git a/tests/string_stream_test.onyx b/tests/string_stream_test.onyx index b18e0d35..b3eb204a 100644 --- a/tests/string_stream_test.onyx +++ b/tests/string_stream_test.onyx @@ -2,7 +2,7 @@ use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { some_string := "This is a test string that can be read.\n\n\n\n\n\n1234 4567"; sstream := io.string_stream_make(some_string); diff --git a/tests/struct_robustness.onyx b/tests/struct_robustness.onyx index 896d038c..f84f7c88 100644 --- a/tests/struct_robustness.onyx +++ b/tests/struct_robustness.onyx @@ -2,7 +2,7 @@ use package core -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { test_simple_struct(); test_simple_union(); @@ -14,7 +14,7 @@ main :: proc (args: [] cstr) { test_polymorphic_union(); test_polymorphic_union_with_use(); - test_simple_struct :: proc () { + test_simple_struct :: () { println("Testing a simple structure."); SimpleStruct :: struct { @@ -33,7 +33,7 @@ main :: proc (args: [] cstr) { cast(u32) age, height, name); } - test_simple_union :: proc () { + test_simple_union :: () { println("\n\nTesting a simple union."); SimpleUnion :: struct #union { @@ -47,7 +47,7 @@ main :: proc (args: [] cstr) { printf("%p == 0x3F000000\n", u.int_val); } - test_default_values :: proc () { + test_default_values :: () { println("\n\nTesting a struct with default values."); DefaultedStruct :: struct { @@ -63,12 +63,12 @@ main :: proc (args: [] cstr) { ds2 := DefaultedStruct.{ i = 3, d = 0 }; print_defaulted(ds2); - print_defaulted :: proc (use ds: DefaultedStruct) { + print_defaulted :: (use ds: DefaultedStruct) { printf("DefaultedStruct(%i, %f, %l, %d)\n", i, f, l, d); } } - test_simple_use :: proc () { + test_simple_use :: () { println("\n\nTesting a struct with `use`."); StructWithUse :: struct { @@ -95,7 +95,7 @@ main :: proc (args: [] cstr) { // This will not work. `use`d members cannot be set directly. // swu3 := StructWithUse.{ 1234, 1, 2, 5678 }; - print_swu :: proc (use swu: StructWithUse) { + print_swu :: (use swu: StructWithUse) { printf("StructWithUse(%i, (%f, %f), %i)\n", first_member, x, y, last_member); } @@ -104,7 +104,7 @@ main :: proc (args: [] cstr) { print_swu(swu2); } - test_polymorphic :: proc () { + test_polymorphic :: () { println("\n\nTesting a polymorphic struct."); PolyStruct :: struct (T: type_expr, R: type_expr) { @@ -123,7 +123,7 @@ main :: proc (args: [] cstr) { printf("PolyStruct(%f, %i)\n", ps2.t_data, ps2.r_data); } - test_polymorphic_with_defaults :: proc () { + test_polymorphic_with_defaults :: () { println("\n\nTesting a polymorphic struct with default values."); PolyStruct :: struct (T: type_expr, R: type_expr) { @@ -137,7 +137,7 @@ main :: proc (args: [] cstr) { printf("PolyStruct(%i, %f)\n", ps.t_data, ps.r_data); } - test_polymorphic_union_with_use :: proc () { + test_polymorphic_union_with_use :: () { println("\n\nTesting a polymorphic union with use."); PolyStruct :: struct (T: type_expr, R: type_expr) { @@ -155,7 +155,7 @@ main :: proc (args: [] cstr) { printf("%i, %d\n", ps.t_data, ps.r_data); } - test_union_with_use :: proc () { + test_union_with_use :: () { println("\n\nTesting a union with use."); Vec2 :: struct { @@ -177,7 +177,7 @@ main :: proc (args: [] cstr) { printf("Union(%s)\n", u.name); } - test_polymorphic_union :: proc () { + test_polymorphic_union :: () { println("\n\nTesting a polymorphic union."); PolyUnion :: struct (T: type_expr, R: type_expr) #union { diff --git a/tests/vararg_test.onyx b/tests/vararg_test.onyx index 9bc287e8..7751a254 100644 --- a/tests/vararg_test.onyx +++ b/tests/vararg_test.onyx @@ -4,12 +4,12 @@ package main use package core; -old_va_test :: proc (prefix: str, va: ..i32) { +old_va_test :: (prefix: str, va: ..i32) { println(prefix); for v: va do println(v); } -new_va_test :: proc (prefix: str, va: ...) { +new_va_test :: (prefix: str, va: ...) { println(prefix); for i: 0 .. va.count { @@ -19,7 +19,7 @@ new_va_test :: proc (prefix: str, va: ...) { } } -main :: proc (args: [] cstr) { +main :: (args: [] cstr) { new_va_test("foo", 1, 2, 3.0f, 5.0f); old_va_test("bar", 1);