diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index fa7252e..72ed630 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -5,13 +5,13 @@ jobs: steps: - uses: actions/checkout@v4 - run: sudo apt install g++ - - run: g++ build_tool/build_main.cpp -o bld && ./bld + - run: g++ build_tool/main.cpp -o bld && ./bld run-and-compile-mac: runs-on: macos-latest steps: - uses: actions/checkout@v4 - run: brew install llvm - - run: clang++ build_tool/build_main.cpp -std=c++11 -o bld && ./bld + - run: clang++ build_tool/main.cpp -std=c++11 -o bld && ./bld run-and-compile-windows: runs-on: windows-latest steps: diff --git a/build.bat b/build.bat index acbf959..604904b 100644 --- a/build.bat +++ b/build.bat @@ -3,6 +3,6 @@ call ../misc/compile_setup.bat mkdir build cd build -cl -Fe:bld.exe ../build_tool/build_main.cpp -FC -WX -W3 -wd4200 -diagnostics:column -nologo -Zi -D_CRT_SECURE_NO_WARNINGS +cl -Fe:bld.exe ../build_tool/main.cpp -FC -WX -W3 -wd4200 -diagnostics:column -nologo -Zi -D_CRT_SECURE_NO_WARNINGS cd .. build\bld.exe diff --git a/build.sh b/build.sh index f877c23..8ab3e5a 100644 --- a/build.sh +++ b/build.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -gcc -o bld build_tool/build_main.cpp -g +gcc -o bld build_tool/main.cpp -g ./bld diff --git a/build_file.cpp b/build_file.cpp index 9c56861..d04cb40 100644 --- a/build_file.cpp +++ b/build_file.cpp @@ -1,4 +1,4 @@ -#include "build_tool/build_lib.cpp" +#include "build_tool/library.cpp" void CompileFiles(Strs cc, Strs files); int ReturnValue = 0; diff --git a/build_tool/cache.c b/build_tool/cache.cpp similarity index 96% rename from build_tool/cache.c rename to build_tool/cache.cpp index 90efaf7..472dc80 100644 --- a/build_tool/cache.c +++ b/build_tool/cache.cpp @@ -80,10 +80,10 @@ SRC_CacheEntry *SRC_HashFile(S8_String file, char *parent_file) { for (CL_Token token = CL_Next(&lexer); token.kind != CL_EOF; token = CL_Next(&lexer)) { if (token.is_system_include) continue; - S8_String file_it = S8_Make(token.str, token.len); + S8_String file_it = S8_MakeFromChar(token.string_literal); SRC_CacheEntry *cache = SRC_HashFile(file_it, resolved_file); if (!cache) { - IO_Printf("Missing cache for: %.*s\n", S8_Expand(file_it)); + // error was reported already IO_Printf("Missing cache for: %.*s\n", S8_Expand(file_it)); continue; } diff --git a/build_tool/build_lib.cpp b/build_tool/library.cpp similarity index 99% rename from build_tool/build_lib.cpp rename to build_tool/library.cpp index b72d9da..f026af9 100644 --- a/build_tool/build_lib.cpp +++ b/build_tool/library.cpp @@ -47,7 +47,7 @@ MA_Arena PernamentArena; MA_Arena *Perm = &PernamentArena; Table CMDLine; -#include "cache.c" +#include "cache.cpp" // // diff --git a/build_tool/build_main.cpp b/build_tool/main.cpp similarity index 99% rename from build_tool/build_main.cpp rename to build_tool/main.cpp index faea11c..711b8b4 100644 --- a/build_tool/build_main.cpp +++ b/build_tool/main.cpp @@ -1,5 +1,5 @@ #define BUILD_MAIN -#include "build_lib.cpp" +#include "library.cpp" int main(int argument_count, char **arguments) { OS_MakeDir(S8_Lit("build")); diff --git a/core_library/core.c b/core_library/core.c index b36a856..bfc1e80 100644 --- a/core_library/core.c +++ b/core_library/core.c @@ -3,12 +3,8 @@ leeway for big buffers and other such things. Just make sure to not relay on it because it's easier unless specified. - Not sure if we should assume that strings should use allocators or arenas, for now it's arenas because I don't have other use cases @todo -- Maybe create a nice C++ binding for strings, +- Add proper string arrays and utilities for build files - also add String Arrays and String Builder, temp allocators hook ins for nicer api - - Iterating over unicode codepoints using For -- Redesign clexer because the Arena Tuple is hella weird - - Maybe remove token array stuff, do standard stream thing, then you need one arena ... - - Add filter stuff so we can get includes / comments / normal tokens etc. */ #include "core.h" diff --git a/core_library/filesystem.c b/core_library/filesystem.c index a0260a7..628fff3 100644 --- a/core_library/filesystem.c +++ b/core_library/filesystem.c @@ -495,10 +495,11 @@ OS_API void OS_Advance(OS_FileIter *it) { it->is_directory = file->d_type == DT_DIR; it->filename = S8_CopyChar(it->arena, file->d_name); - const char *is_dir = it->is_directory ? "/" : ""; + const char *dir_char_ending = it->is_directory ? "/" : ""; const char *separator = it->path.str[it->path.len - 1] == '/' ? "" : "/"; - it->relative_path = S8_Format(it->arena, "%.*s%s%s%s", S8_Expand(it->path), separator, file->d_name, is_dir); + it->relative_path = S8_Format(it->arena, "%.*s%s%s%s", S8_Expand(it->path), separator, file->d_name, dir_char_ending); it->absolute_path = OS_GetAbsolutePath(it->arena, it->relative_path); + if (it->is_directory) it->absolute_path = S8_Format(it->arena, "%.*s/", S8_Expand(it->absolute_path)); it->is_valid = true; return; } diff --git a/standalone_libraries/clexer.c b/standalone_libraries/clexer.c index 06c2a0e..a60c0dc 100644 --- a/standalone_libraries/clexer.c +++ b/standalone_libraries/clexer.c @@ -60,6 +60,13 @@ CL_PRIVATE_FUNCTION bool CL_FileExists(char *name) { CL_PRIVATE_FUNCTION void CL_ReportError(CL_Lexer *T, CL_Token *token, const char *string, ...); +CL_PRIVATE_FUNCTION char *CL_PushStringCopy(CL_Allocator arena, char *p, int size) { + char *copy_buffer = (char *)CL_Allocate(arena, size + 1); + CL__MemoryCopy(copy_buffer, p, size); + copy_buffer[size] = 0; + return copy_buffer; +} + CL_INLINE void CL_Advance(CL_Lexer *T) { if (*T->stream == '\n') { T->line += 1; @@ -274,6 +281,8 @@ skip_utf_encode: // so the final string actually needs additional transformation pass. A pass // that will combine the string snippets, replace escape sequences with actual values etc. // +// @warning: @not_sure: we are not setting token->string_literal +// // "String 1" "String 2" - those strings snippets are combined // @todo: look at this again // @todo: make a manual correct version that user can execute if he needs to @@ -635,6 +644,9 @@ CL_PRIVATE_FUNCTION void CL_LexMacroInclude(CL_Lexer *T, CL_Token *token) { } CL_SetTokenLength(T, token); CL_Advance(T); + + // @not_sure: this is because we want null terminated input into path resolution stuff + token->string_literal = CL_PushStringCopy(T->arena, token->str, token->len); } CL_PRIVATE_FUNCTION bool CL_LexMacro(CL_Lexer *T, CL_Token *token) { @@ -1227,13 +1239,6 @@ CL_API_FUNCTION CL_Lexer CL_Begin(CL_Allocator arena, char *stream, char *filena // // -CL_PRIVATE_FUNCTION char *CL_PushStringCopy(CL_Allocator arena, char *p, int size) { - char *copy_buffer = (char *)CL_Allocate(arena, size + 1); - CL__MemoryCopy(copy_buffer, p, size); - copy_buffer[size] = 0; - return copy_buffer; -} - CL_PRIVATE_FUNCTION char *CL_ChopLastSlash(CL_Allocator arena, char *str) { int i = 0; int slash_pos = -1; diff --git a/tests/1test_string.cpp b/tests/1test_string.cpp index da6a77f..529d650 100644 --- a/tests/1test_string.cpp +++ b/tests/1test_string.cpp @@ -1,7 +1,7 @@ #include "../core_library/core.c" -#define CL_Arena MA_Arena -#define CL_PushSize MA_PushSizeNonZeroed +#define CL_Allocator MA_Arena * +#define CL_Allocate(a, s) MA_PushSizeNonZeroed(a, s) #define CL_ASSERT IO_Assert #define CL_VSNPRINTF stbsp_vsnprintf #define CL_SNPRINTF stbsp_snprintf diff --git a/tests/test_filesystem.c b/tests/test_filesystem.c index bd28bae..ae5884d 100644 --- a/tests/test_filesystem.c +++ b/tests/test_filesystem.c @@ -78,7 +78,7 @@ int main() { { for (OS_FileIter it = OS_IterateFiles(&arena, S8_Lit("..")); OS_IsValid(it); OS_Advance(&it)) { if (it.is_directory) { - IO_Assert(it.absolute_path.str[it.absolute_path.len - 1] == '/'); + IO_Assertf(it.absolute_path.str[it.absolute_path.len - 1] == '/', "%.*s", S8_Expand(it.absolute_path)); } IO_Assert(!S8_Seek(it.absolute_path, S8_Lit(".."), 0, 0)); IO_Assert(S8_Seek(it.relative_path, S8_Lit(".."), 0, 0));