about summary refs log tree commit diff stats
path: root/076continuation.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-11-06 01:12:42 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-11-06 01:12:42 -0800
commit3b776ac3843e925ee24f49e8df51ab6a1db6c085 (patch)
tree91bd75152023b6144d3af8c8e8e37a57cfb6867f /076continuation.cc
parentc34a067564e2005a590bfd8730c90fed51cbb2c2 (diff)
downloadmu-3b776ac3843e925ee24f49e8df51ab6a1db6c085.tar.gz
4116 - support calling continuations with arguments
Surprisingly small change, considering how long it took me and how
mind-bending it was. 'return-continuation-until-mark' now behaves like
both call and return instructions, which made it hard to reason about.
Diffstat (limited to '076continuation.cc')
-rw-r--r--076continuation.cc11
1 files changed, 4 insertions, 7 deletions
diff --git a/076continuation.cc b/076continuation.cc
index e3be246d..5311fd67 100644
--- a/076continuation.cc
+++ b/076continuation.cc
@@ -60,7 +60,7 @@ recipe main [
   1:continuation <- call-with-continuation-mark f, 77  # 77 is an argument to f
   2:number <- copy 5
   {
-    2:number <- call 1:continuation, 2:number  # 2 is an argument to g, the 'top' of the continuation
+    2:number <- call 1:continuation, 2:number  # jump to 'return-continuation-until-mark' below
     3:boolean <- greater-or-equal 2:number, 8
     break-if 3:boolean
     loop
@@ -73,10 +73,7 @@ recipe f [
 ]
 recipe g [
   21:number <- next-ingredient
-  rewind-ingredients
-  return-continuation-until-mark
-  # calls of the continuation start from here
-  22:number <- next-ingredient
+  22:number <- return-continuation-until-mark
   23:number <- add 22:number, 1
   return 23:number
 ]
@@ -218,10 +215,10 @@ if (current_instruction().ingredients.at(0).type->atom
     trace("trace") << "calling delimited continuation; growing callstack depth to " << Trace_stream->callstack_depth << end();
     assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
   }
-  ++current_step_index();  // skip past the return-continuation-until-mark
   ingredients.erase(ingredients.begin());  // drop the callee
   finish_call_housekeeping(to_instruction(caller), ingredients);
-  continue;
+  copy(ingredients.begin(), ingredients.end(), inserter(products, products.begin()));
+  break;  // record results of resuming 'return-continuation-until-mark' instruction
 }
 
 //: Ensure that the presence of a continuation keeps its stack frames from being reclaimed.