diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-05-25 13:56:34 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-05-25 13:56:34 -0400 |
| commit | 128b1dd2398f4005341f5afbe3d4230152340650 (patch) | |
| tree | d749ca4c54ace3fdefe4da697ab057fc49870616 | |
| parent | 9d744b3e6ef947fe75ed4c145c56eec74b329d7d (diff) | |
Move standard initialization code into tomo_init() function
| -rw-r--r-- | builtins/functions.c | 9 | ||||
| -rw-r--r-- | builtins/functions.h | 2 | ||||
| -rw-r--r-- | tomo.c | 7 |
3 files changed, 12 insertions, 6 deletions
diff --git a/builtins/functions.c b/builtins/functions.c index bed3dbfd..7ece75ea 100644 --- a/builtins/functions.c +++ b/builtins/functions.c @@ -8,6 +8,7 @@ #include <stdlib.h> #include <sys/param.h> #include <uninorm.h> +#include <unistd.h> #include "array.h" #include "bool.h" @@ -23,6 +24,14 @@ public const char *TOMO_HASH_VECTOR = "tomo hash vector ---------------------------------------------"; +public void tomo_init(void) +{ + GC_INIT(); + USE_COLOR = getenv("COLOR") ? strcmp(getenv("COLOR"), "1") == 0 : isatty(STDOUT_FILENO); + srand(arc4random_uniform(UINT32_MAX)); + srand48(arc4random_uniform(UINT32_MAX)); +} + public void fail(CORD fmt, ...) { if (USE_COLOR) fputs("\x1b[31;7m FAIL: \x1b[m ", stderr); diff --git a/builtins/functions.h b/builtins/functions.h index f1a2867e..cf19a127 100644 --- a/builtins/functions.h +++ b/builtins/functions.h @@ -10,6 +10,8 @@ extern const char *TOMO_HASH_VECTOR; +void tomo_init(void); + void fail(CORD fmt, ...); void fail_source(const char *filename, int64_t start, int64_t end, CORD fmt, ...); CORD builtin_last_err(); @@ -321,16 +321,11 @@ int compile_executable(const char *filename, const char *object_files, module_co binding_t *main_binding = get_binding(module_code->env, "main"); CORD program = CORD_all( - "#include <stdlib.h>\n" "#include <tomo/tomo.h>\n" - "#include <unistd.h>\n" "#include \"", filename, ".h\"\n" "\n" "int main(int argc, char *argv[]) {\n" - "GC_INIT();\n" - "USE_COLOR = getenv(\"COLOR\") ? strcmp(getenv(\"COLOR\"), \"1\") == 0 : isatty(STDOUT_FILENO);\n" - "srand(arc4random_uniform(UINT32_MAX));\n" - "srand48(arc4random_uniform(UINT32_MAX));\n" + "tomo_init();\n" "\n", main_binding && main_binding->type->tag == FunctionType ? CORD_all(compile_cli_arg_call(module_code->env, main_binding->code, main_binding->type), "return 0;\n") |
