diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-05-31 20:34:29 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-05-31 20:34:29 -0400 |
| commit | 11efaa6f8f45aa4557a3a80dfc32f885ac455908 (patch) | |
| tree | 885013dbbe9548d36a0286b42914f85185bc84d9 /tomo.c | |
| parent | fdaadee13352323d0b68d1aaae0c811f83edf07e (diff) | |
Change how behavior is handled for running files with no main() func
Diffstat (limited to 'tomo.c')
| -rw-r--r-- | tomo.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -376,6 +376,11 @@ int compile_object_file(const char *filename, bool force_recompile) int compile_executable(const char *filename, array_t object_files, module_code_t *module_code) { + binding_t *main_binding = get_binding(module_code->env, "main"); + if (!main_binding || main_binding->type->tag != FunctionType) { + errx(1, "No main() function has been defined for %s, so it can't be run!", filename); + } + const char *bin_name = heap_strn(filename, strlen(filename) - strlen(".tm")); const char *run = heap_strf("%s | %s %s %s %s %s %s -x c - -o %s", autofmt, cc, cflags, ldflags, ldlibs, objfiles, CORD_to_const_char_star(Text$join(" ", object_files)), bin_name); @@ -383,7 +388,6 @@ int compile_executable(const char *filename, array_t object_files, module_code_t printf("%s\n", run); FILE *runner = popen(run, "w"); - binding_t *main_binding = get_binding(module_code->env, "main"); CORD program = CORD_all( "#include <tomo/tomo.h>\n" "#include \"", filename, ".h\"\n" @@ -391,9 +395,7 @@ int compile_executable(const char *filename, array_t object_files, module_code_t "int main(int argc, char *argv[]) {\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") - : "errx(1, \"No main function is defined!\");\n", + CORD_all(compile_cli_arg_call(module_code->env, main_binding->code, main_binding->type), "return 0;\n"), "}\n" ); |
