From a9da704c8a6ca9e45c7f7827ed5a3d8048f5b632 Mon Sep 17 00:00:00 2001 From: Elliot <35050275+apache-hb@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:39:05 -0400 Subject: [PATCH] remove some old stuff --- meson.build | 13 +- meson_options.txt | 25 -- src/common/arena/include/arena/arena.h | 5 +- src/common/backtrace/src/dbghelp.c | 7 - src/common/base/include/base/panic.h | 6 +- src/common/core/include/core/win32.h | 26 +- src/common/endian/include/endian/endian.h | 4 - src/common/fs/include/fs/fs.h | 12 + src/common/fs/src/common.c | 9 +- src/common/fs/src/common.h | 2 +- src/common/fs/src/fs.c | 27 ++ src/common/fs/src/physical.c | 13 +- src/common/os/include/os/os.h | 26 +- src/common/os/src/os.c | 13 - src/common/os/src/os_common.c | 4 - src/common/os/src/os_common.h | 22 - src/common/os/src/posix/file.c | 4 - src/common/os/src/posix/fs.c | 15 +- src/common/os/src/windows/dir.c | 4 - src/common/os/src/windows/error.c | 5 - src/common/os/src/windows/file.c | 12 - src/common/os/src/windows/fs.c | 20 +- src/common/os/src/windows/init.c | 6 - src/common/os/src/windows/library.c | 4 - .../editor/include/editor/panels/events.hpp | 10 - .../editor/include/editor/panels/settings.hpp | 16 - .../editor/include/editor/panels/theme.hpp | 11 + src/frontend/gui/editor/meson.build | 3 +- src/frontend/gui/editor/src/main.cpp | 141 +----- src/frontend/gui/editor/src/panels/events.cpp | 423 ------------------ .../gui/editor/src/panels/settings.cpp | 13 - src/frontend/gui/editor/src/panels/theme.cpp | 73 +++ src/language/README.md | 87 ---- src/language/meson.build | 12 - src/tools/harness/main.c | 5 +- .../c_family/lang/data/modules.h | 0 .../c_family/lang/include/c/ast.h | 0 .../c_family/lang/include/c/ast.inc | 0 .../c_family/lang/include/c/driver.h | 0 .../c_family/lang/include/c/events.inc | 0 .../c_family/lang/include/c/scan.h | 0 .../c_family/lang/include/c/sema/sema.h | 0 .../c_family/lang/meson.build | 0 .../language => todo}/c_family/lang/src/ast.c | 0 {src/language => todo}/c_family/lang/src/cc.l | 0 {src/language => todo}/c_family/lang/src/cc.y | 0 .../c_family/lang/src/driver.c | 0 .../c_family/lang/src/events.c | 0 .../c_family/lang/src/main.c | 0 .../c_family/lang/src/scan.c | 0 .../c_family/pre/include/pre/scan.h | 0 .../c_family/pre/meson.build | 0 .../language => todo}/c_family/pre/src/main.c | 0 {src/language => todo}/c_family/pre/src/pre.l | 0 .../language => todo}/c_family/pre/src/scan.c | 0 {src/language => todo}/jvm/include/jvm/jvm.h | 0 .../language => todo}/jvm/include/jvm/jvm.inc | 0 {src/language => todo}/jvm/main.c | 0 {src/language => todo}/jvm/meson.build | 0 {src/language => todo}/jvm/src/jvm/jvm.c | 0 60 files changed, 170 insertions(+), 908 deletions(-) delete mode 100644 src/frontend/gui/editor/include/editor/panels/events.hpp delete mode 100644 src/frontend/gui/editor/include/editor/panels/settings.hpp create mode 100644 src/frontend/gui/editor/include/editor/panels/theme.hpp delete mode 100644 src/frontend/gui/editor/src/panels/events.cpp delete mode 100644 src/frontend/gui/editor/src/panels/settings.cpp create mode 100644 src/frontend/gui/editor/src/panels/theme.cpp delete mode 100644 src/language/README.md rename {src/language => todo}/c_family/lang/data/modules.h (100%) rename {src/language => todo}/c_family/lang/include/c/ast.h (100%) rename {src/language => todo}/c_family/lang/include/c/ast.inc (100%) rename {src/language => todo}/c_family/lang/include/c/driver.h (100%) rename {src/language => todo}/c_family/lang/include/c/events.inc (100%) rename {src/language => todo}/c_family/lang/include/c/scan.h (100%) rename {src/language => todo}/c_family/lang/include/c/sema/sema.h (100%) rename {src/language => todo}/c_family/lang/meson.build (100%) rename {src/language => todo}/c_family/lang/src/ast.c (100%) rename {src/language => todo}/c_family/lang/src/cc.l (100%) rename {src/language => todo}/c_family/lang/src/cc.y (100%) rename {src/language => todo}/c_family/lang/src/driver.c (100%) rename {src/language => todo}/c_family/lang/src/events.c (100%) rename {src/language => todo}/c_family/lang/src/main.c (100%) rename {src/language => todo}/c_family/lang/src/scan.c (100%) rename {src/language => todo}/c_family/pre/include/pre/scan.h (100%) rename {src/language => todo}/c_family/pre/meson.build (100%) rename {src/language => todo}/c_family/pre/src/main.c (100%) rename {src/language => todo}/c_family/pre/src/pre.l (100%) rename {src/language => todo}/c_family/pre/src/scan.c (100%) rename {src/language => todo}/jvm/include/jvm/jvm.h (100%) rename {src/language => todo}/jvm/include/jvm/jvm.inc (100%) rename {src/language => todo}/jvm/main.c (100%) rename {src/language => todo}/jvm/meson.build (100%) rename {src/language => todo}/jvm/src/jvm/jvm.c (100%) diff --git a/meson.build b/meson.build index 60c26f32..d5d3fd5e 100644 --- a/meson.build +++ b/meson.build @@ -38,7 +38,6 @@ endif opt_paranoid = get_option('paranoid').disable_auto_if(is_release) opt_analyze = get_option('analyze').disable_auto_if(meson.is_subproject()) -win32_trickery = get_option('win32_trickery') trace_time = get_option('trace_time').disable_auto_if(meson.is_subproject()) # disable stb_sprintf by default if we're a subproject, people may not @@ -53,7 +52,6 @@ driver_tests = get_option('driver_tests').disable_auto_if(meson.is_subproject()) warning_level = get_option('warning_level').to_int() trace_memory = get_option('trace_memory').disable_auto_if(is_release or meson.is_subproject()) -events = get_option('events').disable_auto_if(is_release or meson.is_subproject()) # these are tools for internal use, so disable them in release mode tool_notify = get_option('tool_notify').disable_auto_if(is_release or meson.is_subproject()) @@ -70,10 +68,7 @@ frontend_example = get_option('frontend_example').disable_auto_if(meson.is_subpr lang_ctu = get_option('lang_ctu').disable_auto_if(meson.is_subproject()) lang_pl0 = get_option('lang_pl0').disable_auto_if(meson.is_subproject()) lang_oberon = get_option('lang_oberon').disable_auto_if(meson.is_subproject()) -lang_jvm = get_option('lang_jvm').disable_auto_if(meson.is_subproject()) lang_example = get_option('lang_example').disable_auto_if(meson.is_subproject()) -lang_c = get_option('lang_c').disable_auto_if(meson.is_subproject()) -lang_cpp = get_option('lang_cpp').disable_auto_if(meson.is_subproject()) # all the codegen targets target_cfamily = get_option('target_cfamily').disable_auto_if(meson.is_subproject()) @@ -114,7 +109,6 @@ config_cdata.set('CTU_PATCH', parts[2].to_int()) config_cdata.set10('CTU_DEBUG', is_debug) config_cdata.set10('CTU_PARANOID', opt_paranoid.allowed()) config_cdata.set10('CTU_BUILD_SHARED', default_library == 'shared') -config_cdata.set10('CTU_WIN32_TRICKERY', win32_trickery.allowed()) # we use `__attribute__((const|pure))` heavily, but during unit tests we # violate function preconditions to test assertions. @@ -127,7 +121,6 @@ config_cdata.set10('CTU_HAS_PRETTY_FUNCTION', warning_level < 3) config_cdata.set10('CTU_TRACE_MEMORY', trace_memory.allowed()) config_cdata.set10('CTU_STB_SPRINTF', opt_stb_sprintf.allowed()) -config_cdata.set10('CTU_EVENTS', events.allowed()) # args for all code all_args = cc.get_supported_arguments( @@ -371,13 +364,12 @@ build_summary = { 'Paranoid asserts': opt_paranoid.allowed(), 'Flex': flex, 'Bison': bison, - 'Win32 trickery': win32_trickery.allowed(), 'Compile time tracing': trace_time.enabled(), 'Module loader': default_library, 'Unit tests': unit_tests, 'Driver tests': driver_tests, 'Doxygen': doxygen, - 'STB sprintf': opt_stb_sprintf + 'STB sprintf': opt_stb_sprintf, }, 'Targets': { 'C Family': target_cfamily.allowed(), @@ -391,12 +383,9 @@ build_summary = { 'Example': frontend_example.allowed() }, 'Languages': { - 'C': lang_c.allowed(), - 'C preprocessor': lang_cpp.allowed(), 'Cthulhu': lang_ctu.allowed(), 'PL/0': lang_pl0.allowed(), 'Oberon-2': lang_oberon.allowed(), - 'JVM bytecode': lang_jvm.allowed(), 'Example': lang_example.allowed() }, 'Tools': { diff --git a/meson_options.txt b/meson_options.txt index eec0521e..b7a9d607 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -15,26 +15,11 @@ option('lang_oberon', type : 'feature', value : 'auto' ) -option('lang_jvm', type : 'feature', - description : 'build the jvm language driver', - value : 'disabled' -) - option('lang_example', type : 'feature', description : 'build the example language driver', value : 'auto' ) -option('lang_c', type : 'feature', - description : 'build the c language driver, implies lang_cpp', - value : 'auto' -) - -option('lang_cpp', type : 'feature', - description : 'build the c preprocessor', - value : 'auto' -) - # interfaces option('frontend_cli', type : 'feature', @@ -89,11 +74,6 @@ option('trace_memory', type : 'feature', value : 'auto' ) -option('events', type : 'feature', - description : 'enable event callbacks', - value : 'auto' -) - option('paranoid', type : 'feature', description : 'enable paranoid assertions', value : 'auto' @@ -130,11 +110,6 @@ option('analyze', type : 'feature', value : 'disabled' ) -option('win32_trickery', type : 'feature', - description : 'enable some slightly hacky win32 handling to speed up builds', - value : 'disabled' -) - option('stb_sprintf', type : 'feature', description : 'use stb_sprintf instead of the libc printf', value : 'auto' diff --git a/src/common/arena/include/arena/arena.h b/src/common/arena/include/arena/arena.h index df3aa853..dea3195f 100644 --- a/src/common/arena/include/arena/arena.h +++ b/src/common/arena/include/arena/arena.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include "core/analyze.h" #include "core/compiler.h" @@ -21,10 +22,6 @@ CT_BEGIN_API /// @ingroup common /// @{ -#ifdef WITH_DOXYGEN -# define CTU_TRACE_MEMORY 1 -#endif - /// @def CTU_TRACE_MEMORY /// @brief a compile time flag to enable memory tracing /// @note this is enabled by default in debug builds, see [The build guide](@ref building) for more information diff --git a/src/common/backtrace/src/dbghelp.c b/src/common/backtrace/src/dbghelp.c index bc39a1dd..707ed338 100644 --- a/src/common/backtrace/src/dbghelp.c +++ b/src/common/backtrace/src/dbghelp.c @@ -4,13 +4,6 @@ #include "core/macros.h" #include "core/win32.h" // IWYU pragma: keep - -#if CTU_WIN32_TRICKERY -# include -# include -# include -#endif - #include #define MAX_NAME_SIZE 512 diff --git a/src/common/base/include/base/panic.h b/src/common/base/include/base/panic.h index 988cfa01..bf8bd340 100644 --- a/src/common/base/include/base/panic.h +++ b/src/common/base/include/base/panic.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include "core/source_info.h" @@ -14,11 +15,6 @@ CT_BEGIN_API /// @ingroup base /// @{ -#ifdef WITH_DOXYGEN -# define CTU_DEBUG 1 -# define CTU_PARANOID 1 -#endif - /// @def CTU_DEBUG /// @brief enable panic handling /// @note this is only enabled in debug builds, see [The build guide](@ref building) for more diff --git a/src/common/core/include/core/win32.h b/src/common/core/include/core/win32.h index 60592296..971afa2f 100644 --- a/src/common/core/include/core/win32.h +++ b/src/common/core/include/core/win32.h @@ -15,30 +15,6 @@ #undef STRICT #undef VC_EXTRALEAN -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#define STRICT -#define VC_EXTRALEAN - -#if CTU_WIN32_TRICKERY -// prevents other headers from detecting if windows.h has already been included -// and then undoing our work here. its on the user to include this header first -// and any transitive includes that their code may have -# define _INC_WINDOWS -// detect amd64, x86, or arm and define them ourselves -# if defined(_M_IX86) -# define _X86_ -# elif defined(_M_AMD64) -# define _AMD64_ -# elif defined(_M_ARM) -# define _ARM_ -# elif defined(_M_ARM64) -# define _ARM64_ -# else -# error "Unknown architecture, disable win32 trickery or add your arch here" -# endif -#else -# include // IWYU pragma: export -#endif +#include // IWYU pragma: export /// @} diff --git a/src/common/endian/include/endian/endian.h b/src/common/endian/include/endian/endian.h index 096f6e3a..265125d6 100644 --- a/src/common/endian/include/endian/endian.h +++ b/src/common/endian/include/endian/endian.h @@ -15,10 +15,6 @@ #if CT_OS_WINDOWS # include "core/win32.h" // IWYU pragma: keep -# if CTU_WIN32_TRICKERY -# include -# include -# endif # define CT_BIG_ENDIAN REG_DWORD_BIG_ENDIAN # define CT_LITTLE_ENDIAN REG_DWORD_LITTLE_ENDIAN # define CT_BYTE_ORDER REG_DWORD diff --git a/src/common/fs/include/fs/fs.h b/src/common/fs/include/fs/fs.h index 68049617..a26ef37f 100644 --- a/src/common/fs/include/fs/fs.h +++ b/src/common/fs/include/fs/fs.h @@ -128,6 +128,18 @@ typedef void (*fs_dirent_callback_t)(const char *path, const char *name, os_dire CT_FS_API void fs_iter_dirents(fs_t *fs, const char *path, void *data, fs_dirent_callback_t callback); +CT_FS_API os_error_t fs_iter_begin( + IN_NOTNULL fs_t *fs, + IN_STRING const char *path, + OUT_NOTNULL fs_iter_t **iter); + +CT_FS_API os_error_t fs_iter_end( + IN_NOTNULL fs_iter_t *iter); + +CT_FS_API os_error_t fs_iter_next( + IN_NOTNULL fs_iter_t *iter, + OUT_NOTNULL fs_inode_t **inode); + /// @} CT_END_API diff --git a/src/common/fs/src/common.c b/src/common/fs/src/common.c index 4bd23395..d429bfec 100644 --- a/src/common/fs/src/common.c +++ b/src/common/fs/src/common.c @@ -53,22 +53,21 @@ bool inode_is(fs_inode_t *inode, os_dirent_t type) // helpers -os_error_t mkdir_recursive(const char *path, bool *create, arena_t *arena) +os_error_t mkdir_recursive(const char *path, arena_t *arena) { CTASSERT(path != NULL); - CTASSERT(create != NULL); size_t index = str_rfind(path, CT_NATIVE_PATH_SEPARATOR); if (index != SIZE_MAX) { // create parent directory char *parent = arena_strndup(path, index, arena); - os_error_t result = mkdir_recursive(parent, create, arena); - if (result != 0) { return result; } + os_error_t result = mkdir_recursive(parent, arena); + if (result != 0 && result != eOsExists) { return result; } } // create this directory - return os_dir_create(path, create); + return os_dir_create(path); } // fs api diff --git a/src/common/fs/src/common.h b/src/common/fs/src/common.h index 0281d615..bd217ded 100644 --- a/src/common/fs/src/common.h +++ b/src/common/fs/src/common.h @@ -65,7 +65,7 @@ CT_LOCAL void *inode_data(fs_inode_t *inode); CT_LOCAL bool inode_is(fs_inode_t *inode, os_dirent_t type); // helpers -CT_LOCAL os_error_t mkdir_recursive(const char *path, bool *success, arena_t *arena); +CT_LOCAL os_error_t mkdir_recursive(const char *path, arena_t *arena); // fs api diff --git a/src/common/fs/src/fs.c b/src/common/fs/src/fs.c index 6579018d..c76fe5b1 100644 --- a/src/common/fs/src/fs.c +++ b/src/common/fs/src/fs.c @@ -461,3 +461,30 @@ void fs_iter_dirents(fs_t *fs, const char *path, void *data, fs_dirent_callback_ iter_dirents(fs, query_inode(fs, fs->root, path), ".", path, data, callback); } + +USE_DECL +os_error_t fs_iter_begin(fs_t *fs, const char *path, fs_iter_t **iter) +{ + CTASSERT(fs != NULL); + CTASSERT(path != NULL); + CTASSERT(iter != NULL); + + return eOsSuccess; +} + +USE_DECL +os_error_t fs_iter_end(fs_iter_t *iter) +{ + CTASSERT(iter != NULL); + + return eOsSuccess; +} + +USE_DECL +os_error_t fs_iter_next(fs_iter_t *iter, fs_inode_t **inode) +{ + CTASSERT(iter != NULL); + CTASSERT(inode != NULL); + + return eOsSuccess; +} diff --git a/src/common/fs/src/physical.c b/src/common/fs/src/physical.c index ab9524a5..b36a250e 100644 --- a/src/common/fs/src/physical.c +++ b/src/common/fs/src/physical.c @@ -158,9 +158,8 @@ static inode_result_t pfs_file_create(fs_t *fs, fs_inode_t *self, const char *na static inode_result_t pfs_dir_create(fs_t *fs, fs_inode_t *self, const char *name) { const char *absolute = get_absolute(fs, self, name); - bool create = false; - os_error_t err = mkdir_recursive(absolute, &create, fs->arena); - if (err != eOsSuccess) + os_error_t err = mkdir_recursive(absolute, fs->arena); + if (err != eOsSuccess && err != eOsExists) { inode_result_t result = { .error = err }; return result; @@ -203,13 +202,9 @@ fs_t *fs_physical(const char *root, arena_t *arena) bool exist = os_dir_exists(root); if (exist) { - bool create = false; - os_error_t err = mkdir_recursive(root, &create, arena); - - // TODO: make this work recursively - CTASSERTF(err == 0, "error creating root directory: %s. %s", root, os_error_string(err, arena)); + os_error_t err = mkdir_recursive(root, arena); - if (!create) + if (err != eOsSuccess && err != eOsExists) { return NULL; } diff --git a/src/common/os/include/os/os.h b/src/common/os/include/os/os.h index eb3c79e0..54642955 100644 --- a/src/common/os/include/os/os.h +++ b/src/common/os/include/os/os.h @@ -118,11 +118,12 @@ CT_OS_API os_error_t os_file_delete(IN_STRING const char *path); /// @brief check if a directory exists /// /// @param path the path to the directory to check -/// @param create true if the directory was created, false if it already existed /// /// @return an error if the directory could not be checked +/// @retval eOsSuccess if the directory was created +/// @retval eOsExists if the directory already exists RET_INSPECT -CT_OS_API os_error_t os_dir_create(IN_STRING const char *path, OUT_NOTNULL bool *create); +CT_OS_API os_error_t os_dir_create(IN_STRING const char *path); /// @brief delete a directory /// @@ -330,27 +331,6 @@ CT_OS_API bool os_mapping_active(INOUT_NOTNULL const os_mapping_t *mapping); CT_NODISCARD CT_OS_API const char *os_file_name(INOUT_NOTNULL const os_file_t *file); -#if CTU_EVENTS - -typedef struct os_events_t -{ - void (*on_file_open)(const os_file_t *file); - void (*on_file_close)(const os_file_t *file); - void (*on_file_read)(const os_file_t *file, size_t size); - void (*on_file_write)(const os_file_t *file, size_t size); - - void (*on_library_open)(const os_library_t *library); - void (*on_library_close)(const os_library_t *library); - void (*on_library_symbol)(const os_library_t *library, const char *name, const os_symbol_t *symbol); - - void (*on_mapping_open)(const os_file_t *file, const os_mapping_t *mapping); - void (*on_mapping_close)(const os_mapping_t *mapping); -} os_events_t; - -CT_OS_API extern os_events_t gOsEvents; - -#endif - /// @} CT_END_API diff --git a/src/common/os/src/os.c b/src/common/os/src/os.c index ae86790d..dde1c709 100644 --- a/src/common/os/src/os.c +++ b/src/common/os/src/os.c @@ -144,8 +144,6 @@ os_error_t os_file_map(os_file_t *file, os_protect_t protect, size_t size, os_ma mapping->view = ptr; } - EVENT_MAPPING_OPEN(file, mapping); - return err; } @@ -154,8 +152,6 @@ os_error_t os_unmap(os_mapping_t *mapping) { CTASSERT(mapping != NULL); - EVENT_MAPPING_CLOSE(mapping); - return impl_unmap(mapping); } @@ -204,8 +200,6 @@ os_error_t os_library_open(const char *path, os_library_t *library) library->library = lib; library->name = path; - EVENT_LIBRARY_OPEN(library); - return eOsSuccess; } @@ -214,8 +208,6 @@ os_error_t os_library_close(os_library_t *library) { CTASSERT(library != NULL); - EVENT_LIBRARY_CLOSE(library); - if (!impl_library_close(library->library)) { return impl_last_error(); @@ -237,7 +229,6 @@ os_error_t os_library_symbol(os_library_t *library, os_symbol_t *symbol, const c } *symbol = addr; - EVENT_LIBRARY_SYMBOL(library, name, symbol); return eOsSuccess; } @@ -271,8 +262,6 @@ os_error_t os_file_open(const char *path, os_access_t access, os_file_t *file) file->file = fd; file->path = path; - EVENT_FILE_OPEN(file); - return eOsSuccess; } @@ -282,8 +271,6 @@ os_error_t os_file_close(os_file_t *fd) CTASSERT(fd != NULL); CTASSERTF(fd->file != CT_OS_INVALID_FILE, "invalid file handle (%s)", fd->path); - EVENT_FILE_CLOSE(fd); - if (!impl_file_close(fd)) { return impl_last_error(); diff --git a/src/common/os/src/os_common.c b/src/common/os/src/os_common.c index 38674a78..426ce5bd 100644 --- a/src/common/os/src/os_common.c +++ b/src/common/os/src/os_common.c @@ -4,10 +4,6 @@ #include "base/panic.h" -#if CTU_EVENTS -os_events_t gOsEvents = { 0 }; -#endif - static const char *const kDirentNames[eOsNodeCount] = { #define OS_DIRENT(ID, STR) [ID] = (STR), #include "os/os.inc" diff --git a/src/common/os/src/os_common.h b/src/common/os/src/os_common.h index abc49771..351812ce 100644 --- a/src/common/os/src/os_common.h +++ b/src/common/os/src/os_common.h @@ -10,28 +10,6 @@ typedef struct os_mapping_t os_mapping_t; CT_BEGIN_API -/// -/// event logging -/// - -#if CTU_EVENTS -# define EVENT_APPLY(fn, ...) do { if (gOsEvents.fn != NULL) gOsEvents.fn(__VA_ARGS__); } while (0) -#else -# define EVENT_APPLY(fn, ...) -#endif - -#define EVENT_FILE_OPEN(file) EVENT_APPLY(on_file_open, file) -#define EVENT_FILE_CLOSE(file) EVENT_APPLY(on_file_close, file) -#define EVENT_FILE_READ(file, size) EVENT_APPLY(on_file_read, file, size) -#define EVENT_FILE_WRITE(file, size) EVENT_APPLY(on_file_write, file, size) - -#define EVENT_LIBRARY_OPEN(lib) EVENT_APPLY(on_library_open, lib) -#define EVENT_LIBRARY_CLOSE(lib) EVENT_APPLY(on_library_close, lib) -#define EVENT_LIBRARY_SYMBOL(lib, name, sym) EVENT_APPLY(on_library_symbol, lib, name, sym) - -#define EVENT_MAPPING_OPEN(file, map) EVENT_APPLY(on_mapping_open, file, map) -#define EVENT_MAPPING_CLOSE(map) EVENT_APPLY(on_mapping_close, map) - /// /// provided by the platform implementation /// diff --git a/src/common/os/src/posix/file.c b/src/common/os/src/posix/file.c index 42d777fb..27eaeaf6 100644 --- a/src/common/os/src/posix/file.c +++ b/src/common/os/src/posix/file.c @@ -95,8 +95,6 @@ os_error_t os_file_read(os_file_t *file, void *buffer, size_t size, size_t *actu } } - EVENT_FILE_READ(file, read); - *actual = read; return 0; } @@ -119,8 +117,6 @@ os_error_t os_file_write(os_file_t *file, const void *buffer, size_t size, size_ } } - EVENT_FILE_WRITE(file, written); - *actual = written; return errno; } diff --git a/src/common/os/src/posix/fs.c b/src/common/os/src/posix/fs.c index 212c5b3e..e4d31343 100644 --- a/src/common/os/src/posix/fs.c +++ b/src/common/os/src/posix/fs.c @@ -26,31 +26,26 @@ os_error_t os_file_delete(const char *path) } USE_DECL -os_error_t os_dir_create(const char *path, bool *create) +os_error_t os_dir_create(const char *path) { CTASSERT(path != NULL); - CTASSERT(create != NULL); // TODO: this is a bit of a hack to avoid a bug in mkdir_recursive // on linux it will pass an empty string into mkdir because of the leading `/` if (ctu_strlen(path) == 0) { - *create = true; - return 0; + return eOsSuccess; } if (mkdir(path, 0777) != 0) { - if (errno != EEXIST) + if (errno == EEXIST) { - return errno; + return eOsExists; } - - errno = 0; } - *create = (errno == 0); - return 0; + return errno; } USE_DECL diff --git a/src/common/os/src/windows/dir.c b/src/common/os/src/windows/dir.c index bddd7b1c..3fc50080 100644 --- a/src/common/os/src/windows/dir.c +++ b/src/common/os/src/windows/dir.c @@ -10,10 +10,6 @@ #include "std/str.h" -#if CTU_WIN32_TRICKERY -# include -#endif - static BOOL find_next(HANDLE handle, WIN32_FIND_DATA *data, DWORD *error) { BOOL result = FindNextFileA(handle, data); diff --git a/src/common/os/src/windows/error.c b/src/common/os/src/windows/error.c index f8186410..5c697823 100644 --- a/src/common/os/src/windows/error.c +++ b/src/common/os/src/windows/error.c @@ -9,11 +9,6 @@ #include "core/win32.h" // IWYU pragma: keep -#if CTU_WIN32_TRICKERY -# include -# include -#endif - #define FORMAT_FLAGS (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS) os_error_t impl_last_error(void) diff --git a/src/common/os/src/windows/file.c b/src/common/os/src/windows/file.c index 3f85b94e..2792eafa 100644 --- a/src/common/os/src/windows/file.c +++ b/src/common/os/src/windows/file.c @@ -7,14 +7,6 @@ #include -#if CTU_WIN32_TRICKERY -# include -# include -# include -# include -# include -#endif - os_error_t impl_copyfile(const char *dst, const char *src) { CTASSERT(dst != NULL); @@ -139,8 +131,6 @@ os_error_t os_file_read(os_file_t *file, void *buffer, size_t size, size_t *actu return GetLastError(); } - EVENT_FILE_READ(file, read); - *actual = read; return 0; } @@ -163,8 +153,6 @@ os_error_t os_file_write(os_file_t *file, const void *buffer, size_t size, size_ return GetLastError(); } - EVENT_FILE_WRITE(file, written); - *actual = written; return ERROR_SUCCESS; } diff --git a/src/common/os/src/windows/fs.c b/src/common/os/src/windows/fs.c index d0df9451..b753832b 100644 --- a/src/common/os/src/windows/fs.c +++ b/src/common/os/src/windows/fs.c @@ -6,14 +6,6 @@ #include "os/os.h" -#if CTU_WIN32_TRICKERY -# include -# include -# include -# include -# include -#endif - USE_DECL os_error_t os_file_delete(const char *path) { @@ -28,25 +20,23 @@ os_error_t os_file_delete(const char *path) } USE_DECL -os_error_t os_dir_create(const char *path, bool *create) +os_error_t os_dir_create(const char *path) { CTASSERT(path != NULL); - CTASSERT(create != NULL); bool result = CreateDirectoryA(path, NULL); if (!result) { DWORD error = GetLastError(); - if (error != ERROR_ALREADY_EXISTS) + if (error == ERROR_ALREADY_EXISTS) { - return error; + return eOsExists; } - result = true; + return error; } - *create = result; - return 0; + return eOsSuccess; } USE_DECL diff --git a/src/common/os/src/windows/init.c b/src/common/os/src/windows/init.c index 368698c7..0e161a42 100644 --- a/src/common/os/src/windows/init.c +++ b/src/common/os/src/windows/init.c @@ -8,12 +8,6 @@ #include "core/win32.h" // IWYU pragma: keep -#if CTU_WIN32_TRICKERY -# include -# include -# include -#endif - size_t impl_maxname(void) { return MAX_PATH; diff --git a/src/common/os/src/windows/library.c b/src/common/os/src/windows/library.c index f3602cff..60a931da 100644 --- a/src/common/os/src/windows/library.c +++ b/src/common/os/src/windows/library.c @@ -2,10 +2,6 @@ #include "os_common.h" -#if CTU_WIN32_TRICKERY -# include -#endif - os_library_impl_t impl_library_open(const char *path) { return LoadLibraryA(path); diff --git a/src/frontend/gui/editor/include/editor/panels/events.hpp b/src/frontend/gui/editor/include/editor/panels/events.hpp deleted file mode 100644 index 12df3a74..00000000 --- a/src/frontend/gui/editor/include/editor/panels/events.hpp +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -#pragma once - -#include "editor/panels/panel.hpp" - -namespace ed -{ - void init_events(); - IEditorPanel *create_events_panel(); -} diff --git a/src/frontend/gui/editor/include/editor/panels/settings.hpp b/src/frontend/gui/editor/include/editor/panels/settings.hpp deleted file mode 100644 index 9bb9fda4..00000000 --- a/src/frontend/gui/editor/include/editor/panels/settings.hpp +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -#pragma once - -#include "editor/panels/panel.hpp" - -namespace ed -{ - class SettingsPanel final : IEditorPanel - { - // IEditorPanel - void draw_content() override; - - public: - SettingsPanel(); - }; -} diff --git a/src/frontend/gui/editor/include/editor/panels/theme.hpp b/src/frontend/gui/editor/include/editor/panels/theme.hpp new file mode 100644 index 00000000..eb144bf0 --- /dev/null +++ b/src/frontend/gui/editor/include/editor/panels/theme.hpp @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +#include "editor/panels/panel.hpp" + +namespace ed +{ + IEditorPanel *dark_theme(); + IEditorPanel *light_theme(); + IEditorPanel *classic_theme(); +} diff --git a/src/frontend/gui/editor/meson.build b/src/frontend/gui/editor/meson.build index 83df15e8..d06e2982 100644 --- a/src/frontend/gui/editor/meson.build +++ b/src/frontend/gui/editor/meson.build @@ -9,8 +9,7 @@ src = [ 'src/panels/info.cpp', 'src/panels/arena.cpp', 'src/panels/demo.cpp', - 'src/panels/settings.cpp', - 'src/panels/events.cpp', + 'src/panels/theme.cpp', 'src/utils/io.cpp', diff --git a/src/frontend/gui/editor/src/main.cpp b/src/frontend/gui/editor/src/main.cpp index b489e557..f31f75b9 100644 --- a/src/frontend/gui/editor/src/main.cpp +++ b/src/frontend/gui/editor/src/main.cpp @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0-only -#include "editor/panels/events.hpp" +#include "editor/panels/theme.hpp" #include "stdafx.hpp" // drawing library @@ -27,11 +27,8 @@ #include "support/support.h" #include "memory/memory.h" -#include "interop/compile.h" #include "config/config.h" -#include "io/io.h" - #include "std/typed/vector.h" #include "core/macros.h" @@ -55,76 +52,24 @@ static ed::TraceArena gGlobalArena{"Global Arena", ed::TraceArena::eDrawTree, tr static ed::TraceArena gGmpArena{"GMP Arena", ed::TraceArena::eDrawFlat, true}; static ed::TraceArena gGuiArena{"Dear ImGui Arena", ed::TraceArena::eDrawTree, false}; -namespace ed +static void *imgui_malloc(size_t size, void *user) { - static void *imgui_malloc(size_t size, void *user) - { - arena_t *arena = reinterpret_cast(user); - return ARENA_OPT_MALLOC(size, "ImGui::MemAlloc", NULL, arena); - } - - static void imgui_free(void *ptr, void *user) - { - arena_t *arena = reinterpret_cast(user); - arena_opt_free(ptr, CT_ALLOC_SIZE_UNKNOWN, arena); - } - - void install_trace_arenas() - { - init_global_arena(gGlobalArena.get_arena()); - init_gmp_arena(gGmpArena.get_arena()); - ImGui::SetAllocatorFunctions(imgui_malloc, imgui_free, gGuiArena.get_arena()); - } + arena_t *arena = reinterpret_cast(user); + return ARENA_OPT_MALLOC(size, "ImGui::MemAlloc", NULL, arena); } -class SourceCode +static void imgui_free(void *ptr, void *user) { - io_t *io = nullptr; - const char *path = nullptr; - const char *text = nullptr; - size_t size = 0; - - io_error_t error = 0; - char *str = nullptr; - bool open = true; - - void init() - { - path = io_name(io); - - size = io_size(io); - text = (char*)io_map(io, eOsProtectRead); - - error = io_error(io); - if (error) - { - str = os_error_string(error, get_global_arena()); - } - } -public: - SourceCode(io_t *io) - : io(io) - { - init(); - } - - void draw_body() - { - if (ImGui::BeginTabItem(path, &open, ImGuiTabItemFlags_None)) - { - if (error) - { - ImGui::TextColored(ImVec4(1.f, 0.f, 0.f, 1.f), "Error: %s", str); - } - else - { - ImGui::TextWrapped("%s", text); - } + arena_t *arena = reinterpret_cast(user); + arena_opt_free(ptr, CT_ALLOC_SIZE_UNKNOWN, arena); +} - ImGui::EndTabItem(); - } - } -}; +static void install_trace_arenas() +{ + init_global_arena(gGlobalArena.get_arena()); + init_gmp_arena(gGmpArena.get_arena()); + ImGui::SetAllocatorFunctions(imgui_malloc, imgui_free, gGuiArena.get_arena()); +} class EditorModulePanel : public ed::IEditorPanel { @@ -331,51 +276,6 @@ class DynamicModulePanel final : public ed::IEditorPanel } }; -enum theme_t { - eThemeDark, - eThemeLight, - eThemeClassic, - - eThemeCount -}; - -static theme_t gTheme = eThemeDark; - -template -class ThemeMenuItem final : public ed::IEditorPanel -{ - theme_t theme; - F func; - -public: - ThemeMenuItem(const char *name, theme_t theme, F&& func) - : IEditorPanel(name) - , theme(theme) - , func(std::forward(func)) - { } - - bool is_selected() const - { - return gTheme == theme; - } - - bool menu_item(const char *) override - { - bool result = ImGui::MenuItem(get_title(), nullptr, is_selected(), !is_selected()); - if (result) - { - gTheme = theme; - func(); - } - return result; - } -}; - -static ed::IEditorPanel *theme_menu(const char *name, theme_t theme, auto&& func) -{ - return new ThemeMenuItem(name, theme, std::forward(func)); -} - void draw_menu_items(ed::menu_section_t& section) { for (ed::IEditorPanel *panel : section.panels) @@ -436,10 +336,6 @@ class EditorUi .name = "Memory", .panels = { &gGlobalArena, &gGmpArena, &gGuiArena } }, - ed::menu_section_t { - .name = "Events", - .panels = { ed::create_events_panel() } - }, ed::menu_section_t { .name = "Demo", .panels = { ed::create_imgui_demo_panel(), ed::create_implot_demo_panel() } @@ -450,9 +346,9 @@ class EditorUi ed::menu_t styles_menu = { .name = "Styles", .header = { - theme_menu("Dark", eThemeDark, []() { ImGui::StyleColorsDark(); ImPlot::StyleColorsDark(); }), - theme_menu("Light", eThemeLight, []() { ImGui::StyleColorsLight(); ImPlot::StyleColorsLight(); }), - theme_menu("Classic", eThemeClassic, []() { ImGui::StyleColorsClassic(); ImPlot::StyleColorsClassic(); }), + ed::dark_theme(), + ed::light_theme(), + ed::classic_theme(), } }; @@ -669,8 +565,7 @@ int main(int argc, const char **argv) CT_UNUSED(argv); setup_global(); - ed::install_trace_arenas(); - ed::init_events(); + install_trace_arenas(); draw::config_t config = { .title = L"Editor", diff --git a/src/frontend/gui/editor/src/panels/events.cpp b/src/frontend/gui/editor/src/panels/events.cpp deleted file mode 100644 index bc7e4624..00000000 --- a/src/frontend/gui/editor/src/panels/events.cpp +++ /dev/null @@ -1,423 +0,0 @@ -#include "editor/utils.hpp" -#include "stdafx.hpp" - -#include "editor/panels/events.hpp" - -#include "os/os.h" - -#if CTU_EVENTS - -struct file_event_t -{ - enum { eOpen, eClose, eRead, eWrite } type; - size_t size; -}; - -static const char *file_event_name(int type) -{ - switch (type) - { - case file_event_t::eOpen: return "Open"; - case file_event_t::eClose: return "Close"; - case file_event_t::eRead: return "Read"; - case file_event_t::eWrite: return "Write"; - default: return "Unknown"; - } -} - -struct library_event_t -{ - enum { eOpen, eClose, eSymbol } type; - - std::string name; - const os_symbol_t *sym; -}; - -static const char *library_event_name(int type) -{ - switch (type) - { - case library_event_t::eOpen: return "Open"; - case library_event_t::eClose: return "Close"; - case library_event_t::eSymbol: return "Symbol"; - default: return "Unknown"; - } -} - -template -struct tracked_t -{ - using object_t = T; - const T *object; - - const T *get_object() const - { - return object; - } -}; - -struct file_info_t : tracked_t -{ - std::string path; - std::vector events; - std::unordered_set mappings; -}; - -struct library_info_t : tracked_t -{ - std::string path; - std::vector events; -}; - -struct mapping_info_t : tracked_t -{ - size_t file; - size_t size; - bool active = true; -}; - -template -concept Tracked = requires(const T t) -{ - typename T::object_t; - { t.get_object() } -> std::same_as; -}; - -template -struct tracker_t -{ - using object_t = typename T::object_t; - - std::vector data; - std::unordered_map lookup; - - T &get(const object_t *object) - { - return data[lookup[object]]; - } - - T& add(const T &value) - { - lookup[value.get_object()] = data.size(); - return data.emplace_back(value); - } -}; - -static size_t gActiveMemory = SIZE_MAX; -static MemoryEditor gMemoryEditor; - -static tracker_t gFiles; -static tracker_t gLibraries; -static tracker_t gMappings; - -static void on_file_open(const os_file_t *file) -{ - auto& it = gFiles.add({ {file}, os_file_name(file) }); - it.events.push_back({ file_event_t::eOpen }); -} - -static void on_file_close(const os_file_t *file) -{ - gFiles.get(file).events.push_back({ file_event_t::eClose }); -} - -static void on_file_read(const os_file_t *file, size_t size) -{ - gFiles.get(file).events.push_back({ file_event_t::eRead, size }); -} - -static void on_file_write(const os_file_t *file, size_t size) -{ - gFiles.get(file).events.push_back({ file_event_t::eWrite, size }); -} - -static void on_library_open(const os_library_t *lib) -{ - gLibraries.add({ {lib}, os_library_name(lib) }); -} - -static void on_library_close(const os_library_t *lib) -{ - gLibraries.get(lib).events.push_back({ library_event_t::eClose }); -} - -static void on_library_symbol(const os_library_t *lib, const char *name, const os_symbol_t *sym) -{ - gLibraries.get(lib).events.push_back({ library_event_t::eSymbol, name, sym }); -} - -static void on_mapping_open(const os_file_t *file, const os_mapping_t *map) -{ - auto& fd = gFiles.get(file); - gMappings.add({ {map}, gFiles.lookup[file], os_mapping_size(map) }); - fd.mappings.insert(map); -} - -static void on_mapping_close(const os_mapping_t *map) -{ - gMappings.get(map).active = false; -} - -static const ImGuiTreeNodeFlags kGroupNodeFlags - = ImGuiTreeNodeFlags_SpanAllColumns - | ImGuiTreeNodeFlags_AllowOverlap; - -static const ImGuiTreeNodeFlags kValueNodeFlags - = kGroupNodeFlags - | ImGuiTreeNodeFlags_Leaf - | ImGuiTreeNodeFlags_Bullet - | ImGuiTreeNodeFlags_NoTreePushOnOpen; - -static const ImGuiTableFlags kTraceTableFlags - = ImGuiTableFlags_BordersV - | ImGuiTableFlags_BordersOuterH - | ImGuiTableFlags_Resizable - | ImGuiTableFlags_RowBg - | ImGuiTableFlags_NoHostExtendX - | ImGuiTableFlags_NoBordersInBody; - -static void draw_files() -{ - if (ImGui::BeginTable("Files", 3, kTraceTableFlags)) - { - ImGui::TableSetupColumn("Path"); - ImGui::TableSetupColumn("Events"); - ImGui::TableSetupColumn("Mappings"); - ImGui::TableHeadersRow(); - - for (const auto &file : gFiles.data) - { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - bool is_open = ImGui::TreeNodeEx(file.path.c_str(), kGroupNodeFlags); - - ImGui::TableNextColumn(); - ImGui::Text("%zu", file.events.size()); - - ImGui::TableNextColumn(); - ImGui::Text("%zu", file.mappings.size()); - - if (is_open) - { - for (const auto& event : file.events) - { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - - ImGui::TreeNodeEx(&event, kValueNodeFlags, "%s", file_event_name(event.type)); - - ImGui::TableNextColumn(); - if (event.type == file_event_t::eRead || event.type == file_event_t::eWrite) - { - ImGui::Text("%zu", event.size); - } - else - { - ImGui::TextUnformatted(""); - } - - ImGui::TableNextColumn(); - ImGui::TextUnformatted(""); - } - - ImGui::TreePop(); - } - } - - ImGui::EndTable(); - } -} - -static void draw_libraries() -{ - if (ImGui::BeginTable("Libraries", 2, kTraceTableFlags)) - { - ImGui::TableSetupColumn("Name"); - ImGui::TableSetupColumn("Events"); - ImGui::TableHeadersRow(); - - for (const auto &lib : gLibraries.data) - { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - bool is_open = ImGui::TreeNodeEx(lib.path.c_str(), kGroupNodeFlags); - - ImGui::TableNextColumn(); - ImGui::Text("%zu", lib.events.size()); - - if (is_open) - { - for (const auto& event : lib.events) - { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - - ImGui::TreeNodeEx(&event, kValueNodeFlags, "%s", library_event_name(event.type)); - - ImGui::TableNextColumn(); - if (event.type == library_event_t::eSymbol) - { - ImGui::Text("%s", event.name.c_str()); - ImGui::SetItemTooltip("%p", (void*)event.sym); - } - else - { - ImGui::TextUnformatted(""); - } - } - - ImGui::TreePop(); - } - } - - ImGui::EndTable(); - } -} - -static void draw_mappings() -{ - if (ImGui::BeginTable("Mappings", 3, kTraceTableFlags)) - { - ImGui::TableSetupColumn("Name"); - ImGui::TableSetupColumn("Details"); - ImGui::TableSetupColumn("Memory"); - ImGui::TableHeadersRow(); - - for (const auto &mapping : gMappings.data) - { - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - const auto& file = gFiles.data[mapping.file]; - ImGui::Text("%s", file.path.c_str()); - - ImGui::TableNextColumn(); - ImGui::Text("%zu bytes (%s)", mapping.size, mapping.active ? "active" : "inactive"); - - ImGui::TableNextColumn(); - if (mapping.active) - { - auto label = ed::strfmt<256>("%p", os_mapping_data((os_mapping_t*)mapping.get_object())); - if (ImGui::Button(label)) - { - gActiveMemory = gMappings.lookup[mapping.get_object()]; - } - } - else - { - ImGui::TextDisabled("Inactive"); - } - } - - ImGui::EndTable(); - } -} - -class EventsPanel final : public ed::IEditorPanel -{ - void draw_events() - { - ImGui::Text("%zu files | %zu libraries | %zu mappings", gFiles.data.size(), gLibraries.data.size(), gMappings.data.size()); - - ImGui::Separator(); - - if (ImGui::BeginTabBar("Trackers")) - { - if (ImGui::BeginTabItem("Files")) - { - draw_files(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Libraries")) - { - draw_libraries(); - ImGui::EndTabItem(); - } - - if (ImGui::BeginTabItem("Mappings")) - { - draw_mappings(); - ImGui::EndTabItem(); - } - ImGui::EndTabBar(); - } - } - -public: - EventsPanel() : IEditorPanel("Events") { } - - void draw_content() override - { - draw_events(); - } - - void update() override - { - if (gActiveMemory == SIZE_MAX) - return; - - const auto& mapping = gMappings.data[gActiveMemory]; - if (!mapping.active) - { - gActiveMemory = SIZE_MAX; - return; - } - - bool open = true; - if (ImGui::Begin("Memory Editor", &open)) - { - gMemoryEditor.DrawContents(os_mapping_data((os_mapping_t*)mapping.get_object()), mapping.size); - } - ImGui::End(); - - if (!open) - { - gActiveMemory = SIZE_MAX; - } - } -}; - -void ed::init_events() -{ - os_events_t events = { - .on_file_open = on_file_open, - .on_file_close = on_file_close, - .on_file_read = on_file_read, - .on_file_write = on_file_write, - - .on_library_open = on_library_open, - .on_library_close = on_library_close, - .on_library_symbol = on_library_symbol, - - .on_mapping_open = on_mapping_open, - .on_mapping_close = on_mapping_close, - }; - - gOsEvents = events; -} - -#else - -void ed::init_events() -{ - -} - -class EventsPanel final : public ed::IEditorPanel -{ -public: - EventsPanel() - : IEditorPanel("Events") - { - disable("Events are disabled, reconfigure with -Devents=enabled"); - } - - void draw_content() override { } -}; - -#endif - -ed::IEditorPanel *ed::create_events_panel() -{ - return new EventsPanel(); -} diff --git a/src/frontend/gui/editor/src/panels/settings.cpp b/src/frontend/gui/editor/src/panels/settings.cpp deleted file mode 100644 index 49601373..00000000 --- a/src/frontend/gui/editor/src/panels/settings.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-only -#include "editor/panels/settings.hpp" - -using namespace ed; - -void SettingsPanel::draw_content() -{ - ImGui::Text("Display"); -} - -SettingsPanel::SettingsPanel() - : IEditorPanel("Settings") -{ } diff --git a/src/frontend/gui/editor/src/panels/theme.cpp b/src/frontend/gui/editor/src/panels/theme.cpp new file mode 100644 index 00000000..f14c8857 --- /dev/null +++ b/src/frontend/gui/editor/src/panels/theme.cpp @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +#include "stdafx.hpp" + +#include "editor/panels/theme.hpp" + +enum theme_t { + eThemeDark, + eThemeLight, + eThemeClassic, + + eThemeCount +}; + +static theme_t gTheme = eThemeDark; + +template +class ThemeMenuItem final : public ed::IEditorPanel +{ + theme_t theme; + F func; + +public: + ThemeMenuItem(const char *name, theme_t theme, F&& func) + : IEditorPanel(name) + , theme(theme) + , func(std::forward(func)) + { } + + bool is_selected() const + { + return gTheme == theme; + } + + bool menu_item(const char *) override + { + bool result = ImGui::MenuItem(get_title(), nullptr, is_selected(), !is_selected()); + if (result) + { + gTheme = theme; + func(); + } + return result; + } +}; + +static ed::IEditorPanel *theme_menu(const char *name, theme_t theme, auto&& func) +{ + return new ThemeMenuItem(name, theme, std::forward(func)); +} + +ed::IEditorPanel *ed::dark_theme() +{ + return theme_menu("Dark", eThemeDark, [] { + ImGui::StyleColorsDark(); + ImPlot::StyleColorsDark(); + }); +} + +ed::IEditorPanel *ed::light_theme() +{ + return theme_menu("Light", eThemeLight, [] { + ImGui::StyleColorsLight(); + ImPlot::StyleColorsLight(); + }); +} + +ed::IEditorPanel *ed::classic_theme() +{ + return theme_menu("Classic", eThemeClassic, [] { + ImGui::StyleColorsClassic(); + ImPlot::StyleColorsClassic(); + }); +} diff --git a/src/language/README.md b/src/language/README.md deleted file mode 100644 index 4e12fd63..00000000 --- a/src/language/README.md +++ /dev/null @@ -1,87 +0,0 @@ -# Language driver layout - -all drivers must conform to the same dir structure - -* driver_name/ - * src/ - * include/ - * meson.build - -## Example module - -```c -// src/main.c - -/// default language extensions, must be null terminated -static const char *const kLangNames[] = CT_LANG_EXTS("e", "example"); - -/// exported driver module -const language_t kExampleModule = { - /// the internal name of the driver - .id = "example", - - /// the human visible name of the driver - .name = "Example", - - /// version information - .version = { - .license = "GPLv3", - .desc = "Example language driver", - .author = "Elliot Haisley", - .version = CT_NEW_VERSION(1, 0, 1) - }, - - /// default extensions - .exts = kLangNames, - - /// first time creation function, initialize from gathered config - .fn_create = ex_create, - - /// final teardown function, clean up memory created during init and runs - .fn_destroy = ex_destroy, - - /// parse an io handle into an ast - .fn_parse = ex_parse, - - /// register available passes - .fn_compile_passes = { - /// forward symbols to opt in to order independant lookup - /// across languages - [eStageForwardSymbols] = ex_forward_symbols, - - /// process imports for a translation unit - [eStageCompileImports] = ex_compile_imports, - - /// compile any types that need early compilation - [eStageCompileTypes] = ex_compile_types, - - /// finish compiling symbols into complete trees - [eStageCompileSymbols] = ex_compile_symbols - } -}; -``` - -## Build file requirements - -to be detected by interfaces each build file must add itself to `langs` - -```py -# meson.build -src = [ 'src/main.c' ] - -libexample = library('example', src, - dependencies : [ broker, interop, tree ], - c_args : user_args, - include_directories : [ 'src' ] -) - -langs += { - 'example': { - 'dep': declare_dependency(link_with : libexample), # dependency object - 'mod': 'kExampleModule', # module definition exported from the object - - # an optional fuzz corpus to opt in to fuzzing tools - 'fuzz_corpus': meson.current_source_dir() / 'fuzz_corpus' - } -} -``` diff --git a/src/language/meson.build b/src/language/meson.build index b5ac751c..6d640090 100644 --- a/src/language/meson.build +++ b/src/language/meson.build @@ -1,11 +1,3 @@ -if lang_cpp.allowed() - subdir('c_family/pre') -endif - -if lang_c.allowed() - subdir('c_family/lang') -endif - if lang_ctu.allowed() subdir('ctu') endif @@ -18,10 +10,6 @@ if lang_oberon.allowed() subdir('oberon') endif -if lang_jvm.allowed() - subdir('jvm') -endif - if lang_example.allowed() subdir('example') endif diff --git a/src/tools/harness/main.c b/src/tools/harness/main.c index 4f1f8d01..d3d3e117 100644 --- a/src/tools/harness/main.c +++ b/src/tools/harness/main.c @@ -345,9 +345,8 @@ int run_test_harness(int argc, const char **argv, arena_t *arena) #if CT_OS_WINDOWS const char *lib_dir = str_format(arena, "%s" CT_NATIVE_PATH_SEPARATOR "lib", run_dir); - bool create = false; - os_error_t cwd_err = os_dir_create(lib_dir, &create); - CTASSERTF(cwd_err == 0, "failed to create dir `%s` %s", lib_dir, os_error_string(cwd_err, arena)); + os_error_t cwd_err = os_dir_create(lib_dir); + CTASSERTF(cwd_err == eOsExists || cwd_err == eOsSuccess, "failed to create dir `%s` %s", lib_dir, os_error_string(cwd_err, arena)); char *cmd = str_format(arena, "cl /nologo /c %s /I%s\\include /Fo%s\\", str_join(" ", sources, arena), run_dir, lib_dir); int status = system(cmd); // NOLINT diff --git a/src/language/c_family/lang/data/modules.h b/todo/c_family/lang/data/modules.h similarity index 100% rename from src/language/c_family/lang/data/modules.h rename to todo/c_family/lang/data/modules.h diff --git a/src/language/c_family/lang/include/c/ast.h b/todo/c_family/lang/include/c/ast.h similarity index 100% rename from src/language/c_family/lang/include/c/ast.h rename to todo/c_family/lang/include/c/ast.h diff --git a/src/language/c_family/lang/include/c/ast.inc b/todo/c_family/lang/include/c/ast.inc similarity index 100% rename from src/language/c_family/lang/include/c/ast.inc rename to todo/c_family/lang/include/c/ast.inc diff --git a/src/language/c_family/lang/include/c/driver.h b/todo/c_family/lang/include/c/driver.h similarity index 100% rename from src/language/c_family/lang/include/c/driver.h rename to todo/c_family/lang/include/c/driver.h diff --git a/src/language/c_family/lang/include/c/events.inc b/todo/c_family/lang/include/c/events.inc similarity index 100% rename from src/language/c_family/lang/include/c/events.inc rename to todo/c_family/lang/include/c/events.inc diff --git a/src/language/c_family/lang/include/c/scan.h b/todo/c_family/lang/include/c/scan.h similarity index 100% rename from src/language/c_family/lang/include/c/scan.h rename to todo/c_family/lang/include/c/scan.h diff --git a/src/language/c_family/lang/include/c/sema/sema.h b/todo/c_family/lang/include/c/sema/sema.h similarity index 100% rename from src/language/c_family/lang/include/c/sema/sema.h rename to todo/c_family/lang/include/c/sema/sema.h diff --git a/src/language/c_family/lang/meson.build b/todo/c_family/lang/meson.build similarity index 100% rename from src/language/c_family/lang/meson.build rename to todo/c_family/lang/meson.build diff --git a/src/language/c_family/lang/src/ast.c b/todo/c_family/lang/src/ast.c similarity index 100% rename from src/language/c_family/lang/src/ast.c rename to todo/c_family/lang/src/ast.c diff --git a/src/language/c_family/lang/src/cc.l b/todo/c_family/lang/src/cc.l similarity index 100% rename from src/language/c_family/lang/src/cc.l rename to todo/c_family/lang/src/cc.l diff --git a/src/language/c_family/lang/src/cc.y b/todo/c_family/lang/src/cc.y similarity index 100% rename from src/language/c_family/lang/src/cc.y rename to todo/c_family/lang/src/cc.y diff --git a/src/language/c_family/lang/src/driver.c b/todo/c_family/lang/src/driver.c similarity index 100% rename from src/language/c_family/lang/src/driver.c rename to todo/c_family/lang/src/driver.c diff --git a/src/language/c_family/lang/src/events.c b/todo/c_family/lang/src/events.c similarity index 100% rename from src/language/c_family/lang/src/events.c rename to todo/c_family/lang/src/events.c diff --git a/src/language/c_family/lang/src/main.c b/todo/c_family/lang/src/main.c similarity index 100% rename from src/language/c_family/lang/src/main.c rename to todo/c_family/lang/src/main.c diff --git a/src/language/c_family/lang/src/scan.c b/todo/c_family/lang/src/scan.c similarity index 100% rename from src/language/c_family/lang/src/scan.c rename to todo/c_family/lang/src/scan.c diff --git a/src/language/c_family/pre/include/pre/scan.h b/todo/c_family/pre/include/pre/scan.h similarity index 100% rename from src/language/c_family/pre/include/pre/scan.h rename to todo/c_family/pre/include/pre/scan.h diff --git a/src/language/c_family/pre/meson.build b/todo/c_family/pre/meson.build similarity index 100% rename from src/language/c_family/pre/meson.build rename to todo/c_family/pre/meson.build diff --git a/src/language/c_family/pre/src/main.c b/todo/c_family/pre/src/main.c similarity index 100% rename from src/language/c_family/pre/src/main.c rename to todo/c_family/pre/src/main.c diff --git a/src/language/c_family/pre/src/pre.l b/todo/c_family/pre/src/pre.l similarity index 100% rename from src/language/c_family/pre/src/pre.l rename to todo/c_family/pre/src/pre.l diff --git a/src/language/c_family/pre/src/scan.c b/todo/c_family/pre/src/scan.c similarity index 100% rename from src/language/c_family/pre/src/scan.c rename to todo/c_family/pre/src/scan.c diff --git a/src/language/jvm/include/jvm/jvm.h b/todo/jvm/include/jvm/jvm.h similarity index 100% rename from src/language/jvm/include/jvm/jvm.h rename to todo/jvm/include/jvm/jvm.h diff --git a/src/language/jvm/include/jvm/jvm.inc b/todo/jvm/include/jvm/jvm.inc similarity index 100% rename from src/language/jvm/include/jvm/jvm.inc rename to todo/jvm/include/jvm/jvm.inc diff --git a/src/language/jvm/main.c b/todo/jvm/main.c similarity index 100% rename from src/language/jvm/main.c rename to todo/jvm/main.c diff --git a/src/language/jvm/meson.build b/todo/jvm/meson.build similarity index 100% rename from src/language/jvm/meson.build rename to todo/jvm/meson.build diff --git a/src/language/jvm/src/jvm/jvm.c b/todo/jvm/src/jvm/jvm.c similarity index 100% rename from src/language/jvm/src/jvm/jvm.c rename to todo/jvm/src/jvm/jvm.c