use return code from main in SRFI 22 usage (fixes #783)

This commit is contained in:
Alex Shinn 2021-11-07 10:13:49 +09:00
parent 7be38e044a
commit a92289ceb9

12
main.c
View file

@ -306,7 +306,7 @@ sexp run_main (int argc, char **argv) {
sexp_sint_t i, j, c, quit=0, print=0, init_loaded=0, mods_loaded=0, sexp_sint_t i, j, c, quit=0, print=0, init_loaded=0, mods_loaded=0,
fold_case=SEXP_DEFAULT_FOLD_CASE_SYMS, nonblocking=0; fold_case=SEXP_DEFAULT_FOLD_CASE_SYMS, nonblocking=0;
sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE; sexp_uint_t heap_size=0, heap_max_size=SEXP_MAXIMUM_HEAP_SIZE;
sexp out=SEXP_FALSE, ctx=NULL, ls; sexp out=SEXP_FALSE, ctx=NULL, ls, res=SEXP_ZERO;
sexp_gc_var4(tmp, sym, args, env); sexp_gc_var4(tmp, sym, args, env);
args = SEXP_NULL; args = SEXP_NULL;
env = NULL; env = NULL;
@ -637,7 +637,7 @@ sexp run_main (int argc, char **argv) {
tmp = sexp_env_ref(ctx, env, sym, SEXP_FALSE); tmp = sexp_env_ref(ctx, env, sym, SEXP_FALSE);
if (sexp_procedurep(tmp)) { if (sexp_procedurep(tmp)) {
args = sexp_list1(ctx, args); args = sexp_list1(ctx, args);
check_exception(ctx, sexp_apply(ctx, tmp, args)); res = check_exception(ctx, sexp_apply(ctx, tmp, args));
} else { } else {
fprintf(stderr, "couldn't find main binding: %s in %s\n", main_symbol, main_module ? main_module : argv[i]); fprintf(stderr, "couldn't find main binding: %s in %s\n", main_symbol, main_module ? main_module : argv[i]);
} }
@ -650,7 +650,7 @@ sexp run_main (int argc, char **argv) {
fprintf(stderr, "destroy_context error\n"); fprintf(stderr, "destroy_context error\n");
return SEXP_FALSE; return SEXP_FALSE;
} }
return SEXP_TRUE; return res;
} }
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
@ -666,11 +666,15 @@ void sexp_resume() {
#endif #endif
int main (int argc, char **argv) { int main (int argc, char **argv) {
sexp res;
#if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT #if SEXP_USE_PRINT_BACKTRACE_ON_SEGFAULT
signal(SIGSEGV, sexp_segfault_handler); signal(SIGSEGV, sexp_segfault_handler);
#endif #endif
sexp_scheme_init(); sexp_scheme_init();
if (run_main(argc, argv) == SEXP_FALSE) { res = run_main(argc, argv);
if (sexp_fixnump(res)) {
return sexp_unbox_fixnum(res);
} else if (res == SEXP_FALSE) {
exit_failure(); exit_failure();
} else { } else {
exit_success(); exit_success();