diff --git a/build_file.c b/build_file.c index 8b25a77..55c9799 100644 --- a/build_file.c +++ b/build_file.c @@ -41,19 +41,18 @@ void build_testing_target(void) { ok = os_systemf("testing.exe"); if (ok != 0) exit(ok); + } else { + int ok = os_systemf( + "clang ../src/testing/testing_main.c -o testing.exe -g -I ../src" + " -fdiagnostics-absolute-paths -Wno-unsequenced -Wno-single-bit-bitfield-constant-conversion" + " -lm -ldl" + ); + if (ok != 0) exit(ok); - return; + ok = os_systemf("./testing.exe"); + if (ok != 0) exit(ok); } - int ok = os_systemf( - "clang ../src/testing/testing_main.c -o testing.exe -g -I ../src" - " -fdiagnostics-absolute-paths -Wno-unsequenced -Wno-single-bit-bitfield-constant-conversion" - " -lm -ldl" - ); - if (ok != 0) exit(ok); - - ok = os_systemf("./testing.exe"); - if (ok != 0) exit(ok); } void build_win32_app_base_target(void) { @@ -165,13 +164,13 @@ int main(int argc, char **argv) { generate_testing_code(tcx->temp); generate_text_editor_code(tcx->temp); - b32 run_server = false; b32 run_win32_app_base_target = true; b32 run_testing_target = true; - b32 run_text_editor_dll_target = false; + b32 run_text_editor_dll_target = true; b32 run_prototype_dll_target = false; b32 run_prototype_wasm_target = false; b32 run_prototype_standalone_target = false; + b32 run_server = false; if (run_server) { os_systemf("start /D ..\\package ..\\package\\run_server.bat"); diff --git a/src/core/core.c b/src/core/core.c index ef4c042..87a96d5 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -3,11 +3,14 @@ #elif PLATFORM_WINDOWS #pragma comment(lib, "user32.lib") #pragma comment(lib, "DbgHelp.lib") + #pragma comment(lib, "Shell32.lib") + #pragma comment(lib, "Ole32.lib") #define NOMINMAX #define WIN32_LEAN_AND_MEAN #include #include #include + #include #include #include #include @@ -59,6 +62,7 @@ #include "core_type_info.c" #include "core_hash.c" #include "core_hash_table.c" +#include "core_array.c" #ifndef DONT_INCLUDE_GENERATED_MATH #include "core_math.gen.c" #endif diff --git a/src/core/core_array.c b/src/core/core_array.c new file mode 100644 index 0000000..455d24a --- /dev/null +++ b/src/core/core_array.c @@ -0,0 +1,98 @@ +typedef struct array_header_t array_header_t; +struct array_header_t { + ma_arena_t *arena; + i64 len; + i64 cap; +}; + +#define array_header(arr) ((array_header_t *)(arr) - 1) +#define array_len(arr) (array_header(arr)->len) +#define array_cap(arr) (array_header(arr)->cap) +#define array_add(arr, x) (array_grow(&(arr), sizeof(*(arr)), 1), (arr)[array_len(arr)++] = (x)) +#define array_addn(arr, count) (array_grow(&(arr), sizeof(*(arr)), (count)), array_len(arr) += (count), &(arr)[array_len(arr) - (count)]) +#define array_set_len(arr, x) (array_len(arr) = (x)) +#define array_set_cap(arr, x) (array__set_cap(&(arr), sizeof(*(arr)), (x))) +#define array_pop(arr) ((arr)[--array_len(arr)]) +#define array_swapdel(arr, i) (assert_expr((i) < array_len(arr)), (arr)[(i)] = (arr)[--array_len(arr)]) +#define array_create(arena, type, count) (type *)(array__create((arena), sizeof(type), (count)) + 1) + +fn array_header_t *array__create(ma_arena_t *arena, i64 item_size, i64 item_count) { + array_header_t *hdr = (array_header_t *)ma_push_size(arena, item_size * item_count + sizeof(array_header_t)); + hdr->arena = arena; + hdr->cap = item_count; + return hdr; +} + +fn void array__set_cap(void **arr, i64 item_size, i64 item_count) { + array_header_t *hdr = array_header(*arr); + array_header_t *new_hdr = array__create(hdr->arena, item_size, item_count); + new_hdr->len = CLAMP(hdr->len, 0, item_count); + memory_copy(new_hdr + 1, hdr + 1, new_hdr->len * item_size); + *arr = new_hdr + 1; +} + +fn void array_grow(void **arr, i64 item_size, i64 increment) { + assert(increment >= 1); + array_header_t *hdr = array_header(*arr); + if (hdr->len + increment > hdr->cap) { + array_header_t *new_hdr = array__create(hdr->arena, item_size, (hdr->cap + increment - 1) * 2); + memory_copy(new_hdr + 1, hdr + 1, hdr->len * item_size); + new_hdr->len = hdr->len; + *arr = new_hdr + 1; + // dealloc(hdr); + } +} + +fn_test void test_array(void) { + ma_temp_t scratch = ma_begin_scratch(); + int *arr = array_create(scratch.arena, int, 2); + for (int i = 0; i < 512; i += 1) { + array_add(arr, i); + } + for (int i = 0; i < 512; i += 1) { + assert(arr[i] == i); + } + assert(array_len(arr) == 512); + assert(array_cap(arr) == 512); + for (int i = 511; i >= 0; i -= 1) { + int a = array_pop(arr); + assert(a == i); + } + assert(array_len(arr) == 0); + + { + int *a = array_addn(arr, 4); + assert(arr == a); + assert(array_header(arr)->len == 4); + + int *b = array_addn(arr, 12); + assert(arr + 4 == b); + assert(array_header(arr)->len == 16); + + array_set_len(arr, 0); + } + + { + for (int i = 0; i < 512; i += 1) { + array_add(arr, i); + } + + array_swapdel(arr, 3); + assert(arr[3] == 511); + assert(array_len(arr) == 511); + + array_set_len(arr, 0); + } + + { + for (int i = 0; i < 512; i += 1) { + array_add(arr, i); + } + array_set_cap(arr, 256); + assert(array_len(arr) == 256); + assert(array_cap(arr) == 256); + } + + + ma_end_scratch(scratch); +} diff --git a/src/core/core_lexer.c b/src/core/core_lexer.c index 6095cf1..2bbe749 100644 --- a/src/core/core_lexer.c +++ b/src/core/core_lexer.c @@ -432,7 +432,7 @@ fn void parser_panicf(b32 print_only_file, lex_t *token, const char *str, ...) { if (print_only_file) { fatalf("%s: error: %S", token->file, str8); } else { - fatalf("%S(%d): error: %S", token->file, token->line, str8); + fatalf("%s(%d): error: %S", token->file, token->line, str8); } diff --git a/src/os/os_win32.c b/src/os/os_win32.c index f4ef992..22abd69 100644 --- a/src/os/os_win32.c +++ b/src/os/os_win32.c @@ -363,4 +363,33 @@ fn i32 os_thread_join(os_thread_t *thread) { // os_thread_join(&threads[i]); // } // ma_end_scratch(scratch); -// } \ No newline at end of file +// } + +fn s8_t os_appdata(ma_arena_t *arena, s8_t name) { + assert(name.len != 0); + assert(name.str); + assert(arena); + + wchar_t *out_path = NULL; + HRESULT hr = SHGetKnownFolderPath(&FOLDERID_RoamingAppData, KF_FLAG_CREATE, NULL, &out_path); + if (!SUCCEEDED(hr)) { + debugf(__FUNCTION__".SHGetKnownFolderPath failed with hr: %d", hr); + return s8_null; + } + + s16_t appdata_path = s16_from_str16((u16 *)out_path); + + ma_temp_t scratch = ma_begin_scratch1(arena); + s8_t tmp = s8_from_s16(scratch.arena, appdata_path); + s8_normalize_path_unsafe(tmp); + s8_t path = s8_printf(arena, "%S/%S/", tmp, name); + os_mkdir_t mkdir_status = os_mkdir(path); + if (mkdir_status != os_mkdir_success && mkdir_status != os_mkdir_file_exists) { + debugf(__FUNCTION__".os_mkdir failed with status: %d, for: %S", mkdir_status, path); + path = s8_null; + } + + CoTaskMemFree(out_path); + ma_end_scratch(scratch); + return path; +} \ No newline at end of file diff --git a/src/testing/testing.gen.c b/src/testing/testing.gen.c index 1b1b98a..d58ccd4 100644 --- a/src/testing/testing.gen.c +++ b/src/testing/testing.gen.c @@ -1,5 +1,10 @@ +void test_string16(void); +void test_hash_table(void); +void test_intern_table(void); +void test_array(void); fn void run_tests(void) { test_string16(); test_hash_table(); test_intern_table(); + test_array(); } diff --git a/src/testing/testing.meta.c b/src/testing/testing.meta.c index 3284f2d..19872a5 100644 --- a/src/testing/testing.meta.c +++ b/src/testing/testing.meta.c @@ -21,6 +21,9 @@ void generate_testing_code(ma_arena_t *arena) { } sb8_t *c = sb8_serial_begin(arena); + for (sb8_node_t *it = tests->first; it; it = it->next) { + sb8_printf(c, "void %S(void);\n", it->string); + } sb8_printf(c, "fn void run_tests(void) {\n"); for (sb8_node_t *it = tests->first; it; it = it->next) { sb8_printf(c, " %S();\n", it->string); diff --git a/src/testing/testing_main.c b/src/testing/testing_main.c index 83c040f..81f53c0 100644 --- a/src/testing/testing_main.c +++ b/src/testing/testing_main.c @@ -6,9 +6,12 @@ #include "testing.gen.c" fn void os_test(void) { + ma_temp_t scratch = ma_begin_scratch(); + os_date_t local_time = os_local_time(); os_date_t universal_time = os_universal_time(); - debugf("OS local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time)); + unused(universal_time); unused(local_time); + // debugf("OS local_time = %S | universal_time = %S", os_format_date(tcx->temp, local_time), os_format_date(tcx->temp, universal_time)); s8_t exe_dir = os_exe_dir(tcx->temp); assert(exe_dir.str[exe_dir.len - 1] == '/'); @@ -25,11 +28,19 @@ fn void os_test(void) { assert(os_is_abs(exe)); assert(os_is_abs(cwd)); assert(!os_is_abs(s8("../path/"))); - debugf("OS paths %S %S %S", exe_dir, exe, cwd); + // debugf("OS paths %S %S %S", exe_dir, exe, cwd); s8_t file = os_read(tcx->temp, s8("../.gitignore")); assert(file.str != 0); assert(file.len != 0); + +#if PLATFORM_WINDOWS + s8_t path = os_appdata(scratch.arena, s8("testing")); + assert(path.str[path.len - 1] == '/'); + assert(s8_starts_with(path, s8("C:/"))); + assert(s8_ends_with(path, s8("/testing/"))); +#endif + ma_end_scratch(scratch); } fn void test_s8(void) { diff --git a/src/text_editor/text_editor.gen.c b/src/text_editor/text_editor.gen.c index 774cb0e..a6666fc 100644 --- a/src/text_editor/text_editor.gen.c +++ b/src/text_editor/text_editor.gen.c @@ -10,5 +10,5 @@ void run_all_tests(void) { test_string16(); test_hash_table(); test_intern_table(); - ui_test_text_replace(); + test_array(); }// run_all_tests() diff --git a/src/text_editor/text_editor_main.c b/src/text_editor/text_editor_main.c index 4b9d4aa..4bf643c 100644 --- a/src/text_editor/text_editor_main.c +++ b/src/text_editor/text_editor_main.c @@ -1,21 +1,61 @@ #include "core/core.h" #include "os/os.h" #include "app/app.h" -#include "ui/ui.h" +// #include "ui/ui.h" #include "core/core.c" #include "os/os.c" #include "app/app.c" #include "render/render.c" -#include "ui/ui.c" +// #include "ui/ui.c" #include "text_editor.gen.c" -// @todo: -// Create a complete string16 library -// Win32 SDL_GetPrefPath, create configuration directory, get path -// Win32 set screen saver -// Win32 upload icon +/*todo: + * OK Create a complete string16 library + * OK (Win32) Win32 SDL_GetPrefPath, create configuration directory, get path + * Array + * + * + * + * Win32 upload icon +**/ + +typedef struct caret_t caret_t; +struct caret_t { + i64 ifront; + union { + r1i64_t range; + i64 pos[2]; + }; +}; + +typedef struct xy_t xy_t; +struct xy_t { + i64 col; + i64 line; +}; + +typedef struct buffer_id_t buffer_id_t; +struct buffer_id_t { i64 e; }; + +typedef struct buffer_t buffer_t; +struct buffer_t { + buffer_id_t id; + + union { + s16_t string; + struct { + u16 *data; + i64 len; + }; + }; + i64 cap; + + i64 *line_starts; + i64 line_count; +}; + fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { tcx = thread_ctx; @@ -40,6 +80,10 @@ fn_export b32 app_update(thread_ctx_t *thread_ctx, app_frame_t *frame) { rn_reload_font(font_size, frame->dpr); } + rn_begin_frame(frame); + rn_begin(white_color); + rn_end(); + return true; } diff --git a/src/ui/ui.c b/src/ui/ui.c index bc6e717..281c23f 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -1293,7 +1293,7 @@ fn void ui_demo_everything_lister(void) { ma_temp_t scratch = ma_begin_scratch(); s8_t needle = s8_make(text_input.str, text_input.len); - fuzzy_pair_t *pairs = fuzzy_rate_array(scratch.arena, needle, cmds, lengthof(cmds)); + fuzzy_pair_t *pairs = s8_fuzzy_rate_array(scratch.arena, needle, cmds, lengthof(cmds)); b32 set_focus = lister_just_opened || ti_sig.text_changed; @@ -1370,7 +1370,7 @@ fn void ui_demo_update(app_frame_t *frame, mt_tweak_t *tweak_table, i32 tweak_co ui_top_rectp()[0] = r2f32_shrinks(ui_top_rect(), ui_em(1)); for (i32 i = 0; i < tweak_count; i += 1) { mt_tweak_t *tweak = tweak_table + i; - if (s8_starts_with(tweak->name, s8("_"), false)) { + if (s8_starts_with(tweak->name, s8("_"))) { continue; } diff --git a/src/wasm_app/wasm_app.gen.c b/src/wasm_app/wasm_app.gen.c index 4d1fab2..37bc685 100644 --- a/src/wasm_app/wasm_app.gen.c +++ b/src/wasm_app/wasm_app.gen.c @@ -10,5 +10,6 @@ void run_all_tests(void) { test_string16(); test_hash_table(); test_intern_table(); + test_array(); ui_test_text_replace(); }// run_all_tests()