From 9f7e70904e6c0fa650323ac5e50ebf6003da333c Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Tue, 24 Feb 2026 01:33:45 +0100 Subject: Removes usage of Jinja templates Use CPP to pre-process C files instead --- ui/daemon/ui.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ ui/daemon/ui.j2.c | 86 ---------------------------------------------------- ui/daemon/ui_vars.py | 10 +++--- 3 files changed, 84 insertions(+), 91 deletions(-) create mode 100644 ui/daemon/ui.c delete mode 100644 ui/daemon/ui.j2.c (limited to 'ui/daemon') diff --git a/ui/daemon/ui.c b/ui/daemon/ui.c new file mode 100644 index 0000000..1f6c35c --- /dev/null +++ b/ui/daemon/ui.c @@ -0,0 +1,79 @@ +volatile bool g_running; +uint64_t g_step_block; + +void info_impl(const char *restrict fmt, ...) { + assert(fmt); + printf("\033[1;34m[INFO]\033[0m "); + + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + + printf("\n"); +} + +void warn_impl(const char *restrict fmt, ...) { + assert(fmt); + printf("\033[1;33m[WARN]\033[0m "); + + va_list args; + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + + printf("\n"); +} + +void sig_handler(int signo) { + (void)signo; + + if (g_running) { + g_warn("Signal received, will stop simulator soon..."); + g_running = false; + } +} + +void step_block() { + clock_t beg = clock(); + salis_step(g_step_block - (g_steps % g_step_block)); + clock_t end = clock(); + + if ((end - beg) < (CLOCKS_PER_SEC * 4)) { + g_step_block <<= 1; + } + + if ((end - beg) >= (CLOCKS_PER_SEC * 2) && g_step_block != 1) { + g_step_block >>= 1; + } + + g_info("Simulator running on step '%#lx'", g_steps); +} + +int main() { + g_info = info_impl; + g_warn = warn_impl; + +#if defined(COMMAND_NEW) + salis_init(); +#elif defined(COMMAND_LOAD) + salis_load(); +#endif + + g_running = true; + g_step_block = 1; + + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); + + while (g_running) { + step_block(); + } + + g_info("Saving simulation..."); + salis_save(SIM_PATH); + salis_free(); + + g_info("Exiting salis..."); + return 0; +} diff --git a/ui/daemon/ui.j2.c b/ui/daemon/ui.j2.c deleted file mode 100644 index 02df79b..0000000 --- a/ui/daemon/ui.j2.c +++ /dev/null @@ -1,86 +0,0 @@ -// Author: Paul Oliver -// Project: Salis - -// Lightweight UI for the Salis simulator with minimal output. -// Can be interrupted through OS signals. -// Ideal for running Salis in the background. - -volatile bool g_running; -uint64_t g_step_block; - -void info_impl(const char *restrict fmt, ...) { - assert(fmt); - printf("\033[1;34mINFO:\033[0m "); - - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); - - printf("\n"); -} - -void warn_impl(const char *restrict fmt, ...) { - assert(fmt); - printf("\033[1;31mWARN:\033[0m "); - - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); - - printf("\n"); -} - -void sig_handler(int signo) { - (void)signo; - - if (g_running) { - g_warn("Signal received, will stop simulator soon..."); - g_running = false; - } -} - -void step_block() { - clock_t beg = clock(); - salis_step(g_step_block - (g_steps % g_step_block)); - clock_t end = clock(); - - if ((end - beg) < (CLOCKS_PER_SEC * 4)) { - g_step_block <<= 1; - } - - if ((end - beg) >= (CLOCKS_PER_SEC * 2) && g_step_block != 1) { - g_step_block >>= 1; - } - - g_info("Simulator running on step '%#lx'", g_steps); -} - -int main() { - g_info = info_impl; - g_warn = warn_impl; - - {% if args.command == "new" %} - salis_init(); - {% elif args.command == "load" %} - salis_load(); - {% endif %} - - g_running = true; - g_step_block = 1; - - signal(SIGINT, sig_handler); - signal(SIGTERM, sig_handler); - - while (g_running) { - step_block(); - } - - g_info("Saving simulation..."); - salis_save("{{ sim_path }}"); - salis_free(); - - g_info("Exiting salis..."); - return 0; -} diff --git a/ui/daemon/ui_vars.py b/ui/daemon/ui_vars.py index bb6be7c..5b3d372 100644 --- a/ui/daemon/ui_vars.py +++ b/ui/daemon/ui_vars.py @@ -1,5 +1,5 @@ -def gen_ui_vars(_): - return { - "flags": [], - "includes": ["signal.h", "stdio.h", "unistd.h"], - } +class UIVars: + def __init__(self, _): + self.includes = {"signal.h", "stdio.h", "unistd.h"} + self.defines = set() + self.links = set() -- cgit v1.2.3-70-g09d2