partial recursivity
[calc.git] / program.c
index ef6d833be6c1ca651008d69a183cab3ee294747f..7db9d40291b3433a503b32f07c0b605f2ff7497e 100644 (file)
--- a/program.c
+++ b/program.c
@@ -82,35 +82,31 @@ double call (int id, int nbargs, element_t **args)
         return 0;
     }
 
+    /* set arguments */
+    tab_t *old_argument = copy_tab (argument);
+
     /* backup context */
     workspace_t *tmp = backup_ws (alloc_ws ());
     restore_ws (programs[n]);
-    
+
     /* set arguments */
-    free_tab (argument);
-    argument = NULL;
-    if (nbargs > 0) {
-        def (nbargs, args);
-    }
+    argument = def (nbargs, args);
 
     /* 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 */
-    if (argument) {
-        free_tab (argument);
-    }
-    argument = NULL;
-    if (nbargs > 0) {
-        def (nbargs, args);
-    }
-
     /* restore context */
     backup_ws (programs[n]);
     restore_ws (tmp);
+    free_ws (tmp);
+
+    /* clean arguments */
+    free_tab (argument);
+    argument = old_argument;
 
     return ret;
 }