diff --git a/_run_all_tests.jai b/_run_all_tests.jai index df80cc6..78d46aa 100644 --- a/_run_all_tests.jai +++ b/_run_all_tests.jai @@ -5,16 +5,14 @@ // @note(judah): we use relative imports here because that'll // print cleaner file locations. - #import,file "./array/module.jai"(RUN_TESTS = true); - #import,file "./encoding/module.jai"(RUN_TESTS = true); - #import,file "./hash/module.jai"(RUN_TESTS = true); - #import,file "./memory/module.jai"(RUN_TESTS = true); - #import,file "./meta/module.jai"(RUN_TESTS = true); - #import,file "./platform/module.jai"(RUN_TESTS = true); - #import,file "./kv/module.jai"(RUN_TESTS = true); + #import,file "./array/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); + #import,file "./encoding/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); + #import,file "./hash/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); + #import,file "./memory/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); + #import,file "./meta/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); + #import,file "./platform/module.jai"(RUN_TESTS_AT_COMPILE_TIME = true); - rmath :: #import,file "./math/module.jai"(.radians, RUN_TESTS = true); - dmath :: #import,file "./math/module.jai"(.degrees, RUN_TESTS = true); - tmath :: #import,file "./math/module.jai"(.turns, RUN_TESTS = true); + rmath :: #import,file "./math/module.jai"(.radians, RUN_TESTS_AT_COMPILE_TIME = true); + dmath :: #import,file "./math/module.jai"(.degrees, RUN_TESTS_AT_COMPILE_TIME = true); + tmath :: #import,file "./math/module.jai"(.turns, RUN_TESTS_AT_COMPILE_TIME = true); } - diff --git a/array/bytes.jai b/array/bytes.jai new file mode 100644 index 0000000..de263cc --- /dev/null +++ b/array/bytes.jai @@ -0,0 +1,44 @@ +to_string :: (c: *u8, count := 1) -> string #expand { + return string.{ data = c, count = count }; +} + +Index_Mode :: enum { + from_left; + from_right; +} + +find_index :: (b: []u8, c: u8, $mode := Index_Mode.from_left) -> bool, int { + #if #complete mode == { + case .from_left; + for b if it == c { + return true, it_index; + } + + case .from_right; + i := b.count - 1; + while i >= 0 { + if b[i] == c { + return true, i; + } + + i -= 1; + } + } + + return false, -1; +} + +find_index :: inline (s: string, c: u8, $mode := Index_Mode.from_left) -> bool, int { + ok, idx := find_index(s.([]u8), c, mode); + return ok, idx; +} + +#scope_file; + +// ---------------------------------------------------------- +// TESTS +// ---------------------------------------------------------- + +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; +} diff --git a/array/dynamic_array.jai b/array/dynamic.jai similarity index 96% rename from array/dynamic_array.jai rename to array/dynamic.jai index 07051ce..0c26afa 100644 --- a/array/dynamic_array.jai +++ b/array/dynamic.jai @@ -57,11 +57,14 @@ find_pointer :: (a: *[..]$T, $predicate: (T) -> bool) -> *T, bool, int { #scope_file; -mem :: #import "jc/memory"; +mem :: #import "jc/memory"; meta :: #import "jc/meta"; + basic :: #import "Basic"; // @future -#if RUN_TESTS #run { +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + test.run("remove_ordered", t => { a: [..]int; append(*a, 10, 20, 30); diff --git a/array/module.jai b/array/module.jai index cf5aacf..52376a3 100644 --- a/array/module.jai +++ b/array/module.jai @@ -1,11 +1,13 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); -#load "static_array.jai"; -#load "stable_array.jai"; -#load "dynamic_array.jai"; +#load "bytes.jai"; +#load "dynamic.jai"; +#load "stable.jai"; +#load "static.jai"; +#load "xar.jai"; #scope_module; -#if RUN_TESTS { - test :: #import "jc/test"; +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; } diff --git a/array/stable_array.jai b/array/stable.jai similarity index 98% rename from array/stable_array.jai rename to array/stable.jai index 6b920b4..7957063 100644 --- a/array/stable_array.jai +++ b/array/stable.jai @@ -127,8 +127,8 @@ create_chunk :: (a: *Stable_Array) -> *a.Chunk { // TESTS // ---------------------------------------------------------- -#if RUN_TESTS #run { - test :: #import "jc/test"; +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; test.run("basic operations", t => { a: Stable_Array(int, 4); diff --git a/array/static_array.jai b/array/static.jai similarity index 98% rename from array/static_array.jai rename to array/static.jai index 05a07f9..edebfab 100644 --- a/array/static_array.jai +++ b/array/static.jai @@ -108,8 +108,8 @@ basic :: #import "Basic"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS #run { - test :: #import "jc/test"; +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; test.run("basic operations", (t) => { a: Static_Array(10, int); diff --git a/array/xar.jai b/array/xar.jai new file mode 100644 index 0000000..e834805 --- /dev/null +++ b/array/xar.jai @@ -0,0 +1,9 @@ +#scope_file; + +// ---------------------------------------------------------- +// TESTS +// ---------------------------------------------------------- + +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; +} diff --git a/bytes/module.jai b/bytes/module.jai deleted file mode 100644 index 4c3db65..0000000 --- a/bytes/module.jai +++ /dev/null @@ -1,9 +0,0 @@ -#module_parameters(RUN_TESTS := false); - -#load "buffer.jai"; - -#scope_module; - -#if RUN_TESTS { - test :: #import "jc/test"; -} diff --git a/encoding/base64.jai b/encoding/base64.jai index 4d9b2e4..741a0f4 100644 --- a/encoding/base64.jai +++ b/encoding/base64.jai @@ -164,7 +164,9 @@ strings :: #import "String"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS #run { +#if #exists(TESTS) #run { + test :: #import "jc/meta/test"; + test.run("encodes", (t) => { str :: "Hello, World"; diff --git a/encoding/module.jai b/encoding/module.jai index d8c7ed6..f555dba 100644 --- a/encoding/module.jai +++ b/encoding/module.jai @@ -1,11 +1,10 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); #load "base64.jai"; #load "json.jai"; - #scope_module; -#if RUN_TESTS { - test :: #import "jc/test"; +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; } diff --git a/thirdparty/hmm/HandmadeMath.h b/ext/hmm/HandmadeMath.h similarity index 100% rename from thirdparty/hmm/HandmadeMath.h rename to ext/hmm/HandmadeMath.h diff --git a/thirdparty/hmm/README b/ext/hmm/README similarity index 100% rename from thirdparty/hmm/README rename to ext/hmm/README diff --git a/thirdparty/hmm/examples/degrees.jai b/ext/hmm/examples/degrees.jai similarity index 100% rename from thirdparty/hmm/examples/degrees.jai rename to ext/hmm/examples/degrees.jai diff --git a/thirdparty/hmm/examples/radians.jai b/ext/hmm/examples/radians.jai similarity index 100% rename from thirdparty/hmm/examples/radians.jai rename to ext/hmm/examples/radians.jai diff --git a/thirdparty/hmm/examples/turns.jai b/ext/hmm/examples/turns.jai similarity index 100% rename from thirdparty/hmm/examples/turns.jai rename to ext/hmm/examples/turns.jai diff --git a/thirdparty/hmm/generate.jai b/ext/hmm/generate.jai similarity index 100% rename from thirdparty/hmm/generate.jai rename to ext/hmm/generate.jai diff --git a/thirdparty/hmm/hmm_nosimd.jai b/ext/hmm/hmm_nosimd.jai similarity index 100% rename from thirdparty/hmm/hmm_nosimd.jai rename to ext/hmm/hmm_nosimd.jai diff --git a/thirdparty/hmm/hmm_simd.jai b/ext/hmm/hmm_simd.jai similarity index 100% rename from thirdparty/hmm/hmm_simd.jai rename to ext/hmm/hmm_simd.jai diff --git a/thirdparty/hmm/linux/.need-to-run-generate b/ext/hmm/linux/.need-to-run-generate similarity index 100% rename from thirdparty/hmm/linux/.need-to-run-generate rename to ext/hmm/linux/.need-to-run-generate diff --git a/thirdparty/hmm/mac/hmm_degrees_nosimd.a b/ext/hmm/mac/hmm_degrees_nosimd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_degrees_nosimd.a rename to ext/hmm/mac/hmm_degrees_nosimd.a diff --git a/thirdparty/hmm/mac/hmm_degrees_nosimd.dylib b/ext/hmm/mac/hmm_degrees_nosimd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_degrees_nosimd.dylib rename to ext/hmm/mac/hmm_degrees_nosimd.dylib diff --git a/thirdparty/hmm/mac/hmm_degrees_simd.a b/ext/hmm/mac/hmm_degrees_simd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_degrees_simd.a rename to ext/hmm/mac/hmm_degrees_simd.a diff --git a/thirdparty/hmm/mac/hmm_degrees_simd.dylib b/ext/hmm/mac/hmm_degrees_simd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_degrees_simd.dylib rename to ext/hmm/mac/hmm_degrees_simd.dylib diff --git a/thirdparty/hmm/mac/hmm_radians_nosimd.a b/ext/hmm/mac/hmm_radians_nosimd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_radians_nosimd.a rename to ext/hmm/mac/hmm_radians_nosimd.a diff --git a/thirdparty/hmm/mac/hmm_radians_nosimd.dylib b/ext/hmm/mac/hmm_radians_nosimd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_radians_nosimd.dylib rename to ext/hmm/mac/hmm_radians_nosimd.dylib diff --git a/thirdparty/hmm/mac/hmm_radians_simd.a b/ext/hmm/mac/hmm_radians_simd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_radians_simd.a rename to ext/hmm/mac/hmm_radians_simd.a diff --git a/thirdparty/hmm/mac/hmm_radians_simd.dylib b/ext/hmm/mac/hmm_radians_simd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_radians_simd.dylib rename to ext/hmm/mac/hmm_radians_simd.dylib diff --git a/thirdparty/hmm/mac/hmm_turns_nosimd.a b/ext/hmm/mac/hmm_turns_nosimd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_turns_nosimd.a rename to ext/hmm/mac/hmm_turns_nosimd.a diff --git a/thirdparty/hmm/mac/hmm_turns_nosimd.dylib b/ext/hmm/mac/hmm_turns_nosimd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_turns_nosimd.dylib rename to ext/hmm/mac/hmm_turns_nosimd.dylib diff --git a/thirdparty/hmm/mac/hmm_turns_simd.a b/ext/hmm/mac/hmm_turns_simd.a similarity index 100% rename from thirdparty/hmm/mac/hmm_turns_simd.a rename to ext/hmm/mac/hmm_turns_simd.a diff --git a/thirdparty/hmm/mac/hmm_turns_simd.dylib b/ext/hmm/mac/hmm_turns_simd.dylib similarity index 100% rename from thirdparty/hmm/mac/hmm_turns_simd.dylib rename to ext/hmm/mac/hmm_turns_simd.dylib diff --git a/thirdparty/hmm/module.jai b/ext/hmm/module.jai similarity index 100% rename from thirdparty/hmm/module.jai rename to ext/hmm/module.jai diff --git a/thirdparty/hmm/win/.need-to-run-generate b/ext/hmm/win/.need-to-run-generate similarity index 100% rename from thirdparty/hmm/win/.need-to-run-generate rename to ext/hmm/win/.need-to-run-generate diff --git a/thirdparty/luajit/examples/000-it-works.jai b/ext/luajit/examples/000-it-works.jai similarity index 100% rename from thirdparty/luajit/examples/000-it-works.jai rename to ext/luajit/examples/000-it-works.jai diff --git a/thirdparty/luajit/generate.jai b/ext/luajit/generate.jai similarity index 100% rename from thirdparty/luajit/generate.jai rename to ext/luajit/generate.jai diff --git a/thirdparty/luajit/lib/lauxlib.h b/ext/luajit/lib/lauxlib.h similarity index 100% rename from thirdparty/luajit/lib/lauxlib.h rename to ext/luajit/lib/lauxlib.h diff --git a/thirdparty/luajit/lib/lua.h b/ext/luajit/lib/lua.h similarity index 100% rename from thirdparty/luajit/lib/lua.h rename to ext/luajit/lib/lua.h diff --git a/thirdparty/luajit/lib/luaconf.h b/ext/luajit/lib/luaconf.h similarity index 100% rename from thirdparty/luajit/lib/luaconf.h rename to ext/luajit/lib/luaconf.h diff --git a/thirdparty/luajit/lib/luajit.h b/ext/luajit/lib/luajit.h similarity index 100% rename from thirdparty/luajit/lib/luajit.h rename to ext/luajit/lib/luajit.h diff --git a/thirdparty/luajit/lib/lualib.h b/ext/luajit/lib/lualib.h similarity index 100% rename from thirdparty/luajit/lib/lualib.h rename to ext/luajit/lib/lualib.h diff --git a/thirdparty/luajit/luajit.jai b/ext/luajit/luajit.jai similarity index 100% rename from thirdparty/luajit/luajit.jai rename to ext/luajit/luajit.jai diff --git a/thirdparty/luajit/mac/luajit-5.1.a b/ext/luajit/mac/luajit-5.1.a similarity index 100% rename from thirdparty/luajit/mac/luajit-5.1.a rename to ext/luajit/mac/luajit-5.1.a diff --git a/thirdparty/luajit/mac/luajit-5.1.dylib b/ext/luajit/mac/luajit-5.1.dylib similarity index 100% rename from thirdparty/luajit/mac/luajit-5.1.dylib rename to ext/luajit/mac/luajit-5.1.dylib diff --git a/thirdparty/luajit/module.jai b/ext/luajit/module.jai similarity index 100% rename from thirdparty/luajit/module.jai rename to ext/luajit/module.jai diff --git a/thirdparty/luajit/x/module.jai b/ext/luajit/x/module.jai similarity index 100% rename from thirdparty/luajit/x/module.jai rename to ext/luajit/x/module.jai diff --git a/thirdparty/raylib/README b/ext/raylib/README similarity index 100% rename from thirdparty/raylib/README rename to ext/raylib/README diff --git a/thirdparty/raylib/examples/basic-window.jai b/ext/raylib/examples/basic-window.jai similarity index 100% rename from thirdparty/raylib/examples/basic-window.jai rename to ext/raylib/examples/basic-window.jai diff --git a/thirdparty/raylib/examples/input-keys.jai b/ext/raylib/examples/input-keys.jai similarity index 100% rename from thirdparty/raylib/examples/input-keys.jai rename to ext/raylib/examples/input-keys.jai diff --git a/thirdparty/raylib/generate.jai b/ext/raylib/generate.jai similarity index 100% rename from thirdparty/raylib/generate.jai rename to ext/raylib/generate.jai diff --git a/thirdparty/raylib/lib/raylib.h b/ext/raylib/lib/raylib.h similarity index 100% rename from thirdparty/raylib/lib/raylib.h rename to ext/raylib/lib/raylib.h diff --git a/thirdparty/raylib/lib/raymath.h b/ext/raylib/lib/raymath.h similarity index 100% rename from thirdparty/raylib/lib/raymath.h rename to ext/raylib/lib/raymath.h diff --git a/thirdparty/raylib/lib/rlgl.h b/ext/raylib/lib/rlgl.h similarity index 100% rename from thirdparty/raylib/lib/rlgl.h rename to ext/raylib/lib/rlgl.h diff --git a/thirdparty/raylib/linux/libraygui.a b/ext/raylib/linux/libraygui.a similarity index 100% rename from thirdparty/raylib/linux/libraygui.a rename to ext/raylib/linux/libraygui.a diff --git a/thirdparty/raylib/linux/libraygui.so b/ext/raylib/linux/libraygui.so similarity index 100% rename from thirdparty/raylib/linux/libraygui.so rename to ext/raylib/linux/libraygui.so diff --git a/thirdparty/raylib/linux/libraylib.a b/ext/raylib/linux/libraylib.a similarity index 100% rename from thirdparty/raylib/linux/libraylib.a rename to ext/raylib/linux/libraylib.a diff --git a/thirdparty/raylib/linux/libraylib.so b/ext/raylib/linux/libraylib.so similarity index 100% rename from thirdparty/raylib/linux/libraylib.so rename to ext/raylib/linux/libraylib.so diff --git a/thirdparty/raylib/linux/libraylib.so.5.5.0 b/ext/raylib/linux/libraylib.so.5.5.0 similarity index 100% rename from thirdparty/raylib/linux/libraylib.so.5.5.0 rename to ext/raylib/linux/libraylib.so.5.5.0 diff --git a/thirdparty/raylib/linux/libraylib.so.550 b/ext/raylib/linux/libraylib.so.550 similarity index 100% rename from thirdparty/raylib/linux/libraylib.so.550 rename to ext/raylib/linux/libraylib.so.550 diff --git a/thirdparty/raylib/mac/libraygui.a b/ext/raylib/mac/libraygui.a similarity index 100% rename from thirdparty/raylib/mac/libraygui.a rename to ext/raylib/mac/libraygui.a diff --git a/thirdparty/raylib/mac/libraygui.dylib b/ext/raylib/mac/libraygui.dylib similarity index 100% rename from thirdparty/raylib/mac/libraygui.dylib rename to ext/raylib/mac/libraygui.dylib diff --git a/thirdparty/raylib/mac/libraylib.5.5.0.dylib b/ext/raylib/mac/libraylib.5.5.0.dylib similarity index 100% rename from thirdparty/raylib/mac/libraylib.5.5.0.dylib rename to ext/raylib/mac/libraylib.5.5.0.dylib diff --git a/thirdparty/raylib/mac/libraylib.550.dylib b/ext/raylib/mac/libraylib.550.dylib similarity index 100% rename from thirdparty/raylib/mac/libraylib.550.dylib rename to ext/raylib/mac/libraylib.550.dylib diff --git a/thirdparty/raylib/mac/libraylib.a b/ext/raylib/mac/libraylib.a similarity index 100% rename from thirdparty/raylib/mac/libraylib.a rename to ext/raylib/mac/libraylib.a diff --git a/thirdparty/raylib/mac/libraylib.dylib b/ext/raylib/mac/libraylib.dylib similarity index 100% rename from thirdparty/raylib/mac/libraylib.dylib rename to ext/raylib/mac/libraylib.dylib diff --git a/thirdparty/raylib/module.jai b/ext/raylib/module.jai similarity index 100% rename from thirdparty/raylib/module.jai rename to ext/raylib/module.jai diff --git a/thirdparty/raylib/raylib.jai b/ext/raylib/raylib.jai similarity index 100% rename from thirdparty/raylib/raylib.jai rename to ext/raylib/raylib.jai diff --git a/thirdparty/raylib/rlgl/module.jai b/ext/raylib/rlgl/module.jai similarity index 100% rename from thirdparty/raylib/rlgl/module.jai rename to ext/raylib/rlgl/module.jai diff --git a/thirdparty/raylib/rlgl/rlgl.jai b/ext/raylib/rlgl/rlgl.jai similarity index 100% rename from thirdparty/raylib/rlgl/rlgl.jai rename to ext/raylib/rlgl/rlgl.jai diff --git a/thirdparty/raylib/wasm/libraygui.a b/ext/raylib/wasm/libraygui.a similarity index 100% rename from thirdparty/raylib/wasm/libraygui.a rename to ext/raylib/wasm/libraygui.a diff --git a/thirdparty/raylib/wasm/libraylib.a b/ext/raylib/wasm/libraylib.a similarity index 100% rename from thirdparty/raylib/wasm/libraylib.a rename to ext/raylib/wasm/libraylib.a diff --git a/thirdparty/raylib/win/libraygui.dll b/ext/raylib/win/libraygui.dll similarity index 100% rename from thirdparty/raylib/win/libraygui.dll rename to ext/raylib/win/libraygui.dll diff --git a/thirdparty/raylib/win/libraygui.lib b/ext/raylib/win/libraygui.lib similarity index 100% rename from thirdparty/raylib/win/libraygui.lib rename to ext/raylib/win/libraygui.lib diff --git a/thirdparty/raylib/win/librayguidll.lib b/ext/raylib/win/librayguidll.lib similarity index 100% rename from thirdparty/raylib/win/librayguidll.lib rename to ext/raylib/win/librayguidll.lib diff --git a/thirdparty/raylib/win/libraylib.dll b/ext/raylib/win/libraylib.dll similarity index 100% rename from thirdparty/raylib/win/libraylib.dll rename to ext/raylib/win/libraylib.dll diff --git a/thirdparty/raylib/win/libraylib.lib b/ext/raylib/win/libraylib.lib similarity index 100% rename from thirdparty/raylib/win/libraylib.lib rename to ext/raylib/win/libraylib.lib diff --git a/thirdparty/raylib/win/libraylibdll.lib b/ext/raylib/win/libraylibdll.lib similarity index 100% rename from thirdparty/raylib/win/libraylibdll.lib rename to ext/raylib/win/libraylibdll.lib diff --git a/thirdparty/remotery/examples/it-works.jai b/ext/remotery/examples/it-works.jai similarity index 100% rename from thirdparty/remotery/examples/it-works.jai rename to ext/remotery/examples/it-works.jai diff --git a/thirdparty/remotery/generate.jai b/ext/remotery/generate.jai similarity index 100% rename from thirdparty/remotery/generate.jai rename to ext/remotery/generate.jai diff --git a/thirdparty/remotery/lib/Remotery.c b/ext/remotery/lib/Remotery.c similarity index 100% rename from thirdparty/remotery/lib/Remotery.c rename to ext/remotery/lib/Remotery.c diff --git a/thirdparty/remotery/lib/Remotery.h b/ext/remotery/lib/Remotery.h similarity index 100% rename from thirdparty/remotery/lib/Remotery.h rename to ext/remotery/lib/Remotery.h diff --git a/thirdparty/remotery/lib/RemoteryMetal.mm b/ext/remotery/lib/RemoteryMetal.mm similarity index 100% rename from thirdparty/remotery/lib/RemoteryMetal.mm rename to ext/remotery/lib/RemoteryMetal.mm diff --git a/thirdparty/remotery/mac/remotery.a b/ext/remotery/mac/remotery.a similarity index 100% rename from thirdparty/remotery/mac/remotery.a rename to ext/remotery/mac/remotery.a diff --git a/thirdparty/remotery/mac/remotery.dylib b/ext/remotery/mac/remotery.dylib similarity index 100% rename from thirdparty/remotery/mac/remotery.dylib rename to ext/remotery/mac/remotery.dylib diff --git a/thirdparty/remotery/module.jai b/ext/remotery/module.jai similarity index 100% rename from thirdparty/remotery/module.jai rename to ext/remotery/module.jai diff --git a/thirdparty/remotery/remotery.jai b/ext/remotery/remotery.jai similarity index 100% rename from thirdparty/remotery/remotery.jai rename to ext/remotery/remotery.jai diff --git a/thirdparty/remotery/vis/Code/Console.js b/ext/remotery/vis/Code/Console.js similarity index 100% rename from thirdparty/remotery/vis/Code/Console.js rename to ext/remotery/vis/Code/Console.js diff --git a/thirdparty/remotery/vis/Code/DataViewReader.js b/ext/remotery/vis/Code/DataViewReader.js similarity index 100% rename from thirdparty/remotery/vis/Code/DataViewReader.js rename to ext/remotery/vis/Code/DataViewReader.js diff --git a/thirdparty/remotery/vis/Code/GLCanvas.js b/ext/remotery/vis/Code/GLCanvas.js similarity index 100% rename from thirdparty/remotery/vis/Code/GLCanvas.js rename to ext/remotery/vis/Code/GLCanvas.js diff --git a/thirdparty/remotery/vis/Code/GridWindow.js b/ext/remotery/vis/Code/GridWindow.js similarity index 100% rename from thirdparty/remotery/vis/Code/GridWindow.js rename to ext/remotery/vis/Code/GridWindow.js diff --git a/thirdparty/remotery/vis/Code/MouseInteraction.js b/ext/remotery/vis/Code/MouseInteraction.js similarity index 100% rename from thirdparty/remotery/vis/Code/MouseInteraction.js rename to ext/remotery/vis/Code/MouseInteraction.js diff --git a/thirdparty/remotery/vis/Code/NameMap.js b/ext/remotery/vis/Code/NameMap.js similarity index 100% rename from thirdparty/remotery/vis/Code/NameMap.js rename to ext/remotery/vis/Code/NameMap.js diff --git a/thirdparty/remotery/vis/Code/PixelTimeRange.js b/ext/remotery/vis/Code/PixelTimeRange.js similarity index 100% rename from thirdparty/remotery/vis/Code/PixelTimeRange.js rename to ext/remotery/vis/Code/PixelTimeRange.js diff --git a/thirdparty/remotery/vis/Code/Remotery.js b/ext/remotery/vis/Code/Remotery.js similarity index 100% rename from thirdparty/remotery/vis/Code/Remotery.js rename to ext/remotery/vis/Code/Remotery.js diff --git a/thirdparty/remotery/vis/Code/SampleGlobals.js b/ext/remotery/vis/Code/SampleGlobals.js similarity index 100% rename from thirdparty/remotery/vis/Code/SampleGlobals.js rename to ext/remotery/vis/Code/SampleGlobals.js diff --git a/thirdparty/remotery/vis/Code/Shaders/Grid.js b/ext/remotery/vis/Code/Shaders/Grid.js similarity index 100% rename from thirdparty/remotery/vis/Code/Shaders/Grid.js rename to ext/remotery/vis/Code/Shaders/Grid.js diff --git a/thirdparty/remotery/vis/Code/Shaders/Shared.js b/ext/remotery/vis/Code/Shaders/Shared.js similarity index 100% rename from thirdparty/remotery/vis/Code/Shaders/Shared.js rename to ext/remotery/vis/Code/Shaders/Shared.js diff --git a/thirdparty/remotery/vis/Code/Shaders/Timeline.js b/ext/remotery/vis/Code/Shaders/Timeline.js similarity index 100% rename from thirdparty/remotery/vis/Code/Shaders/Timeline.js rename to ext/remotery/vis/Code/Shaders/Timeline.js diff --git a/thirdparty/remotery/vis/Code/Shaders/Window.js b/ext/remotery/vis/Code/Shaders/Window.js similarity index 100% rename from thirdparty/remotery/vis/Code/Shaders/Window.js rename to ext/remotery/vis/Code/Shaders/Window.js diff --git a/thirdparty/remotery/vis/Code/ThreadFrame.js b/ext/remotery/vis/Code/ThreadFrame.js similarity index 100% rename from thirdparty/remotery/vis/Code/ThreadFrame.js rename to ext/remotery/vis/Code/ThreadFrame.js diff --git a/thirdparty/remotery/vis/Code/TimelineMarkers.js b/ext/remotery/vis/Code/TimelineMarkers.js similarity index 100% rename from thirdparty/remotery/vis/Code/TimelineMarkers.js rename to ext/remotery/vis/Code/TimelineMarkers.js diff --git a/thirdparty/remotery/vis/Code/TimelineRow.js b/ext/remotery/vis/Code/TimelineRow.js similarity index 100% rename from thirdparty/remotery/vis/Code/TimelineRow.js rename to ext/remotery/vis/Code/TimelineRow.js diff --git a/thirdparty/remotery/vis/Code/TimelineWindow.js b/ext/remotery/vis/Code/TimelineWindow.js similarity index 100% rename from thirdparty/remotery/vis/Code/TimelineWindow.js rename to ext/remotery/vis/Code/TimelineWindow.js diff --git a/thirdparty/remotery/vis/Code/TitleWindow.js b/ext/remotery/vis/Code/TitleWindow.js similarity index 100% rename from thirdparty/remotery/vis/Code/TitleWindow.js rename to ext/remotery/vis/Code/TitleWindow.js diff --git a/thirdparty/remotery/vis/Code/TraceDrop.js b/ext/remotery/vis/Code/TraceDrop.js similarity index 100% rename from thirdparty/remotery/vis/Code/TraceDrop.js rename to ext/remotery/vis/Code/TraceDrop.js diff --git a/thirdparty/remotery/vis/Code/WebGL.js b/ext/remotery/vis/Code/WebGL.js similarity index 100% rename from thirdparty/remotery/vis/Code/WebGL.js rename to ext/remotery/vis/Code/WebGL.js diff --git a/thirdparty/remotery/vis/Code/WebGLFont.js b/ext/remotery/vis/Code/WebGLFont.js similarity index 100% rename from thirdparty/remotery/vis/Code/WebGLFont.js rename to ext/remotery/vis/Code/WebGLFont.js diff --git a/thirdparty/remotery/vis/Code/WebSocketConnection.js b/ext/remotery/vis/Code/WebSocketConnection.js similarity index 100% rename from thirdparty/remotery/vis/Code/WebSocketConnection.js rename to ext/remotery/vis/Code/WebSocketConnection.js diff --git a/thirdparty/remotery/vis/Styles/Fonts/FiraCode/FiraCode-Regular.ttf b/ext/remotery/vis/Styles/Fonts/FiraCode/FiraCode-Regular.ttf similarity index 100% rename from thirdparty/remotery/vis/Styles/Fonts/FiraCode/FiraCode-Regular.ttf rename to ext/remotery/vis/Styles/Fonts/FiraCode/FiraCode-Regular.ttf diff --git a/thirdparty/remotery/vis/Styles/Fonts/FiraCode/LICENSE b/ext/remotery/vis/Styles/Fonts/FiraCode/LICENSE similarity index 100% rename from thirdparty/remotery/vis/Styles/Fonts/FiraCode/LICENSE rename to ext/remotery/vis/Styles/Fonts/FiraCode/LICENSE diff --git a/thirdparty/remotery/vis/Styles/Remotery.css b/ext/remotery/vis/Styles/Remotery.css similarity index 100% rename from thirdparty/remotery/vis/Styles/Remotery.css rename to ext/remotery/vis/Styles/Remotery.css diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Animation.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Animation.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Animation.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Animation.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Bind.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Bind.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Bind.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Bind.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Convert.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Convert.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Convert.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Convert.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Core.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Core.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Core.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Core.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/DOM.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/DOM.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/DOM.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/DOM.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Keyboard.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Keyboard.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Keyboard.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Keyboard.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/LocalStore.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/LocalStore.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/LocalStore.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/LocalStore.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Mouse.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/Mouse.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/Mouse.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/Mouse.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/Core/Code/MurmurHash3.js b/ext/remotery/vis/extern/BrowserLib/Core/Code/MurmurHash3.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/Core/Code/MurmurHash3.js rename to ext/remotery/vis/extern/BrowserLib/Core/Code/MurmurHash3.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Button.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Button.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Button.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Button.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/ComboBox.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/ComboBox.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/ComboBox.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/ComboBox.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Container.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Container.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Container.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Container.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/EditBox.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/EditBox.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/EditBox.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/EditBox.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Grid.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Grid.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Grid.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Grid.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Label.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Label.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Label.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Label.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Treeview.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Treeview.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Treeview.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Treeview.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/TreeviewItem.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/TreeviewItem.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/TreeviewItem.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/TreeviewItem.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Window.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Window.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/Window.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/Window.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/WindowManager.js b/ext/remotery/vis/extern/BrowserLib/WindowManager/Code/WindowManager.js similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Code/WindowManager.js rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Code/WindowManager.js diff --git a/thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Styles/WindowManager.css b/ext/remotery/vis/extern/BrowserLib/WindowManager/Styles/WindowManager.css similarity index 100% rename from thirdparty/remotery/vis/extern/BrowserLib/WindowManager/Styles/WindowManager.css rename to ext/remotery/vis/extern/BrowserLib/WindowManager/Styles/WindowManager.css diff --git a/thirdparty/remotery/vis/index.html b/ext/remotery/vis/index.html similarity index 100% rename from thirdparty/remotery/vis/index.html rename to ext/remotery/vis/index.html diff --git a/hash/module.jai b/hash/module.jai index 86fa975..9dc1779 100644 --- a/hash/module.jai +++ b/hash/module.jai @@ -1,4 +1,11 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); #load "murmur.jai"; #load "xxhash.jai"; +#load "table.jai"; + +#scope_module; + +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; +} diff --git a/hash/table.jai b/hash/table.jai new file mode 100644 index 0000000..9bf5101 --- /dev/null +++ b/hash/table.jai @@ -0,0 +1,189 @@ +// Dead simple key-value pair type (aka. hash table or hash map) +Table :: struct(Key: Type, Value: Type) { + allocator: Allocator; + slots: [..]Slot; + free_slots: [..]int; + count: int; + + Slot :: struct { + hash: u32 = invalid_hash; + key: Key = ---; + value: Value = ---; + } + + hash_proc :: hash.murmur32; + invalid_hash :: (0x8000_dead).(u32); // @note(judah): I'm curious what values would hit this hash on accident + number_of_items_to_allocate_initially :: 16; // @note(judah): must be a power of two +} + +get :: (t: *Table, key: t.Key) -> t.Value, bool { + slot, ok := find_slot(t, get_hash(t, key)); + if !ok { + return mem.zero_of(t.Value), false; + } + + return slot.value, true; +} + +set :: (t: *Table, key: t.Key, value: t.Value) { + hash := get_hash(t, key); + slot, exists := find_slot(t, hash); + if !exists { + slot = create_or_reuse_slot(t); + slot.hash = hash; + } + + slot.key = key; + slot.value = value; +} + +exists :: (t: *Table, key: t.Key) -> bool { + _, exists := find_slot(t, get_hash(t, key)); + return exists; +} + +// @note(judah): we use 'delete' instead of 'remove' because it's a keyword... +delete :: (t: *Table, key: t.Key) -> t.Value, bool { + slot, ok, idx := find_slot(t, get_hash(t, key)); + if !ok return mem.zero_of(t.Value), false; + + last_value := slot.value; + mark_slot_for_reuse(t, idx); + + return last_value, true; +} + +reset :: (t: *Table) { + t.count = 0; + t.slots.count = 0; + t.free_slots.count = 0; +} + +for_expansion :: (t: *Table, body: Code, flags: For_Flags) #expand { + #assert (flags & .POINTER == 0) "cannot iterate by pointer"; + for <=(flags & .REVERSE == .REVERSE) slot: t.slots if slot.hash != t.invalid_hash { + `it := slot.value; + `it_index := slot.key; + #insert,scope(body)(break = break slot) body; + } +} + + +#scope_file; + +get_hash :: inline (t: *Table, key: t.Key) -> u32 { + hash := t.hash_proc(key); + basic.assert(hash != t.invalid_hash, "key % collided with invalid hash marker (%)", key, t.invalid_hash); + return hash; +} + +find_slot :: (t: *Table, hash: u32) -> *t.Slot, bool, int { + for * t.slots if it.hash == hash { + return it, true, it_index; + } + + return null, false, -1; +} + +create_or_reuse_slot :: (t: *Table) -> *t.Slot { + inline try_lazy_init(t); + + if t.free_slots.count > 0 { + slot_idx := t.free_slots[t.free_slots.count - 1]; + t.free_slots.count -= 1; + return *t.slots[slot_idx]; + } + + if t.slots.allocated == 0 { + array.resize(*t.slots, t.number_of_items_to_allocate_initially); + } + else if t.slots.count >= t.slots.allocated { + array.resize(*t.slots, mem.next_power_of_two(t.slots.allocated)); + } + + slot := array.append(*t.slots); + t.count = t.slots.count; + return slot; +} + +mark_slot_for_reuse :: (t: *Table, index: int) { + inline try_lazy_init(t); + + t.count -= 1; + t.slots[index] = .{ hash = t.invalid_hash }; + + array.append(*t.free_slots, index); +} + +try_lazy_init :: inline (t: *Table) { + mem.lazy_set_allocator(t); + mem.lazy_set_allocator(*t.slots); + mem.lazy_set_allocator(*t.free_slots); +} + +mem :: #import "jc/memory"; +array :: #import "jc/array"; +hash :: #import "jc/hash"; + +basic :: #import "Basic"; // @future + + +// ---------------------------------------------------------- +// TESTS +// ---------------------------------------------------------- + +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + + test.run("basic operations", t => { + ITERATIONS :: 64; + + values: Table(int, int); + for 0..ITERATIONS { + set(*values, it, it * it); + } + + for 0..ITERATIONS { + v, ok := get(*values, it); + test.expect(t, v == it * it); + } + + for 0..ITERATIONS if it % 2 == 0 { + _, ok := delete(*values, it); + test.expect(t, ok); + } + + for 0..ITERATIONS if it % 2 == 0 { + _, ok := get(*values, it); + test.expect(t, !ok); + } + }); + + test.run("free slots", t => { + values: Table(int, int); + + set(*values, 1, 100); + set(*values, 2, 200); + set(*values, 3, 300); + test.expect(t, values.count == 3); + test.expect(t, values.slots.allocated == values.number_of_items_to_allocate_initially); + + // deleting something that doesn't exist should do nothing + _, ok := delete(*values, 0); + test.expect(t, !ok); + test.expect(t, values.count == 3); + + delete(*values, 2); + test.expect(t, values.count == 2); + }); + + test.run("iteration", t => { + values: Table(int, int); + + for 0..10 set(*values, it, it * it); + test.expect(t, values.count == 11); + + for v, k: values test.expect(t, v == k * k); + for < v, k: values test.expect(t, v == k * k); + }); +} diff --git a/jc.jai b/jc.jai deleted file mode 120000 index 501958c..0000000 --- a/jc.jai +++ /dev/null @@ -1 +0,0 @@ -jc.jai/ \ No newline at end of file diff --git a/kv/module.jai b/kv/module.jai deleted file mode 100644 index 3a294b6..0000000 --- a/kv/module.jai +++ /dev/null @@ -1,193 +0,0 @@ -#module_parameters(RUN_TESTS := false); - -// Dead simple key-value pair type (aka. hash table or hash map) -Kv :: struct(Key: Type, Value: Type) { - allocator: Allocator; - slots: [..]Slot; - free_slots: [..]int; - count: int; - - Slot :: struct { - hash: u32 = invalid_hash; - key: Key = ---; - value: Value = ---; - } - - hash_proc :: hash.murmur32; - invalid_hash :: (0x8000_dead).(u32); // @note(judah): I'm curious what values would hit this hash on accident - number_of_items_to_allocate_initially :: 16; // @note(judah): must be a power of two -} - -get :: (kv: *Kv, key: kv.Key) -> kv.Value, bool { - slot, ok := find_slot(kv, get_hash(kv, key)); - if !ok { - return mem.zero_of(kv.Value), false; - } - - return slot.value, true; -} - -set :: (kv: *Kv, key: kv.Key, value: kv.Value) { - hash := get_hash(kv, key); - slot, exists := find_slot(kv, hash); - if !exists { - slot = create_or_reuse_slot(kv); - slot.hash = hash; - } - - slot.key = key; - slot.value = value; -} - -exists :: (kv: *Kv, key: kv.Key) -> bool { - _, exists := find_slot(kv, get_hash(kv, key)); - return exists; -} - -// @note(judah): we use 'delete' instead of 'remove' because it's a keyword... -delete :: (kv: *Kv, key: kv.Key) -> kv.Value, bool { - slot, ok, idx := find_slot(kv, get_hash(kv, key)); - if !ok return mem.zero_of(kv.Value), false; - - last_value := slot.value; - mark_slot_for_reuse(kv, idx); - - return last_value, true; -} - -reset :: (kv: *Kv) { - kv.count = 0; - kv.slots.count = 0; - kv.free_slots.count = 0; -} - -for_expansion :: (kv: *Kv, body: Code, flags: For_Flags) #expand { - #assert (flags & .POINTER == 0) "cannot iterate by pointer"; - for <=(flags & .REVERSE == .REVERSE) slot: kv.slots if slot.hash != kv.invalid_hash { - `it := slot.value; - `it_index := slot.key; - #insert,scope(body)(break = break slot) body; - } -} - - -#scope_file; - -get_hash :: inline (kv: *Kv, key: kv.Key) -> u32 { - hash := kv.hash_proc(key); - basic.assert(hash != kv.invalid_hash, "key % collided with invalid hash marker (%)", key, kv.invalid_hash); - return hash; -} - -find_slot :: (kv: *Kv, hash: u32) -> *kv.Slot, bool, int { - for * kv.slots if it.hash == hash { - return it, true, it_index; - } - - return null, false, -1; -} - -create_or_reuse_slot :: (kv: *Kv) -> *kv.Slot { - inline try_lazy_init(kv); - - if kv.free_slots.count > 0 { - slot_idx := kv.free_slots[kv.free_slots.count - 1]; - kv.free_slots.count -= 1; - return *kv.slots[slot_idx]; - } - - if kv.slots.allocated == 0 { - array.resize(*kv.slots, kv.number_of_items_to_allocate_initially); - } - else if kv.slots.count >= kv.slots.allocated { - array.resize(*kv.slots, mem.next_power_of_two(kv.slots.allocated)); - } - - slot := array.append(*kv.slots); - kv.count = kv.slots.count; - return slot; -} - -mark_slot_for_reuse :: (kv: *Kv, index: int) { - inline try_lazy_init(kv); - - kv.count -= 1; - kv.slots[index] = .{ hash = kv.invalid_hash }; - - array.append(*kv.free_slots, index); -} - -try_lazy_init :: inline (kv: *Kv) { - mem.lazy_set_allocator(kv); - mem.lazy_set_allocator(*kv.slots); - mem.lazy_set_allocator(*kv.free_slots); -} - -mem :: #import "jc/memory"; -array :: #import "jc/array"; -hash :: #import "jc/hash"; - -basic :: #import "Basic"; // @future - - -// ---------------------------------------------------------- -// TESTS -// ---------------------------------------------------------- - -#if RUN_TESTS { - test :: #import "jc/test"; - - #run { - test.run("basic operations", t => { - ITERATIONS :: 64; - - values: Kv(int, int); - for 0..ITERATIONS { - set(*values, it, it * it); - } - - for 0..ITERATIONS { - v, ok := get(*values, it); - test.expect(t, v == it * it); - } - - for 0..ITERATIONS if it % 2 == 0 { - _, ok := delete(*values, it); - test.expect(t, ok); - } - - for 0..ITERATIONS if it % 2 == 0 { - _, ok := get(*values, it); - test.expect(t, !ok); - } - }); - - test.run("free slots", t => { - values: Kv(int, int); - - set(*values, 1, 100); - set(*values, 2, 200); - set(*values, 3, 300); - test.expect(t, values.count == 3); - test.expect(t, values.slots.allocated == values.number_of_items_to_allocate_initially); - - // deleting something that doesn't exist should do nothing - _, ok := delete(*values, 0); - test.expect(t, !ok); - test.expect(t, values.count == 3); - - delete(*values, 2); - test.expect(t, values.count == 2); - }); - - test.run("iteration", t => { - values: Kv(int, int); - - for 0..10 set(*values, it, it * it); - test.expect(t, values.count == 11); - - for v, k: values test.expect(t, v == k * k); - for < v, k: values test.expect(t, v == k * k); - }); - } -} diff --git a/math/common.jai b/math/common.jai index b610979..33e938d 100644 --- a/math/common.jai +++ b/math/common.jai @@ -2,18 +2,21 @@ PI :: 3.1415926; TAU :: 6.2831853; -#if UNITS == .turns { - to_rad :: turn_to_rad; +#if #exists(UNITS) #if UNITS == { + case .turns; + to_rad :: turn_to_rad; + from_rad :: rad_to_turn; + case .radians; + to_rad :: rad_to_rad; + from_rad :: rad_to_rad; + case .degrees; + to_rad :: deg_to_rad; + from_rad :: rad_to_deg; +} +else { + to_rad :: turn_to_rad; from_rad :: rad_to_turn; } -else #if UNITS == .radians { - to_rad :: rad_to_rad; - from_rad :: rad_to_rad; -} -else #if UNITS == .degrees { - to_rad :: deg_to_rad; - from_rad :: rad_to_deg; -} turn_to_rad :: (turns: float64) -> float #expand #no_debug { CONSTANT :float64: PI*2.0; diff --git a/math/mat.jai b/math/mat.jai index 99b2cf2..a273055 100644 --- a/math/mat.jai +++ b/math/mat.jai @@ -404,7 +404,9 @@ inverse :: (m: Mat4) -> Mat4 { #scope_file; -#if RUN_TESTS #run { +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + test.run(basic.tprint("%: Mat2", UNITS), t => { { identity := m2_identity; diff --git a/math/module.jai b/math/module.jai index 8ccdc92..fc0d757 100644 --- a/math/module.jai +++ b/math/module.jai @@ -2,7 +2,7 @@ UNITS: enum { radians; degrees; turns; } = .turns, RECT_TYPE: Type = float, // RECT_METHOD: enum { dimension; absolute; } = absolute, // Note(Jesse): Maybe at a later point we can do this - RUN_TESTS := false + RUN_TESTS_AT_COMPILE_TIME := false ); #assert meta.type_is_scalar(RECT_TYPE); @@ -31,11 +31,11 @@ F64_Min, F64_Max :: #run meta.lo_for(float64), #run meta.hi_for(float64); #scope_module; meta :: #import "jc/meta"; -math :: #import "Math"; // @future +math :: #import "Math"; // @future basic :: #import "Basic"; // @future -#if RUN_TESTS { - test :: #import "jc/test"; +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; } // @temp(judah): move these to the right files diff --git a/math/shape.jai b/math/shape.jai index 9b51a1d..2d488df 100644 --- a/math/shape.jai +++ b/math/shape.jai @@ -1,4 +1,3 @@ - Rect :: #type,distinct Vec(4, RECT_TYPE); Circle :: struct { @@ -154,7 +153,5 @@ get_center :: (r: Rect) -> Vec2 { basic :: #import "Basic"; -#if RUN_TESTS #run,stallable { - test.run(basic.tprint("%: Vec2", UNITS), t => { - }); +#if #exists(RUN_TESTS) #run { } diff --git a/math/vec.jai b/math/vec.jai index a12384c..8657688 100644 --- a/math/vec.jai +++ b/math/vec.jai @@ -653,7 +653,9 @@ cross :: (a: Vec3, b: Vec3) -> Vec3 { #scope_file -#if RUN_TESTS #run,stallable { +#if #exists(RUN_TESTS) #run,stallable { + test :: #import "jc/meta/test"; + test.run(basic.tprint("%: Vec2", UNITS), t => { { a: Vec2 = v2f(0.0, 1.0); diff --git a/memory/allocators.jai b/memory/allocators.jai index 244ca39..dea88df 100644 --- a/memory/allocators.jai +++ b/memory/allocators.jai @@ -112,24 +112,22 @@ meta :: #import "jc/meta"; // TESTS // ---------------------------------------------------------- -#if RUN_TESTS { - test :: #import "jc/test"; +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; - #run { - test.run("arena:basic", t => { - memory := request_memory(1 * Kilobyte); - defer release_memory(memory); + test.run("arena:basic", t => { + memory := request_memory(1 * Kilobyte); + defer release_memory(memory); - arena: Arena; - init_arena(*arena, memory, 1 * Kilobyte); + arena: Arena; + init_arena(*arena, memory, 1 * Kilobyte); - context.allocator = make_arena_allocator(*arena); - save_point := allocator_save(); + context.allocator = make_arena_allocator(*arena); + save_point := allocator_save(); - i := request_memory(int); - basic.assert(i != null); - basic.assert(arena.offset == size_of(int)); - allocator_restore(save_point); - }); - } + i := request_memory(int); + basic.assert(i != null); + basic.assert(arena.offset == size_of(int)); + allocator_restore(save_point); + }); } diff --git a/bytes/buffer.jai b/memory/buffer.jai similarity index 87% rename from bytes/buffer.jai rename to memory/buffer.jai index 96b5375..60b0167 100644 --- a/bytes/buffer.jai +++ b/memory/buffer.jai @@ -6,7 +6,7 @@ Buffer :: struct { } append :: inline (buf: *Buffer, ptr: *void, count: int) { - inline meta.lazy_set_allocator(buf); + inline mem.lazy_set_allocator(buf); free_space := ensure_buffer_has_room(buf, count); memcpy(free_space, ptr, count); @@ -28,6 +28,7 @@ reset :: inline (buf: *Buffer) { #scope_file; array :: #import "jc/array"; +mem :: #import "jc/memory"; meta :: #import "jc/meta"; ensure_buffer_has_room :: (buf: *Buffer, count: int) -> *u8 { @@ -41,7 +42,9 @@ ensure_buffer_has_room :: (buf: *Buffer, count: int) -> *u8 { return ptr; } -#if RUN_TESTS #run { +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + test.run("basic operations", t => { buf: Buffer; }); diff --git a/memory/module.jai b/memory/module.jai index a31aa12..bc00856 100644 --- a/memory/module.jai +++ b/memory/module.jai @@ -1,4 +1,4 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); Kilobyte :: 1024; Megabyte :: 1024 * Kilobyte; @@ -174,6 +174,12 @@ lazy_set_allocator :: (array: *[..]$T, allocator := context.allocator) #expand { #load "allocators.jai"; +#scope_module; + +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; +} + #scope_file; meta :: #import "jc/meta"; @@ -186,33 +192,31 @@ compiler :: #import "Compiler"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS { - test :: #import "jc/test"; +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; - #run { - test.run("request_memory:dynamic arrays", (t) => { - a1 := request_memory([..]int); - defer release_memory(a1); + test.run("request_memory:dynamic arrays", (t) => { + a1 := request_memory([..]int); + defer release_memory(a1); - test.expect(t, a1.count == 0); - test.expect(t, a1.allocated == 0); + test.expect(t, a1.count == 0); + test.expect(t, a1.allocated == 0); - basic.array_add(*a1, 10, 20, 30); - test.expect(t, a1.count == 3); - test.expect(t, a1.allocated != 0, "%", a1.allocated); + basic.array_add(*a1, 10, 20, 30); + test.expect(t, a1.count == 3); + test.expect(t, a1.allocated != 0, "%", a1.allocated); - a2 := request_memory([..]int, 8); - defer release_memory(a2); + a2 := request_memory([..]int, 8); + defer release_memory(a2); - test.expect(t, a2.count == 0); - test.expect(t, a2.allocated == 8); - }); + test.expect(t, a2.count == 0); + test.expect(t, a2.allocated == 8); + }); - test.run("request_memory:values", (t) => { - v1 := request_memory(int); - defer release_memory(v1); + test.run("request_memory:values", (t) => { + v1 := request_memory(int); + defer release_memory(v1); - test.expect(t, v1.* == 0); - }); - } + test.expect(t, v1.* == 0); + }); } diff --git a/meta/macros.jai b/meta/macros.jai index c38fb15..f8c0c83 100644 --- a/meta/macros.jai +++ b/meta/macros.jai @@ -224,7 +224,9 @@ compiler :: #import "Compiler"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS #run { +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + test.run("this_block", (t) => { i := 0; diff --git a/meta/module.jai b/meta/module.jai index 76695a6..91fe6dc 100644 --- a/meta/module.jai +++ b/meta/module.jai @@ -1,4 +1,4 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); get_stack_trace_caller_location :: (loc := #caller_location) -> Source_Code_Location { if context.stack_trace == null || context.stack_trace.info == null { @@ -67,6 +67,10 @@ snake_to_pascal :: (name: string) -> string { #scope_module; +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; +} + mem :: #import "jc/memory"; basic :: #import "Basic"; // @future @@ -77,10 +81,10 @@ compiler :: #import "Compiler"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS { - test :: #import "jc/test"; +#if RUN_TESTS_AT_COMPILE_TIME #run { + test :: #import "jc/meta/test"; - #run test.run("snake_to_pascal", t => { + test.run("snake_to_pascal", t => { test.expect(t, snake_to_pascal("some_name") == "SomeName"); test.expect(t, snake_to_pascal("_some_name") == "SomeName"); test.expect(t, snake_to_pascal("some__name") == "SomeName"); diff --git a/reload/examples/everything-you-need.jai b/meta/reload/examples/everything-you-need.jai similarity index 95% rename from reload/examples/everything-you-need.jai rename to meta/reload/examples/everything-you-need.jai index 0de5065..cef6c57 100644 --- a/reload/examples/everything-you-need.jai +++ b/meta/reload/examples/everything-you-need.jai @@ -23,7 +23,7 @@ G: *struct { // The maximum amount of memory your program is allowed to use. // Its true size is max_memory - state_size bytes. -#program_export max_memory: u64 = 4 * Gigabyte; +#program_export max_memory: u64 = 4 * mem.Gigabyte; // The current size of the global state structure. #program_export state_size: u64 = size_of(type_of(G.*)); @@ -90,6 +90,7 @@ G: *struct { // Use the default build options build_options :: () => reload.Simple_Build_Options.{}; -reload :: #import "jc/reload"; +reload :: #import "jc/meta/reload"; +mem :: #import "jc/memory"; #import "Basic"; diff --git a/reload/examples/quickstart.jai b/meta/reload/examples/quickstart.jai similarity index 91% rename from reload/examples/quickstart.jai rename to meta/reload/examples/quickstart.jai index 2d07938..1f17a8a 100644 --- a/reload/examples/quickstart.jai +++ b/meta/reload/examples/quickstart.jai @@ -2,7 +2,7 @@ G: *struct { allocator: Allocator; }; -#program_export max_memory: u64 = 4 * Gigabyte; +#program_export max_memory: u64 = 4 * mem.Gigabyte; #program_export state_size: u64 = size_of(type_of(G.*)); #program_export init :: (state: *void, allocator: Allocator, full_reset: bool) { @@ -26,6 +26,8 @@ G: *struct { #import "Basic"; +mem :: #import "jc/memory"; + DISABLE_HOT_RELOADING :: false; #if DISABLE_HOT_RELOADING { @@ -49,7 +51,7 @@ DISABLE_HOT_RELOADING :: false; } } else { - reload :: #import "jc/reload"; + reload :: #import "jc/meta/reload"; #poke_name reload frame; #poke_name reload init; #poke_name reload setup; diff --git a/reload/module.jai b/meta/reload/module.jai similarity index 99% rename from reload/module.jai rename to meta/reload/module.jai index 4d05b14..a543439 100644 --- a/reload/module.jai +++ b/meta/reload/module.jai @@ -113,7 +113,7 @@ user_options :: #run -> Simple_Build_Options { #load "%1"; main :: () { - (#import "jc/reload").reload_main(); + (#import "jc/meta/reload").reload_main(); } END, file_path); diff --git a/reload/reload_main.jai b/meta/reload/reload_main.jai similarity index 100% rename from reload/reload_main.jai rename to meta/reload/reload_main.jai diff --git a/test/module.jai b/meta/test/module.jai similarity index 100% rename from test/module.jai rename to meta/test/module.jai diff --git a/meta/type_info.jai b/meta/type_info.jai index 0bafc45..23c8585 100644 --- a/meta/type_info.jai +++ b/meta/type_info.jai @@ -166,7 +166,9 @@ compiler :: #import "Compiler"; // @future // TESTS // ---------------------------------------------------------- -#if RUN_TESTS #run { +#if #exists(RUN_TESTS) #run { + test :: #import "jc/meta/test"; + test.run("lo_for:primitives", t => { test.expect(t, lo_for(u8) == 0); test.expect(t, lo_for(s8) == -128); diff --git a/platform/module.jai b/platform/module.jai index b41df09..4a07854 100644 --- a/platform/module.jai +++ b/platform/module.jai @@ -1,10 +1,10 @@ -#module_parameters(RUN_TESTS := false); +#module_parameters(RUN_TESTS_AT_COMPILE_TIME := false); #load "arch.jai"; -#scope_file; +#scope_module; -#if RUN_TESTS { - test :: #import "jc/test"; +#if RUN_TESTS_AT_COMPILE_TIME { + RUN_TESTS :: true; }