correct switching context
authorLaurent Mazet <mazet@softndesign.org>
Sat, 4 Feb 2023 23:19:22 +0000 (00:19 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Sat, 4 Feb 2023 23:19:22 +0000 (00:19 +0100)
calc.c
parser.c

diff --git a/calc.c b/calc.c
index c31743d0193696c94db512c12ddfc04185a5e6ee..4b95ffef8ad28cfe7769499690082a6a170ccf5e 100644 (file)
--- a/calc.c
+++ b/calc.c
@@ -387,9 +387,12 @@ int main (int argc, char *argv[])
 // test: echo -e 'set (1, 2, 3, 3.11, pi, 4)\nget (4)' | calc.exe | grep '=> 3.11'
 // test: echo -e 'set (1, 2, 3, 3.11, pi, 4)\npop\npop\n5\npush\nshow' | calc.exe | grep 'stack: 1 2 3 3.11 5'
 // test: echo -e 'set (1, 2, 3, 3.11, pi, 4)\nset\nput (3, 4)\nshow' | calc.exe | grep 'stack: 0 0 4'
-// test: echo -e 'set (1, 2, 3, 3.11, pi, 4)\nlen' | calc.exe | grep '=> 6'
+// test: echo -e 'set (0, -1)\nset (1, 2, 3, 3.11, pi, 4)\nlen' | calc.exe | grep '=> 6'
 // test: echo -e 'set (1, 2)\npop\npush (3)\nput (5, -1)\nlen\nshow\nget (3)\nquit' | calc.exe -n -v 3 | grep -q bye
 // test: echo -e 'put\nget\nget (1)\npop\nput (0)' | calc.exe | grep -c 'error' | xargs test 5 =
+// test: echo -e 'prog (1, 1, {set (1, 2), push (rcl (1)), show})\ncall (1, 10)\nprog (1, 1, cos (rcl (1)))\ncall (1, pi / 2)' | calc.exe -n | grep -q 'stack: 1 2 10'
+// test: echo -e 'prog (1, 1, {set (1, 2), push (rcl (1)), show});\ncall (1, 10);\nshow\ndel (1)' | calc.exe | grep -q 'stack:$'
+// test: echo -e 'prog (1, 1, {set (1, 2), push (rcl (1)), show});\ncall (1, 10);\nlen' | calc.exe | grep -q '=> 0'
 
 // Gauss sequence
 // test: echo -e '{sto (1, 0), sto (10, 0), while (inc (10) < 100, {sto (1, rcl (1) + rcl (10)), print (rcl (1))})};' | calc.exe | grep -q '=> 5050'
index 4e360ddaf70bec25ea4cb46ad72bd2bb12aa276e..74e980b39c4dac2ea4e3f812d7fe0483c8e9989e 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -175,8 +175,8 @@ keyword_t functions[NB_FUNCTIONS] = {
     { "pop",  Pop, 0, 3, 5},
     { "push", Push, 1, 4, 5},
     { "put",  Put, 2, 3, 5},
-    { "set",  Set, MAX_ARGS, 3, 9},
-    { "show",  Show, 0, 4, 9},
+    { "set",  Set, MAX_ARGS, 3, 5},
+    { "show",  Show, 0, 4, 5},
 };
 
 #define NB_CONSTANTS 3
@@ -871,12 +871,17 @@ double call (int id, int nbops, element_t **ops)
     element_t *elements = dupelement ((programs + n)->root);
     ret = evaluate_element (elements, 0);
     delelement (elements);
+    (programs + n)->answer = answer;
+    (programs + n)->storage = storage;
+    (programs + n)->storage_size = storage_size;
+    (programs + n)->stack = stack;
+    (programs + n)->stack_size = stack_size;
 
     /* restore context */
     answer = tmp.answer;
     storage = tmp.storage;
-    storage = tmp.storage;
-    stack_size = tmp.stack_size;
+    storage_size = tmp.storage_size;
+    stack = tmp.stack;
     stack_size = tmp.stack_size;
 
     return ret;