poke-devel
[Top][All Lists]
Advanced

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

[COMMITTED] libpoke: add exit_status arguments to all the pk_compile_ fu


From: Jose E. Marchesi
Subject: [COMMITTED] libpoke: add exit_status arguments to all the pk_compile_ functions
Date: Tue, 11 Jan 2022 13:06:07 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>

        * poke/pk-cmd-vm.c (pk_cmd_vm_disas_fun): Likewise.
        * libpoke/pkl.c (pkl_execute_buffer): Get an argument exit_status.
        (pkl_execute_statement): Likewise.
        (pkl_execute_expression): Likewise.
        * libpoke/libpoke.c (pk_compile_buffer): Likewise.
        (pk_compile_statement): Likewise.
        (pk_compile_expression): Likewise.
        * libpoke/pkl.h: Adjust function prototypes accordingly.
        * libpoke/libpoke.h: Likewise.
        * poke/pk-cmd.c (pk_cmd_exec): Pass additional arguments to
        pk_compile_{buffer,statement}.
        * testsuite/poke.libpoke/values.c (testcase_pk_val_equal_p): Likewise.
        * testsuite/poke.libpoke/foreign-iod.c (main): Likewise.
        (TEST_IO): Likewise.
        (main): Likewise.
        * poke/pk-mi.c (pk_mi_dispatch_msg): Likewise.
        * poke/pk-map.c (pk_map_load_parsed_map): Likewise.
        (pk_map_load_parsed_map): Likewise.
        (pk_map_load_parsed_map): Likewise.
        * testsuite/poke.mi-json/mi-json.c (compile_initial_poke_code): 
LIkewise.
        (compile_poke_expression): Likewise.
---
 ChangeLog                            | 24 ++++++++++++++++++++++++
 libpoke/libpoke.c                    | 15 ++++++++-------
 libpoke/libpoke.h                    | 27 +++++++++++++++++++--------
 libpoke/pkl.c                        | 25 +++++++++++++++++++------
 libpoke/pkl.h                        | 11 +++++++----
 poke/pk-cmd-vm.c                     |  2 +-
 poke/pk-cmd.c                        |  4 ++--
 poke/pk-map.c                        |  8 +++++---
 poke/pk-mi.c                         |  2 +-
 testsuite/poke.libpoke/foreign-iod.c |  6 +++---
 testsuite/poke.libpoke/values.c      |  6 +++---
 testsuite/poke.mi-json/mi-json.c     |  4 ++--
 12 files changed, 94 insertions(+), 40 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 714a2961..ced3a8b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2022-01-11  Jose E. Marchesi  <jemarch@gnu.org>
+
+       * poke/pk-cmd-vm.c (pk_cmd_vm_disas_fun): Likewise.
+       * libpoke/pkl.c (pkl_execute_buffer): Get an argument exit_status.
+       (pkl_execute_statement): Likewise.
+       (pkl_execute_expression): Likewise.
+       * libpoke/libpoke.c (pk_compile_buffer): Likewise.
+       (pk_compile_statement): Likewise.
+       (pk_compile_expression): Likewise.
+       * libpoke/pkl.h: Adjust function prototypes accordingly.
+       * libpoke/libpoke.h: Likewise.
+       * poke/pk-cmd.c (pk_cmd_exec): Pass additional arguments to
+       pk_compile_{buffer,statement}.
+       * testsuite/poke.libpoke/values.c (testcase_pk_val_equal_p): Likewise.
+       * testsuite/poke.libpoke/foreign-iod.c (main): Likewise.
+       (TEST_IO): Likewise.
+       (main): Likewise.
+       * poke/pk-mi.c (pk_mi_dispatch_msg): Likewise.
+       * poke/pk-map.c (pk_map_load_parsed_map): Likewise.
+       (pk_map_load_parsed_map): Likewise.
+       (pk_map_load_parsed_map): Likewise.
+       * testsuite/poke.mi-json/mi-json.c (compile_initial_poke_code): 
LIkewise.
+       (compile_poke_expression): Likewise.
+
 2022-01-08  Jose E. Marchesi  <jemarch@gnu.org>
 
        * utils/pk-bin2poke.in: New file.
diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index 7ca5be93..21bed8e3 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -131,19 +131,20 @@ pk_compile_file (pk_compiler pkc, const char *filename,
 
 int
 pk_compile_buffer (pk_compiler pkc, const char *buffer,
-                   const char **end)
+                   const char **end, int *exit_status)
 {
-  PK_RETURN (pkl_execute_buffer (pkc->compiler, buffer, end) ? PK_OK
-                                                             : PK_ERROR);
+  PK_RETURN (pkl_execute_buffer (pkc->compiler, buffer,
+                                 end, exit_status) ? PK_OK : PK_ERROR);
 }
 
 int
 pk_compile_statement (pk_compiler pkc, const char *buffer,
-                      const char **end, pk_val *valp)
+                      const char **end, pk_val *valp,
+                      int *exit_status)
 {
   pvm_val val;
 
-  if (!pkl_execute_statement (pkc->compiler, buffer, end, &val))
+  if (!pkl_execute_statement (pkc->compiler, buffer, end, &val, exit_status))
     PK_RETURN (PK_ERROR);
 
   if (valp)
@@ -154,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)
+                       const char **end, pk_val *valp, int *exit_status)
 {
   pvm_val val;
 
-  if (!pkl_execute_expression (pkc->compiler, buffer, end, &val))
+  if (!pkl_execute_expression (pkc->compiler, buffer, end, &val, exit_status))
     PK_RETURN (PK_ERROR);
 
   if (valp)
diff --git a/libpoke/libpoke.h b/libpoke/libpoke.h
index e8bc05ba..65c2b38d 100644
--- a/libpoke/libpoke.h
+++ b/libpoke/libpoke.h
@@ -132,7 +132,7 @@ void pk_compiler_free (pk_compiler pkc) LIBPOKE_API;
 
 int pk_errno (pk_compiler pkc) LIBPOKE_API;
 
-/* Compile a Poke program from the given file FILENAME.
+/* 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.
@@ -143,7 +143,7 @@ int pk_errno (pk_compiler pkc) LIBPOKE_API;
 int pk_compile_file (pk_compiler pkc, const char *filename,
                      int *exit_status) LIBPOKE_API;
 
-/* Compile a Poke program from a memory buffer.
+/* Compile an execute a Poke program from a memory buffer.
 
    BUFFER is a NULL-terminated string.
 
@@ -151,20 +151,27 @@ int pk_compile_file (pk_compiler pkc, const char 
*filename,
    not part of the compiled entity.
 
    Return PK_ERROR in case of a compilation error.  Otherwise,
-   return PK_OK.  */
+   return PK_OK.
+
+   If not NULL, *EXIT_STATUS is set to the status resulting from the
+   execution of the buffer contents.  */
 
 int pk_compile_buffer (pk_compiler pkc, const char *buffer,
-                       const char **end) LIBPOKE_API;
+                       const char **end, int *exit_status) 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
    statement".
 
    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.  */
+   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.  */
 
 int pk_compile_statement (pk_compiler pkc, const char *buffer,
-                          const char **end, pk_val *val) LIBPOKE_API;
+                          const char **end, pk_val *val,
+                          int *exit_status) LIBPOKE_API;
 
 /* Like pk_compile_buffer but compile and execute a single Poke
    expression, which evaluates to a value.
@@ -172,10 +179,14 @@ int pk_compile_statement (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 executing the expression.
 
-   Return PK_ERROR in case of a compilation error, PK_OK otherwise.  */
+   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.  */
 
 int pk_compile_expression (pk_compiler pkc, const char *buffer,
-                           const char **end, pk_val *val) LIBPOKE_API;
+                           const char **end, pk_val *val,
+                           int *exit_status) LIBPOKE_API;
 
 /* Load a module using the given compiler.
 
diff --git a/libpoke/pkl.c b/libpoke/pkl.c
index 1b81bbd4..bb52be9b 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)
+                    const char *buffer, const char **end, int *exit_status)
 {
   pkl_ast ast = NULL;
   pvm_program program;
@@ -336,8 +336,12 @@ 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 (pvm_run (compiler->vm, program, &val) != PVM_EXIT_OK)
+    if (status != PVM_EXIT_OK)
       goto error;
 
     /* Discard the value.  */
@@ -356,12 +360,13 @@ pkl_execute_buffer (pkl_compiler compiler,
 int
 pkl_execute_statement (pkl_compiler compiler,
                        const char *buffer, const char **end,
-                       pvm_val *val)
+                       pvm_val *val, int *exit_status)
 {
   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);
@@ -384,7 +389,10 @@ pkl_execute_statement (pkl_compiler compiler,
   pvm_program_make_executable (program);
 
   /* Execute the routine in the poke vm.  */
-  if (pvm_run (compiler->vm, program, val) != PVM_EXIT_OK)
+  status = pvm_run (compiler->vm, program, val);
+  if (exit_status)
+    *exit_status = status;
+  if (status != PVM_EXIT_OK)
     goto error;
 
   pvm_destroy_program (program);
@@ -405,6 +413,7 @@ 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);
@@ -438,12 +447,13 @@ pkl_compile_expression (pkl_compiler compiler,
 int
 pkl_execute_expression (pkl_compiler compiler,
                         const char *buffer, const char **end,
-                        pvm_val *val)
+                        pvm_val *val, int *exit_status)
 {
   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);
@@ -466,7 +476,10 @@ pkl_execute_expression (pkl_compiler compiler,
   pvm_program_make_executable (program);
 
   /* Execute the routine in the poke vm.  */
-  if (pvm_run (compiler->vm, program, val) != PVM_EXIT_OK)
+  status = pvm_run (compiler->vm, program, val);
+  if (exit_status)
+    *exit_status = status;
+  if (status != PVM_EXIT_OK)
     goto error;
 
   pvm_destroy_program (program);
diff --git a/libpoke/pkl.h b/libpoke/pkl.h
index 0190512c..ebbdf5ab 100644
--- a/libpoke/pkl.h
+++ b/libpoke/pkl.h
@@ -97,24 +97,27 @@ int pkl_execute_file (pkl_compiler compiler, const char 
*fname,
 /* 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.  */
+   part of the compiled entity.
+
+   If EXIT_STATUS is not NULL, set it to the status in which the
+   executed program terminated.  */
 
 int pkl_execute_buffer (pkl_compiler compiler, const char *buffer,
-                        const char **end);
+                        const char **end, int *exit_status);
 
 /* 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);
+                            pvm_val *val, int *exit_status);
 
 /* 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);
+                           pvm_val *val, int *exit_status);
 
 /* Compile a single Poke expression and return the resulting PVM
    program.  */
diff --git a/poke/pk-cmd-vm.c b/poke/pk-cmd-vm.c
index b2ea9986..cb7a7682 100644
--- a/poke/pk-cmd-vm.c
+++ b/poke/pk-cmd-vm.c
@@ -64,7 +64,7 @@ pk_cmd_vm_disas_fun (int argc, struct pk_cmd_arg argv[], 
uint64_t uflags)
   assert (PK_CMD_ARG_TYPE (argv[1]) == PK_CMD_ARG_STR);
 
   expr = PK_CMD_ARG_STR (argv[1]);
-  ret = pk_compile_expression (poke_compiler, expr, NULL, &cls);
+  ret = pk_compile_expression (poke_compiler, expr, NULL, &cls, NULL);
 
   if (ret != PK_OK)
     /* The compiler has already printed diagnostics in the
diff --git a/poke/pk-cmd.c b/poke/pk-cmd.c
index 0c4fbd52..d203c8d1 100644
--- a/poke/pk-cmd.c
+++ b/poke/pk-cmd.c
@@ -642,7 +642,7 @@ pk_cmd_exec (const char *str)
       if (what == 0)
         {
           /* Declaration.  */
-          if (pk_compile_buffer (poke_compiler, ecmd, &end) != PK_OK)
+          if (pk_compile_buffer (poke_compiler, ecmd, &end, NULL) != PK_OK)
             {
               retval = 0;
               goto cleanup;
@@ -653,7 +653,7 @@ pk_cmd_exec (const char *str)
           /* Statement.  */
           pk_val val;
 
-          if (pk_compile_statement (poke_compiler, ecmd, &end, &val) != PK_OK)
+          if (pk_compile_statement (poke_compiler, ecmd, &end, &val, NULL) != 
PK_OK)
             {
               retval = 0;
               goto cleanup;
diff --git a/poke/pk-map.c b/poke/pk-map.c
index 48043852..cc19c6f1 100644
--- a/poke/pk-map.c
+++ b/poke/pk-map.c
@@ -480,7 +480,7 @@ pk_map_load_parsed_map (int ios_id, const char *mapname,
      poke_compiler.  */
   if (pk_compile_buffer (poke_compiler,
                          PK_MAP_PARSED_MAP_PROLOGUE (map),
-                         NULL) != PK_OK)
+                         NULL, NULL) != PK_OK)
     return 0;
 
   /* Process the map entries and create the mapped global
@@ -501,7 +501,8 @@ pk_map_load_parsed_map (int ios_id, const char *mapname,
           if (pk_compile_expression (poke_compiler,
                                      condition,
                                      NULL /* end */,
-                                     &val) != PK_OK)
+                                     &val,
+                                     NULL /* exit_status */) != PK_OK)
             goto error;
 
           if (pk_type_code (pk_typeof (val)) != PK_INT
@@ -536,7 +537,8 @@ pk_map_load_parsed_map (int ios_id, const char *mapname,
           /* XXX what about constraints?  */
           if (pk_compile_buffer (poke_compiler,
                                  defvar_str,
-                                 NULL /* end */) != PK_OK)
+                                 NULL /* end */,
+                                 NULL /* exit_status */) != PK_OK)
             goto error;
         }
     }
diff --git a/poke/pk-mi.c b/poke/pk-mi.c
index cf00172d..e52c38d3 100644
--- a/poke/pk-mi.c
+++ b/poke/pk-mi.c
@@ -323,7 +323,7 @@ pk_mi_dispatch_msg (pk_mi_msg msg)
 
         ok = pk_compile_expression (poke_compiler,
                                     "format (\"%v\", __pkl_mi_value)",
-                                    NULL, &val);
+                                    NULL, &val, NULL);
         assert (ok == PK_OK);
 
         resp = pk_mi_make_resp (PK_MI_RESP_PRINTV, pk_mi_msg_number (msg),
diff --git a/testsuite/poke.libpoke/foreign-iod.c 
b/testsuite/poke.libpoke/foreign-iod.c
index f4aa0d37..070d6e36 100644
--- a/testsuite/poke.libpoke/foreign-iod.c
+++ b/testsuite/poke.libpoke/foreign-iod.c
@@ -179,7 +179,7 @@ main (int argc, char *argv[])
   /* Open the foreign IOD.  */
   {
     pk_val val;
-    if (pk_compile_statement (poke_compiler, "open (\"<foreign>\");", NULL, 
&val)
+    if (pk_compile_statement (poke_compiler, "open (\"<foreign>\");", NULL, 
&val, NULL)
         != PK_OK)
       {
         fail ("opening <foreign>");
@@ -204,7 +204,7 @@ main (int argc, char *argv[])
     {                                                                   \
       pk_val val;                                                       \
       iod_op.used_p = 0;                                                \
-      if (pk_compile_statement (poke_compiler, CMD ";", NULL, &val)     \
+      if (pk_compile_statement (poke_compiler, CMD ";", NULL, &val, NULL) \
           != PK_OK)                                                     \
         {                                                               \
           fail ((CMD));                                                 \
@@ -234,7 +234,7 @@ main (int argc, char *argv[])
   /* Close the foreign IOD.  */
   {
     pk_val val;
-    if (pk_compile_statement (poke_compiler, "close (0);", NULL, &val)
+    if (pk_compile_statement (poke_compiler, "close (0);", NULL, &val, NULL)
         != PK_OK)
       {
         fail ("closing <foreign>");
diff --git a/testsuite/poke.libpoke/values.c b/testsuite/poke.libpoke/values.c
index f205c681..bfe38106 100644
--- a/testsuite/poke.libpoke/values.c
+++ b/testsuite/poke.libpoke/values.c
@@ -232,13 +232,13 @@ testcase_pk_val_equal_p (const char *filename, const char 
*sec_code,
   if (!pkc)
     goto error;
 
-  if (pk_compile_buffer (pkc, sec_code, NULL) != PK_OK)
+  if (pk_compile_buffer (pkc, sec_code, NULL, NULL) != PK_OK)
     goto error;
 
-  if (pk_compile_expression (pkc, sec_expr1, NULL, &val1) != PK_OK)
+  if (pk_compile_expression (pkc, sec_expr1, NULL, &val1, NULL) != PK_OK)
     goto error;
 
-  if (pk_compile_expression (pkc, sec_expr2, NULL, &val2) != PK_OK)
+  if (pk_compile_expression (pkc, sec_expr2, NULL, &val2, NULL) != PK_OK)
     goto error;
 
   /*  We should have a way to discriminate if we should check
diff --git a/testsuite/poke.mi-json/mi-json.c b/testsuite/poke.mi-json/mi-json.c
index 3f1bdbec..10e94817 100644
--- a/testsuite/poke.mi-json/mi-json.c
+++ b/testsuite/poke.mi-json/mi-json.c
@@ -107,7 +107,7 @@ compile_initial_poke_code (FILE *ifp, pk_compiler pkc)
 
   if (poke_code)
     {
-      error = pk_compile_buffer (pkc, poke_code, NULL);
+      error = pk_compile_buffer (pkc, poke_code, NULL, NULL);
       free (poke_code);
     }
 
@@ -135,7 +135,7 @@ compile_poke_expression (FILE *ifp, pk_compiler pkc, pk_val 
*val)
 
       line[nread - 1] = '\0';
 
-      if (pk_compile_expression (pkc, (const char *)line, NULL, val) != PK_OK)
+      if (pk_compile_expression (pkc, (const char *)line, NULL, val, NULL) != 
PK_OK)
         goto error;
     }
 
-- 
2.11.0




reply via email to

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