| @@ -16,7 +16,7 @@ struct Array_List { | |||
| void dealloc() { | |||
| free(data); | |||
| data = 0; | |||
| data = nullptr; | |||
| } | |||
| @@ -75,10 +75,10 @@ struct Hook : Array_List<Lambda<void()>> { | |||
| } | |||
| }; | |||
| // struct __System_Shutdown_Hook : Hook { | |||
| // void operator()() = delete; | |||
| // ~__System_Shutdown_Hook() { | |||
| // Hook::operator()(); | |||
| // dealloc(); | |||
| // } | |||
| // } system_shutdown_hook; | |||
| struct __System_Shutdown_Hook : Hook { | |||
| void operator()() = delete; | |||
| ~__System_Shutdown_Hook() { | |||
| Hook::operator()(); | |||
| dealloc(); | |||
| } | |||
| } system_shutdown_hook; | |||
| @@ -52,14 +52,19 @@ expands to: | |||
| }; | |||
| */ | |||
| #if defined(unix) || defined(__unix__) || defined(__unix) | |||
| #define NULL_HANDLE "/dev/null" | |||
| #else | |||
| #define NULL_HANDLE "nul" | |||
| #endif | |||
| #define ignore_stdout \ | |||
| if (0) \ | |||
| label(finished,__LINE__): ; \ | |||
| else \ | |||
| for (FILE* tmp = ftb_stdout;;) \ | |||
| for (defer{ fclose(ftb_stdout); ftb_stdout= tmp; } ;;) \ | |||
| for (FILE* label(fluid_let_, __LINE__) = ftb_stdout;;) \ | |||
| for (defer{ fclose(ftb_stdout); ftb_stdout=label(fluid_let_, __LINE__) ; } ;;) \ | |||
| if (1) { \ | |||
| ftb_stdout = fopen("nul", "w"); \ | |||
| ftb_stdout = fopen(NULL_HANDLE, "w"); \ | |||
| goto label(body,__LINE__); \ | |||
| } \ | |||
| else \ | |||
| @@ -68,7 +73,6 @@ expands to: | |||
| goto label(finished, __LINE__); \ | |||
| } \ | |||
| else label(body,__LINE__): | |||
| /***************** | |||
| @@ -91,6 +95,7 @@ expands to: | |||
| goto TOKENPASTE2(finished, __LINE__); \ | |||
| } \ | |||
| else TOKENPASTE2(body,__LINE__): | |||
| ; | |||
| /** | |||
| @@ -1,9 +1,9 @@ | |||
| #pragma once | |||
| #if defined(_WIN32) || defined(_WIN64) | |||
| #pragma message("Compiling for Windows") | |||
| // #pragma message ("Compiling for Windows") | |||
| #define FTB_WINDOWS | |||
| #elseif | |||
| #pragma message("Compiling for Linux") | |||
| #else | |||
| // #pragma message ("Compiling for Linux") | |||
| #define FTB_LINUX | |||
| #endif | |||
| @@ -8,6 +8,7 @@ | |||
| #include <string.h> | |||
| #include "hashmap.hpp" | |||
| #include "hooks.hpp" | |||
| FILE* ftb_stdout = stdout; | |||
| @@ -443,27 +444,28 @@ auto print_str_line(FILE* f, char* str) -> s32 { | |||
| return print_to_file(f, "%.*s", length, str); | |||
| } | |||
| void deinit_printer() { | |||
| printer_map.dealloc(); | |||
| type_map.dealloc(); | |||
| } | |||
| void init_printer() { | |||
| color_stack.alloc(); | |||
| printer_map.alloc(); | |||
| type_map.alloc(); | |||
| register_printer("u32", print_u32, Printer_Function_Type::_32b); | |||
| register_printer("u64", print_u64, Printer_Function_Type::_64b); | |||
| register_printer("bool", print_bool, Printer_Function_Type::_32b); | |||
| register_printer("s64", print_s64, Printer_Function_Type::_64b); | |||
| register_printer("s32", print_s32, Printer_Function_Type::_32b); | |||
| register_printer("f32", print_flt, Printer_Function_Type::_flt); | |||
| register_printer("f64", print_flt, Printer_Function_Type::_flt); | |||
| register_printer("->char", print_str, Printer_Function_Type::_ptr); | |||
| register_printer("->", print_ptr, Printer_Function_Type::_ptr); | |||
| register_printer("color<", print_color_start, Printer_Function_Type::_ptr); | |||
| register_printer(">color", print_color_end, Printer_Function_Type::_void); | |||
| register_printer("->Str", print_Str, Printer_Function_Type::_ptr); | |||
| register_printer("->char_line", print_str_line, Printer_Function_Type::_ptr); | |||
| system_shutdown_hook << [](){ | |||
| color_stack.dealloc(); | |||
| printer_map.dealloc(); | |||
| type_map.dealloc(); | |||
| }; | |||
| register_printer("u32", print_u32, Printer_Function_Type::_32b); | |||
| register_printer("u64", print_u64, Printer_Function_Type::_64b); | |||
| register_printer("bool", print_bool, Printer_Function_Type::_32b); | |||
| register_printer("s64", print_s64, Printer_Function_Type::_64b); | |||
| register_printer("s32", print_s32, Printer_Function_Type::_32b); | |||
| register_printer("f32", print_flt, Printer_Function_Type::_flt); | |||
| register_printer("f64", print_flt, Printer_Function_Type::_flt); | |||
| register_printer("->char", print_str, Printer_Function_Type::_ptr); | |||
| register_printer("->", print_ptr, Printer_Function_Type::_ptr); | |||
| register_printer("color<", print_color_start, Printer_Function_Type::_ptr); | |||
| register_printer(">color", print_color_end, Printer_Function_Type::_void); | |||
| register_printer("->Str", print_Str, Printer_Function_Type::_ptr); | |||
| register_printer("->char_line", print_str_line, Printer_Function_Type::_ptr); | |||
| } | |||
| @@ -18,11 +18,15 @@ typedef s32 testresult; | |||
| "\n\tgot anyways: " format "\n", \ | |||
| __FILE__, __LINE__, (type)(value), (type)(variable)) | |||
| #define assert_equal_string(variable, value) \ | |||
| if (!string_equal(variable, value)) { \ | |||
| print_assert_equal_fail(&(variable), &(value), String*, "%{->Str}"); \ | |||
| return fail; \ | |||
| } | |||
| #define assert_equal_string(variable, value) \ | |||
| do { \ | |||
| auto v1{variable}; \ | |||
| auto v2{value}; \ | |||
| if (!string_equal(v1, v2)) { \ | |||
| print_assert_equal_fail(&(v1), &(v2), String*, "%{->Str}"); \ | |||
| return fail; \ | |||
| } \ | |||
| } while (0) | |||
| #define assert_equal_int(variable, value) \ | |||
| if (variable != value) { \ | |||
| @@ -82,8 +86,8 @@ typedef s32 testresult; | |||
| for(s32 i = -1; i < 70; ++i) \ | |||
| fputs((i%3==1)? "." : " ", stdout); \ | |||
| fputs(console_red "failed\n" console_normal, stdout); \ | |||
| if(error) { \ | |||
| free(error); \ | |||
| error = nullptr; \ | |||
| if(error) { \ | |||
| free(error); \ | |||
| error = nullptr; \ | |||
| } \ | |||
| } \ | |||
| } | |||
| @@ -23,11 +23,17 @@ typedef wchar_t path_char; | |||
| typedef char path_char; | |||
| #endif | |||
| struct String { | |||
| struct StringSlice { | |||
| const char* data; | |||
| u64 length; | |||
| }; | |||
| struct String { | |||
| char* data; | |||
| u64 length; | |||
| }; | |||
| inline auto heap_copy_c_string(const char* str) -> char* { | |||
| #ifdef FTB_WINDOWS | |||
| return _strdup(str); | |||
| @@ -43,9 +49,32 @@ inline auto make_heap_string(const char* str) -> String { | |||
| return ret; | |||
| } | |||
| inline const String make_static_string(char* str) { | |||
| String ret; | |||
| inline auto make_static_string(const char* str) -> const StringSlice { | |||
| StringSlice ret; | |||
| ret.length = strlen(str); | |||
| ret.data = str; | |||
| return ret; | |||
| } | |||
| auto inline string_equal(const char* input, const char* check) -> bool { | |||
| return strcmp(input, check) == 0; | |||
| } | |||
| auto inline string_equal(StringSlice str, const char* check) -> bool { | |||
| if (str.length != strlen(check)) | |||
| return false; | |||
| return strncmp(str.data, check, str.length) == 0; | |||
| } | |||
| auto inline string_equal(const char* check, StringSlice str) -> bool { | |||
| if (str.length != strlen(check)) | |||
| return false; | |||
| return strncmp(str.data, check, str.length) == 0; | |||
| } | |||
| auto inline string_equal(StringSlice str1, StringSlice str2) -> bool { | |||
| if (str1.length != str2.length) | |||
| return false; | |||
| return strncmp(str1.data, str2.data, str2.length) == 0; | |||
| } | |||