diff --git a/src/c/main.d b/src/c/main.d index a600e7ffe..8e2dd7b05 100644 --- a/src/c/main.d +++ b/src/c/main.d @@ -722,23 +722,27 @@ cl_boot(int argc, char **argv) cl_object p, all_threads = mp_all_processes(); for (p = all_threads; !Null(p); p = ECL_CONS_CDR(p)) { cl_object process = ECL_CONS_CAR(p); - if (process != this) mp_process_kill(process); + if (process != this && process->process.active) + mp_process_kill(process); } for (p = all_threads; !Null(p); p = ECL_CONS_CDR(p)) { cl_object process = ECL_CONS_CAR(p); - if (process != this) mp_process_join(process); + if (process != this && process->process.active) + mp_process_join(process); } } #endif - the_env->nvalues = 1; - the_env->values[0] = code; + ECL_SET(@'ext::*program-exit-code*', code); if (the_env->frs_org <= the_env->frs_top) ecl_unwind(the_env, the_env->frs_org); - CEerror(Ct, "QUIT: there is no frame to return to. " - "Using continue will just abort.", 0); + si_exit(1, code); +} +@) + +@(defun ext::exit (&optional (code ECL_SYM_VAL(ecl_process_env(),@'ext::*program-exit-code*'))) +@ cl_shutdown(); exit(FIXNUMP(code)? fix(code) : 0); -} @) cl_object diff --git a/src/c/symbols_list.h b/src/c/symbols_list.h index e34ec5946..1a1f0cc7f 100644 --- a/src/c/symbols_list.h +++ b/src/c/symbols_list.h @@ -1839,5 +1839,8 @@ cl_symbols[] = { {EXT_ "ARRAY-RAW-DATA", EXT_ORDINARY, si_array_raw_data, 1, OBJNULL}, +{EXT_ "*PROGRAM-EXIT-CODE*", EXT_SPECIAL, NULL, -1, MAKE_FIXNUM(0)}, +{EXT_ "EXIT", EXT_ORDINARY, si_exit, -1, OBJNULL}, + /* Tag for end of list */ {NULL, CL_ORDINARY, NULL, -1, OBJNULL}}; diff --git a/src/c/symbols_list2.h b/src/c/symbols_list2.h index cd49d3762..2a88e7dee 100644 --- a/src/c/symbols_list2.h +++ b/src/c/symbols_list2.h @@ -1839,5 +1839,8 @@ cl_symbols[] = { {EXT_ "ARRAY-RAW-DATA","si_array_raw_data"}, +{EXT_ "*PROGRAM-EXIT-CODE*",NULL}, +{EXT_ "EXIT","si_exit"}, + /* Tag for end of list */ {NULL,NULL}}; diff --git a/src/cmp/cmpmain.lsp b/src/cmp/cmpmain.lsp index 79783e830..e3d80818f 100755 --- a/src/cmp/cmpmain.lsp +++ b/src/cmp/cmpmain.lsp @@ -267,6 +267,7 @@ main(int argc, char **argv) read_VV(OBJNULL, ~A); ~A } CL_CATCH_ALL_END; + si_exit(0); }") #+:win32 @@ -284,6 +285,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS read_VV(OBJNULL, ~A); ~A } CL_CATCH_ALL_END; + si_exit(0); }") (defun init-function-name (s &key (kind :object)) @@ -408,17 +410,7 @@ filesystem or in the database of ASDF modules." cl_object output; si_select_package(make_simple_base_string(\"CL-USER\")); output = si_safe_eval(3, ecl_read_from_cstring(lisp_code), Cnil, OBJNULL); -" stream) - (when (eq target :program) - (princ " -cl_shutdown(); -if (FIXNUMP(output)) - return fix(output); -if (Null(output) || (output == OBJNULL)) - return 0; -return 1;" - stream)) - (princ #\} stream) +}" stream) ))))) (cond ((null prologue-code) (setf prologue-code "")) diff --git a/src/h/external.h b/src/h/external.h index 4669bb12b..71b11ddc7 100644 --- a/src/h/external.h +++ b/src/h/external.h @@ -888,6 +888,7 @@ extern ECL_API cl_object si_getenv(cl_object var); extern ECL_API cl_object si_setenv(cl_object var, cl_object value); extern ECL_API cl_object si_pointer(cl_object x); extern ECL_API cl_object si_quit _ARGS((cl_narg narg, ...)) /*__attribute__((noreturn))*/; +extern ECL_API cl_object si_exit _ARGS((cl_narg narg, ...)) /*__attribute__((noreturn))*/; typedef enum { ECL_OPT_INCREMENTAL_GC = 0,