about summary refs log tree commit diff stats
path: root/apps/tile/rpn.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-26 23:29:14 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-26 23:29:14 -0700
commit4578687622e89eb1d593e99cee72c124b48cff07 (patch)
tree9d376f68d8cbfafeb50290d3b659765a83427a14 /apps/tile/rpn.mu
parent6f4ff604de488d69d6451f92414656e8125caa99 (diff)
downloadmu-4578687622e89eb1d593e99cee72c124b48cff07.tar.gz
6879
Extract a new function.
Diffstat (limited to 'apps/tile/rpn.mu')
-rw-r--r--apps/tile/rpn.mu32
1 files changed, 18 insertions, 14 deletions
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index 2b45d981..96c5f8d6 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -125,7 +125,24 @@ fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs
   var table-storage: table
   var table/esi: (addr table) <- address table-storage
   initialize-table table, 0x10
-  #
+  bind-args callee, caller-stack, table
+  # obtain body
+  var body-ah/eax: (addr handle line) <- get callee, body
+  var body/eax: (addr line) <- lookup *body-ah
+  # perform call
+  var stack-storage: value-stack
+  var stack/edi: (addr value-stack) <- address stack-storage
+  initialize-value-stack stack, 0x10
+#?   print-string-to-real-screen "about to enter recursive eval\n"
+  evaluate defs, table, body, 0, stack
+#?   print-string-to-real-screen "exited recursive eval\n"
+  # stitch result from stack into caller
+  var result/eax: int <- pop-int-from-value-stack stack
+  push-int-to-value-stack caller-stack, result
+}
+
+fn bind-args _callee: (addr function), caller-stack: (addr value-stack), table: (addr table) {
+  var callee/ecx: (addr function) <- copy _callee
   var curr-arg-ah/eax: (addr handle word) <- get callee, args
   var curr-arg/eax: (addr word) <- lookup *curr-arg-ah
   #
@@ -151,19 +168,6 @@ fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs
     curr-arg <- lookup *next-arg-ah
     loop
   }
-  # obtain body
-  var body-ah/eax: (addr handle line) <- get callee, body
-  var body/eax: (addr line) <- lookup *body-ah
-  # perform call
-  var stack-storage: value-stack
-  var stack/edi: (addr value-stack) <- address stack-storage
-  initialize-value-stack stack, 0x10
-#?   print-string-to-real-screen "about to enter recursive eval\n"
-  evaluate defs, table, body, 0, stack
-#?   print-string-to-real-screen "exited recursive eval\n"
-  # stitch result from stack into caller
-  var result/eax: int <- pop-int-from-value-stack stack
-  push-int-to-value-stack caller-stack, result
 }
 
 # Copy of 'simplify' that just tracks the maximum stack depth needed