poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] pkl: Return exception value instead of exit_status


From: Mohammad-Reza Nabipoor
Subject: [PATCH] pkl: Return exception value instead of exit_status
Date: Thu, 13 Jan 2022 01:06:35 +0330

2022-01-12  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>

        * libpoke/pvm.h (pvm_run): Add new arg for exception.
        * libpoke/pvm.c (pvm_run): Report exception.
        (pvm_call_closure): Fix pvm_run invocation.
        (PVM_STATE_EXCEPTION_VALUE): New macro.
        * libpoke/pkl.h (pkl_execute_file): Add new arg for exception.
        (pkl_execute_buffer): Likewise.
        (pkl_execute_expression): Likewise.
        (pkl_execute_statement): Likewise.
        * libpoke/pkl.c (pkl_execute_file): Likewise.
        (pkl_execute_buffer): Likewise.
        (pkl_execute_expression): Likewise.
        (pkl_execute_statement): Likewise.
        * libpoke/libpoke.h (pk_file_compile): Likewise.
        (pk_compile_buffer): Likewise.
        (pk_compile_statement): Likewise.
        (pk_compile_expression): Likewise.
        * libpoke/libpoke.c (pk_file_compile): Likewise.
        (pk_compile_buffer): Likewise.
        (pk_compile_statement): Likewise.
        (pk_compile_expression): Likewise.
        (pk_call): Fix pvm_run invocation.
        * libpoke/pvm.jitter (state-struct-backing-c): Add new field.
        (popexite): Add new instruction.
        * libpoke/pkl-insn.def: Likewise.
        * libpoke/pkl-rt-1.pk (_pkl_exception_handler): Change return value
        to `Exception` from `int<32>`.
        * libpoke/pkl-asm.c (pkl_asm_finish): Update to report exception.
        * poke/pk-cmd-ios.c (pk_cmd_load_file): Fix comment.
        * poke/pk-map.c (pk_map_load_parsed_map): Likewise.
        * poke/poke.c (parse_args_2): Update to use exception value.
---
 ChangeLog            | 33 +++++++++++++++++++++++++++++++++
 libpoke/libpoke.c    | 18 +++++++++---------
 libpoke/libpoke.h    | 24 ++++++++++++------------
 libpoke/pkl-asm.c    |  5 ++++-
 libpoke/pkl-insn.def |  1 +
 libpoke/pkl-rt-1.pk  |  4 ++--
 libpoke/pkl.c        | 31 ++++++++-----------------------
 libpoke/pkl.h        | 16 ++++++++--------
 libpoke/pvm.c        |  9 +++++++--
 libpoke/pvm.h        |  5 +++--
 libpoke/pvm.jitter   | 19 +++++++++++++++++++
 poke/pk-cmd-ios.c    |  2 +-
 poke/pk-map.c        |  4 ++--
 poke/poke.c          | 22 +++++++++++++++++-----
 14 files changed, 126 insertions(+), 67 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b34f1b41..375d19bb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,36 @@
+2022-01-12  Mohammad-Reza Nabipoor  <mnabipoor@gnu.org>
+
+       * libpoke/pvm.h (pvm_run): Add new arg for exception.
+       * libpoke/pvm.c (pvm_run): Report exception.
+       (pvm_call_closure): Fix pvm_run invocation.
+       (PVM_STATE_EXCEPTION_VALUE): New macro.
+       * libpoke/pkl.h (pkl_execute_file): Add new arg for exception.
+       (pkl_execute_buffer): Likewise.
+       (pkl_execute_expression): Likewise.
+       (pkl_execute_statement): Likewise.
+       * libpoke/pkl.c (pkl_execute_file): Likewise.
+       (pkl_execute_buffer): Likewise.
+       (pkl_execute_expression): Likewise.
+       (pkl_execute_statement): Likewise.
+       * libpoke/libpoke.h (pk_file_compile): Likewise.
+       (pk_compile_buffer): Likewise.
+       (pk_compile_statement): Likewise.
+       (pk_compile_expression): Likewise.
+       * libpoke/libpoke.c (pk_file_compile): Likewise.
+       (pk_compile_buffer): Likewise.
+       (pk_compile_statement): Likewise.
+       (pk_compile_expression): Likewise.
+       (pk_call): Fix pvm_run invocation.
+       * libpoke/pvm.jitter (state-struct-backing-c): Add new field.
+       (popexite): Add new instruction.
+       * libpoke/pkl-insn.def: Likewise.
+       * libpoke/pkl-rt-1.pk (_pkl_exception_handler): Change return value
+       to `Exception` from `int<32>`.
+       * libpoke/pkl-asm.c (pkl_asm_finish): Update to report exception.
+       * poke/pk-cmd-ios.c (pk_cmd_load_file): Fix comment.
+       * poke/pk-map.c (pk_map_load_parsed_map): Likewise.
+       * poke/poke.c (parse_args_2): Update to use exception value.
+
 2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>
 
        * libpoke/pvm-val.c (pvm_typeof): If given a type value, return
diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index 21bed8e3..e78febc0 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -122,29 +122,29 @@ pk_errno (pk_compiler pkc)
 
 int
 pk_compile_file (pk_compiler pkc, const char *filename,
-                 int *exit_status)
+                 pk_val *exception)
 {
-  PK_RETURN (pkl_execute_file (pkc->compiler, filename, exit_status)
+  PK_RETURN (pkl_execute_file (pkc->compiler, filename, exception)
                  ? PK_OK
                  : PK_ERROR);
 }
 
 int
 pk_compile_buffer (pk_compiler pkc, const char *buffer,
-                   const char **end, int *exit_status)
+                   const char **end, pk_val *exception)
 {
   PK_RETURN (pkl_execute_buffer (pkc->compiler, buffer,
-                                 end, exit_status) ? PK_OK : PK_ERROR);
+                                 end, exception) ? PK_OK : PK_ERROR);
 }
 
 int
 pk_compile_statement (pk_compiler pkc, const char *buffer,
                       const char **end, pk_val *valp,
-                      int *exit_status)
+                      pk_val *exception)
 {
   pvm_val val;
 
-  if (!pkl_execute_statement (pkc->compiler, buffer, end, &val, exit_status))
+  if (!pkl_execute_statement (pkc->compiler, buffer, end, &val, exception))
     PK_RETURN (PK_ERROR);
 
   if (valp)
@@ -155,11 +155,11 @@ pk_compile_statement (pk_compiler pkc, const char *buffer,
 
 int
 pk_compile_expression (pk_compiler pkc, const char *buffer,
-                       const char **end, pk_val *valp, int *exit_status)
+                       const char **end, pk_val *valp, pk_val *exception)
 {
   pvm_val val;
 
-  if (!pkl_execute_expression (pkc->compiler, buffer, end, &val, exit_status))
+  if (!pkl_execute_expression (pkc->compiler, buffer, end, &val, exception))
     PK_RETURN (PK_ERROR);
 
   if (valp)
@@ -741,7 +741,7 @@ pk_call (pk_compiler pkc, pk_val cls, pk_val *ret, int 
narg, ...)
 
   /* Run the program in the poke VM.  */
   pvm_program_make_executable (program);
-  rret = pvm_run (pkc->vm, program, ret);
+  rret = pvm_run (pkc->vm, program, ret, NULL);
 
   pvm_destroy_program (program);
   PK_RETURN (rret == PVM_EXIT_OK ? PK_OK : PK_ERROR);
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index dd164172..5712f819 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -134,14 +134,14 @@ int pk_errno (pk_compiler pkc) LIBPOKE_API;
 
 /* Compile an execute a Poke program from the given file FILENAME.
 
-   If not NULL, *EXIT_STATUS is set to the status resulting from the
-   execution of the program.
+   If not NULL, *EXCEPTION is set to the unhandled exception which
+   happened during execution of program, or PK_NULL.
 
    Return PK_ERROR in case of a compilation error.  Otherwise,
    return PK_OK.  */
 
 int pk_compile_file (pk_compiler pkc, const char *filename,
-                     int *exit_status) LIBPOKE_API;
+                     pk_val *exception) LIBPOKE_API;
 
 /* Compile an execute a Poke program from a memory buffer.
 
@@ -153,11 +153,11 @@ int pk_compile_file (pk_compiler pkc, const char 
*filename,
    Return PK_ERROR in case of a compilation error.  Otherwise,
    return PK_OK.
 
-   If not NULL, *EXIT_STATUS is set to the status resulting from the
-   execution of the buffer contents.  */
+   If not NULL, *EXCEPTION is set to the unhandled exception which
+   happened during execution of program, or PK_NULL.  */
 
 int pk_compile_buffer (pk_compiler pkc, const char *buffer,
-                       const char **end, int *exit_status) LIBPOKE_API;
+                       const char **end, pk_val *exception) LIBPOKE_API;
 
 /* Like pk_compile_buffer but compile and execute a single Poke
    statement, which may evaluate to a value if it is an "expression
@@ -166,12 +166,12 @@ int pk_compile_buffer (pk_compiler pkc, const char 
*buffer,
    VAL, if given, is a pointer to a pk_val variable that is set to the
    result value of an expression-statement, or to PK_NULL.
 
-   If not NULL, *EXIT_STATUS is set to the status resulting from the
-   execution of the buffer contents.  */
+   If not NULL, *EXCEPTION is set to the unhandled exception which
+   happened during execution of program, or PK_NULL.  */
 
 int pk_compile_statement (pk_compiler pkc, const char *buffer,
                           const char **end, pk_val *val,
-                          int *exit_status) LIBPOKE_API;
+                          pk_val *exception) LIBPOKE_API;
 
 /* Like pk_compile_buffer but compile and execute a single Poke
    expression, which evaluates to a value.
@@ -181,12 +181,12 @@ int pk_compile_statement (pk_compiler pkc, const char 
*buffer,
 
    Return PK_ERROR in case of a compilation error, PK_OK otherwise.
 
-   If not NULL, *EXIT_STATUS is set to the status resulting from the
-   execution of the buffer contents.  */
+   If not NULL, *EXCEPTION is set to the unhandled exception which
+   happened during execution of program, or PK_NULL.  */
 
 int pk_compile_expression (pk_compiler pkc, const char *buffer,
                            const char **end, pk_val *val,
-                           int *exit_status) LIBPOKE_API;
+                           pk_val *exception) LIBPOKE_API;
 
 /* Load a module using the given compiler.
 
diff --git a/libpoke/pkl-asm.c b/libpoke/pkl-asm.c
index c6a4258e..d9671542 100644
--- a/libpoke/pkl-asm.c
+++ b/libpoke/pkl-asm.c
@@ -1236,7 +1236,10 @@ pkl_asm_finish (pkl_asm pasm, int epilogue)
          assembly.  Otherwise, call the _pkl_exception_handler
          function which is part of the compiler run-time.  */
       if (pkl_bootstrapped_p (pasm->compiler))
-        pkl_asm_call (pasm, "_pkl_exception_handler");
+        {
+          pkl_asm_call (pasm, "_pkl_exception_handler");
+          pkl_asm_insn (pasm, PKL_INSN_POPEXITE);
+        }
       else
         {
           pkl_asm_insn (pasm, PKL_INSN_DROP); /* Discard the exception.  */
diff --git a/libpoke/pkl-insn.def b/libpoke/pkl-insn.def
index 918c6435..4a70eae2 100644
--- a/libpoke/pkl-insn.def
+++ b/libpoke/pkl-insn.def
@@ -441,6 +441,7 @@ PKL_DEF_INSN(PKL_INSN_GETENV,"","getenv")
 PKL_DEF_INSN(PKL_INSN_PUSHE,"l","pushe")
 PKL_DEF_INSN(PKL_INSN_POPE,"","pope")
 PKL_DEF_INSN(PKL_INSN_RAISE,"","raise")
+PKL_DEF_INSN(PKL_INSN_POPEXITE,"","popexite")
 
 /* IOS related instructions.  */
 
diff --git a/libpoke/pkl-rt-1.pk b/libpoke/pkl-rt-1.pk
index 7e09326a..19923b45 100644
--- a/libpoke/pkl-rt-1.pk
+++ b/libpoke/pkl-rt-1.pk
@@ -186,7 +186,7 @@ var exception_code = lambda _ExceptionCodeGenerator:
    or be ready to underflow the exception handlers stack and face some
    ugly shit.  You have been warned!  */
 
-fun _pkl_exception_handler = (Exception exception) int<32>:
+fun _pkl_exception_handler = (Exception exception) Exception:
   {
    if (exception.code != EC_exit && exception.code != EC_signal)
      {
@@ -202,7 +202,7 @@ fun _pkl_exception_handler = (Exception exception) int<32>:
          }
      }
 
-   return exception.exit_status;
+   return exception;
   }
 
 /* Find the greatest common divisor of two unsigned 64-bit integrals A
diff --git a/libpoke/pkl.c b/libpoke/pkl.c
index bb52be9b..959e630f 100644
--- a/libpoke/pkl.c
+++ b/libpoke/pkl.c
@@ -305,7 +305,7 @@ rest_of_compilation (pkl_compiler compiler,
 
 int
 pkl_execute_buffer (pkl_compiler compiler,
-                    const char *buffer, const char **end, int *exit_status)
+                    const char *buffer, const char **end, pvm_val *exception)
 {
   pkl_ast ast = NULL;
   pvm_program program;
@@ -336,12 +336,8 @@ pkl_execute_buffer (pkl_compiler compiler,
   /* Execute the program in the poke vm.  */
   {
     pvm_val val;
-    int status = pvm_run (compiler->vm, program, &val);
 
-    if (exit_status)
-      *exit_status = status;
-
-    if (status != PVM_EXIT_OK)
+    if (pvm_run (compiler->vm, program, &val, exception) != PVM_EXIT_OK)
       goto error;
 
     /* Discard the value.  */
@@ -360,13 +356,12 @@ pkl_execute_buffer (pkl_compiler compiler,
 int
 pkl_execute_statement (pkl_compiler compiler,
                        const char *buffer, const char **end,
-                       pvm_val *val, int *exit_status)
+                       pvm_val *val, pvm_val *exception)
 {
   pkl_ast ast = NULL;
   pvm_program program;
   int ret;
   pkl_env env = NULL;
-  int status;
 
   compiler->compiling = PKL_COMPILING_STATEMENT;
   env = pkl_env_dup_toplevel (compiler->env);
@@ -389,10 +384,7 @@ pkl_execute_statement (pkl_compiler compiler,
   pvm_program_make_executable (program);
 
   /* Execute the routine in the poke vm.  */
-  status = pvm_run (compiler->vm, program, val);
-  if (exit_status)
-    *exit_status = status;
-  if (status != PVM_EXIT_OK)
+  if (pvm_run (compiler->vm, program, val, exception) != PVM_EXIT_OK)
     goto error;
 
   pvm_destroy_program (program);
@@ -413,7 +405,6 @@ pkl_compile_expression (pkl_compiler compiler,
   pvm_program program;
   int ret;
   pkl_env env = NULL;
-  int status;
 
    compiler->compiling = PKL_COMPILING_EXPRESSION;
    env = pkl_env_dup_toplevel (compiler->env);
@@ -447,13 +438,12 @@ pkl_compile_expression (pkl_compiler compiler,
 int
 pkl_execute_expression (pkl_compiler compiler,
                         const char *buffer, const char **end,
-                        pvm_val *val, int *exit_status)
+                        pvm_val *val, pvm_val *exception)
 {
   pkl_ast ast = NULL;
   pvm_program program;
   int ret;
   pkl_env env = NULL;
-  int status;
 
   compiler->compiling = PKL_COMPILING_EXPRESSION;
   env = pkl_env_dup_toplevel (compiler->env);
@@ -476,10 +466,7 @@ pkl_execute_expression (pkl_compiler compiler,
   pvm_program_make_executable (program);
 
   /* Execute the routine in the poke vm.  */
-  status = pvm_run (compiler->vm, program, val);
-  if (exit_status)
-    *exit_status = status;
-  if (status != PVM_EXIT_OK)
+  if (pvm_run (compiler->vm, program, val, exception) != PVM_EXIT_OK)
     goto error;
 
   pvm_destroy_program (program);
@@ -494,7 +481,7 @@ pkl_execute_expression (pkl_compiler compiler,
 
 int
 pkl_execute_file (pkl_compiler compiler, const char *fname,
-                  int *exit_status)
+                  pvm_val *exception)
 {
   int ret;
   pkl_ast ast = NULL;
@@ -532,10 +519,8 @@ pkl_execute_file (pkl_compiler compiler, const char *fname,
   /* Execute the program in the poke vm.  */
   {
     pvm_val val;
-    int status = pvm_run (compiler->vm, program, &val);
 
-    if (exit_status)
-      *exit_status = status;
+    pvm_run (compiler->vm, program, &val, exception);
   }
 
   pvm_destroy_program (program);
diff --git a/libpoke/pkl.h b/libpoke/pkl.h
index ebbdf5ab..ac1ced30 100644
--- a/libpoke/pkl.h
+++ b/libpoke/pkl.h
@@ -88,36 +88,36 @@ void pkl_free (pkl_compiler compiler);
 /* Compile an execute a Poke program from the given file FNAME.
    Return 1 if the compilation was successful, 0 otherwise.
 
-   If EXIT_STATUS is not NULL, set it to the status in which the
-   executed program terminated.  */
+   If EXCEPTION is not NULL, set it to the unhandled exception which
+   happened during execution of program, or PVM_NULL.  */
 
 int pkl_execute_file (pkl_compiler compiler, const char *fname,
-                      int *exit_status);
+                      pvm_val *exception);
 
 /* Compile and execute Poke program from a NULL-terminated string
    BUFFER.  Return 0 in case of a compilation error, 1 otherwise.  If
    not NULL, END is set to the first character in BUFFER that is not
    part of the compiled entity.
 
-   If EXIT_STATUS is not NULL, set it to the status in which the
-   executed program terminated.  */
+   If EXCEPTION is not NULL, set it to the unhandled exception which
+   happened during execution of program, or PVM_NULL.  */
 
 int pkl_execute_buffer (pkl_compiler compiler, const char *buffer,
-                        const char **end, int *exit_status);
+                        const char **end, pvm_val *exception);
 
 /* Like pkl_execute_buffer, but compile and execute a single Poke
    expression, that generates a value in VAL. */
 
 int pkl_execute_expression (pkl_compiler compiler,
                             const char *buffer, const char **end,
-                            pvm_val *val, int *exit_status);
+                            pvm_val *val, pvm_val *exception);
 
 /* Like pkl_execute_expression but compile and execute a single Poke statement,
    which may generate a value in VAL if it is an "expression
    statement".  Otherwise VAL is set to PVM_NULL.  */
 
 int pkl_execute_statement (pkl_compiler compiler, const char *buffer, const 
char **end,
-                           pvm_val *val, int *exit_status);
+                           pvm_val *val, pvm_val *exception);
 
 /* Compile a single Poke expression and return the resulting PVM
    program.  */
diff --git a/libpoke/pvm.c b/libpoke/pvm.c
index 7529891b..74a646ca 100644
--- a/libpoke/pvm.c
+++ b/libpoke/pvm.c
@@ -35,6 +35,8 @@
 
 #define PVM_STATE_RESULT_VALUE(PVM)                     \
   (PVM_STATE_BACKING_FIELD (& (PVM)->pvm_state, result_value))
+#define PVM_STATE_EXCEPTION_VALUE(PVM)                  \
+  (PVM_STATE_BACKING_FIELD (& (PVM)->pvm_state, exception_value))
 #define PVM_STATE_EXIT_CODE(PVM)                        \
   (PVM_STATE_BACKING_FIELD (& (PVM)->pvm_state, exit_code))
 #define PVM_STATE_VM(PVM)                               \
@@ -155,12 +157,13 @@ pvm_get_env (pvm apvm)
 }
 
 enum pvm_exit_code
-pvm_run (pvm apvm, pvm_program program, pvm_val *res)
+pvm_run (pvm apvm, pvm_program program, pvm_val *res, pvm_val *exc)
 {
   sighandler_t previous_handler;
   pvm_routine routine = pvm_program_routine (program);
 
   PVM_STATE_RESULT_VALUE (apvm) = PVM_NULL;
+  PVM_STATE_EXCEPTION_VALUE (apvm) = PVM_NULL;
   PVM_STATE_EXIT_CODE (apvm) = PVM_EXIT_OK;
 
   previous_handler = signal (SIGINT, pvm_handle_signal);
@@ -169,6 +172,8 @@ pvm_run (pvm apvm, pvm_program program, pvm_val *res)
 
   if (res != NULL)
     *res = PVM_STATE_RESULT_VALUE (apvm);
+  if (exc != NULL)
+    *exc = PVM_STATE_EXCEPTION_VALUE (apvm);
 
   return PVM_STATE_EXIT_CODE (apvm);
 }
@@ -197,7 +202,7 @@ pvm_call_closure (pvm vm, pvm_val cls, ...)
   /* Run the program in the poke VM.  */
   program = pkl_asm_finish (pasm, 1 /* epilogue */);
   pvm_program_make_executable (program);
-  (void) pvm_run (vm, program, NULL);
+  (void) pvm_run (vm, program, NULL, NULL);
   pvm_destroy_program (program);
 
 }
diff --git a/libpoke/pvm.h b/libpoke/pvm.h
index 2bf736b7..ba7c9f83 100644
--- a/libpoke/pvm.h
+++ b/libpoke/pvm.h
@@ -593,14 +593,15 @@ void pvm_reset_profile (pvm pvm);
 /* Run a PVM program in a virtual machine.
 
    If the execution of PROGRAM generates a result value, it is put in
-   RES.
+   RES. And if it raises an exception, it is put in EXCEPTION.
 
    This function returns an exit code, indicating whether the
    execution was successful or not.  */
 
 enum pvm_exit_code pvm_run (pvm vm,
                             pvm_program program,
-                            pvm_val *res);
+                            pvm_val *res,
+                            pvm_val *exception);
 
 /* Given a PVM and a closure value, call the closure.
 
diff --git a/libpoke/pvm.jitter b/libpoke/pvm.jitter
index 1ff133fe..71ec1687 100644
--- a/libpoke/pvm.jitter
+++ b/libpoke/pvm.jitter
@@ -963,6 +963,7 @@ state-struct-backing-c
   code
       enum pvm_exit_code exit_code;
       pvm_val result_value;
+      pvm_val exception_value;
       jitter_stack_height canary_stack;
       jitter_stack_height canary_returnstack;
       jitter_stack_height canary_exceptionstack;
@@ -6119,6 +6120,24 @@ instruction raise ()
   end
 end
 
+# Instruction: popexite
+#
+# Pops the exception on the stack into VM internal state and put the
+# exit_status on the stack.
+#
+# Stack: ( EXCEPTION  -- INT )
+# Exceptions Stack: ( -- )
+
+instruction popexite ()
+  code
+    pvm_val exc = JITTER_TOP_STACK ();
+
+    JITTER_DROP_STACK ();
+    PVM_STATE_BACKING_FIELD (exception_value) = exc;
+    JITTER_PUSH_STACK (pvm_ref_struct_cstr (exc, "exit_status"));
+  end
+end
+
 
 ## Debugging Instructions
 
diff --git a/poke/pk-cmd-ios.c b/poke/pk-cmd-ios.c
index 3723b932..1f494e46 100644
--- a/poke/pk-cmd-ios.c
+++ b/poke/pk-cmd-ios.c
@@ -398,7 +398,7 @@ pk_cmd_load_file (int argc, struct pk_cmd_arg argv[], 
uint64_t uflags)
   else
     goto no_file;
 
-  if (pk_compile_file (poke_compiler, filename, NULL /* exit_status */)
+  if (pk_compile_file (poke_compiler, filename, NULL /* exception */)
       != PK_OK)
     /* Note that the compiler emits its own error messages.  */
     goto error;
diff --git a/poke/pk-map.c b/poke/pk-map.c
index cc19c6f1..d4b61c81 100644
--- a/poke/pk-map.c
+++ b/poke/pk-map.c
@@ -502,7 +502,7 @@ pk_map_load_parsed_map (int ios_id, const char *mapname,
                                      condition,
                                      NULL /* end */,
                                      &val,
-                                     NULL /* exit_status */) != PK_OK)
+                                     NULL /* exception */) != PK_OK)
             goto error;
 
           if (pk_type_code (pk_typeof (val)) != PK_INT
@@ -538,7 +538,7 @@ pk_map_load_parsed_map (int ios_id, const char *mapname,
           if (pk_compile_buffer (poke_compiler,
                                  defvar_str,
                                  NULL /* end */,
-                                 NULL /* exit_status */) != PK_OK)
+                                 NULL /* exception */) != PK_OK)
             goto error;
         }
     }
diff --git a/poke/poke.c b/poke/poke.c
index e317bf5d..1e44cb83 100644
--- a/poke/poke.c
+++ b/poke/poke.c
@@ -432,11 +432,19 @@ parse_args_2 (int argc, char *argv[])
           pk_set_quiet_p (poke_compiler, 1);
           break;
         case 'l':
-        case LOAD_ARG:
+        case LOAD_ARG: {
+          pk_val exception;
+
           if (pk_compile_file (poke_compiler, optarg,
-                               NULL /* exit_status */) != PK_OK)
-            goto exit_success;
-          break;
+                               &exception) != PK_OK
+              || exception != PK_NULL)
+            {
+              if (!poke_quiet_p)
+                pk_printf (_("unhandled exception while loading '%s'\n"),
+                           optarg);
+              goto exit_success;
+            }
+        } break;
         case 'c':
         case CMD_ARG:
           {
@@ -454,14 +462,18 @@ parse_args_2 (int argc, char *argv[])
           }
         case 'L':
           {
+            pk_val exception;
             int exit_status;
 
             /* Build argv in the compiler, with the rest of the
                command-line arguments.  Then execute the script and
                return.  */
             set_script_args (argc, argv);
-            if (pk_compile_file (poke_compiler, optarg, &exit_status) != PK_OK)
+            if (pk_compile_file (poke_compiler, optarg, &exception) != PK_OK)
               goto exit_failure;
+            exit_status
+              = pk_int_value (pk_struct_ref_field_value (exception,
+                                                         "exit_status"));
 
             finalize ();
             exit (exit_status);
-- 
2.34.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]