about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-12 22:24:18 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-12 22:24:18 -0700
commit1228ec731ead0abec824f469cfc81f59209a2dcb (patch)
treec7f68fff89d4a1739c1b66cf5f41d2173be69d3e /cpp
parent43867ac84972c4b031c49dcec3246411def72143 (diff)
downloadmu-1228ec731ead0abec824f469cfc81f59209a2dcb.tar.gz
896 - c++: routine
Diffstat (limited to 'cpp')
-rw-r--r--cpp/012run31
1 files changed, 20 insertions, 11 deletions
diff --git a/cpp/012run b/cpp/012run
index 45a6048f..2145f360 100644
--- a/cpp/012run
+++ b/cpp/012run
@@ -27,27 +27,36 @@ struct call {
 };
 typedef stack<call> call_stack;
 
+struct routine {
+  size_t alloc;
+  size_t alloc_max;
+  call_stack calls;
+  size_t limit;
+  size_t running_since;
+  // todo: sleep conditions
+};
+
 :(code)
 void run(string form) {
   recipe_number r = add_recipe(form);
-  call_stack context;
-  context.push(call(r));
-  run(context);
+  routine rr;
+  rr.calls.push(call(r));
+  run(rr);
 }
 
-void run(call_stack context) {
+void run(routine rr) {
 // #defines save us the trouble of updating aliases when dependent variables
 // change.
-#define TOP_RECIPE Recipe[context.top().running_recipe]
+#define TOP_RECIPE Recipe[rr.calls.top().running_recipe]
 #define instructions TOP_RECIPE.steps
-  while (!context.empty()) {
-    while (context.top().pc >= instructions.size()) {
-      context.pop();
-      if (context.empty()) return;
+  while (!rr.calls.empty()) {
+    while (rr.calls.top().pc >= instructions.size()) {
+      rr.calls.pop();
+      if (rr.calls.empty()) return;
       // todo: no results returned warning
-      ++context.top().pc;
+      ++rr.calls.top().pc;
     }
-    size_t& pc = context.top().pc;
+    size_t& pc = rr.calls.top().pc;
     trace("run") << "instruction " << TOP_RECIPE.name << '/' << pc;
     switch (instructions[pc].operation) {
     // Primitive Recipe Implementations.