test
authorLaurent Mazet <mazet@softndesign.org>
Wed, 15 Feb 2023 23:03:17 +0000 (00:03 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 15 Feb 2023 23:03:17 +0000 (00:03 +0100)
argument.c
program.c

index bda7684e754e813659e1c53fe72b56bb60210331..c8f345f40d4d1c83895492eef5fe00f574a8ca8a 100644 (file)
@@ -1,3 +1,5 @@
+#include <stdio.h>
+
 #include "parser.h"
 #include "tabular.h"
 
@@ -21,10 +23,14 @@ double arg (int n)
 double def (int nbops, element_t **ops)
 {
     int i;
-    argument = resize_tab (argument, nbops);
+    tab_t *new = alloc_tab (nbops);
     for (i = 0; i < nbops; i++) {
-        set_tab (argument, i + 1, evaluate_element (ops[i], 0));
+        double val = evaluate_element (ops[i], 0);
+        VERBOSE (DEBUG, fprintf (stdout, "arg[%d] = %g\n", i + i, val));
+        set_tab (new, i + 1, val);
     }
+    free_tab (argument);
+    argument = new;
     return size_tab (argument);
 }
 
index dc433aa57ec969f2111aae27f46c526e325cdf73..a6801f8a48574ed34a003ed5451e1ef8e6a35ea7 100644 (file)
--- a/program.c
+++ b/program.c
@@ -81,22 +81,25 @@ double call (int id, int nbargs, element_t **args)
         VERBOSE (WARNING, fprintf (stdout, "error unknown program (%d)\n", id));
         return 0;
     }
+    VERBOSE (DEBUG, fprintf (stdout, "id -> n; %d -> %d\n", id, n));
 
-    /* backup context */
-    workspace_t *tmp = backup_ws (alloc_ws ());
-    restore_ws (programs[n]);
-    
     /* set arguments */
     free_tab (argument);
     argument = NULL;
+    VERBOSE (DEBUG, fprintf (stdout, "nbargs; %d\n", nbargs));
     if (nbargs > 0) {
         def (nbargs, args);
     }
 
+    /* backup context */
+    workspace_t *tmp = backup_ws (alloc_ws ());
+    restore_ws (programs[n]);
+
     /* evaluate program */
     answer = 0;
     element_t *elements = dupelement (programs[n]->root);
     ret = evaluate_element (elements, 0);
+    VERBOSE (DEBUG, fprintf (stdout, "ret; %g\n", ret));
     delelement (elements);
 
     /* clean arguments */