about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-10-28 05:40:27 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-10-28 05:40:27 -0700
commit3eeea0a22d16e0fcd43bd33725c0b54639d0ad14 (patch)
tree79d7b11bbd47d3a8c2e5d32d2f5b5ccf1310d0f9
parent6808ff7d6df42aa8a8abe63041254b40b76ba8db (diff)
downloadmu-3eeea0a22d16e0fcd43bd33725c0b54639d0ad14.tar.gz
2294
Bah, sick of CALL and continuations.
-rw-r--r--034call.cc7
-rw-r--r--035call_ingredient.cc6
-rw-r--r--037recipe.cc4
-rw-r--r--053continuation.cc14
-rw-r--r--counters.mu16
-rw-r--r--mu.vim1
6 files changed, 35 insertions, 13 deletions
diff --git a/034call.cc b/034call.cc
index 11dc326e..b799b594 100644
--- a/034call.cc
+++ b/034call.cc
@@ -90,6 +90,7 @@ if (Recipe.find(inst.operation) == Recipe.end()) {
 }
 :(replace{} "default:" following "End Primitive Recipe Implementations")
 default: {
+  const instruction& call_instruction = current_instruction();
   if (Recipe.find(current_instruction().operation) == Recipe.end()) {  // duplicate from Checks
     // stop running this instruction immediately
     ++current_step_index();
@@ -102,9 +103,13 @@ default: {
     assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
   }
   Current_routine->calls.push_front(call(current_instruction().operation));
-  call_housekeeping:
+  finish_call_housekeeping(call_instruction, ingredients);
   continue;  // not done with caller; don't increment current_step_index()
 }
+:(code)
+void finish_call_housekeeping(const instruction& call_instruction, const vector<vector<double> >& ingredients) {
+  // End Call Housekeeping
+}
 
 :(scenario calling_undefined_recipe_fails)
 % Hide_errors = true;
diff --git a/035call_ingredient.cc b/035call_ingredient.cc
index a56510d6..c8f6d75a 100644
--- a/035call_ingredient.cc
+++ b/035call_ingredient.cc
@@ -22,13 +22,17 @@ recipe f [
 
 :(before "End call Fields")
 vector<vector<double> > ingredient_atoms;
+vector<type_tree*> ingredient_types;
 long long int next_ingredient_to_process;
 :(before "End call Constructor")
 next_ingredient_to_process = 0;
 
-:(after "call_housekeeping:")
+:(before "End Call Housekeeping")
 for (long long int i = 0; i < SIZE(ingredients); ++i) {
   Current_routine->calls.front().ingredient_atoms.push_back(ingredients.at(i));
+  if (SIZE(Current_routine->calls) > 1)
+    Current_routine->calls.front().ingredient_types.push_back(call_instruction.ingredients.at(i).type);
+  // todo: else function is main and ingredient_type is string
 }
 
 :(before "End Primitive Recipe Declarations")
diff --git a/037recipe.cc b/037recipe.cc
index b3f4d90f..51ad79af 100644
--- a/037recipe.cc
+++ b/037recipe.cc
@@ -60,9 +60,11 @@ case CALL: {
     trace("trace") << "indirect 'call': incrementing callstack depth to " << Trace_stream->callstack_depth << end();
     assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
   }
+  const instruction& caller_instruction = current_instruction();
   Current_routine->calls.push_front(call(ingredients.at(0).at(0)));
   ingredients.erase(ingredients.begin());  // drop the callee
-  goto call_housekeeping;
+  finish_call_housekeeping(caller_instruction, ingredients);
+  continue;
 }
 
 :(code)
diff --git a/053continuation.cc b/053continuation.cc
index 080eb736..b92217d6 100644
--- a/053continuation.cc
+++ b/053continuation.cc
@@ -196,10 +196,12 @@ case CREATE_DELIMITED_CONTINUATION: {
     trace("trace") << "delimited continuation; incrementing callstack depth to " << Trace_stream->callstack_depth << end();
     assert(Trace_stream->callstack_depth < 9000);  // 9998-101 plus cushion
   }
+  const instruction& caller_instruction = current_instruction();
   Current_routine->calls.front().is_reset = true;
   Current_routine->calls.push_front(call(Recipe_ordinal[current_instruction().ingredients.at(0).name]));
   ingredients.erase(ingredients.begin());  // drop the callee
-  goto call_housekeeping;
+  finish_call_housekeeping(caller_instruction, ingredients);
+  continue;
 }
 
 //: save the slice of current call stack until the 'create-delimited-continuation'
@@ -266,6 +268,7 @@ call_stack::iterator find_reset(call_stack& c) {
       raise_error << maybe(current_recipe_name()) << "no such delimited continuation " << current_instruction().ingredients.at(0).original_string << '\n' << end();
     }
     const call_stack& new_calls = Delimited_continuation[ingredients.at(0).at(0)];
+    const call& caller = (SIZE(new_calls) > 1) ? *++new_calls.rbegin() : Current_routine->calls.front();
     for (call_stack::const_reverse_iterator p = new_calls.rbegin(); p != new_calls.rend(); ++p)
       Current_routine->calls.push_front(*p);
     if (Trace_stream) {
@@ -275,8 +278,15 @@ call_stack::iterator find_reset(call_stack& c) {
     }
     ++current_step_index();  // skip past the reply-delimited-continuation
     ingredients.erase(ingredients.begin());  // drop the callee
-    goto call_housekeeping;
+    finish_call_housekeeping(to_instruction(caller), ingredients);
+    continue;
   }
 
+:(code)
+const instruction& to_instruction(const call& c) {
+  assert(Recipe.find(c.running_recipe) != Recipe.end());
+  return Recipe[c.running_recipe].steps.at(c.running_step_index);
+}
+
 :(before "End is_mu_recipe Cases")
 if (r.type && r.type->value == Type_ordinal["continuation"]) return true;
diff --git a/counters.mu b/counters.mu
index be1f098a..8a4da073 100644
--- a/counters.mu
+++ b/counters.mu
@@ -1,18 +1,18 @@
 # example program: maintain multiple counters with isolated lexical scopes
 # (spaces)
 
-recipe new-counter [
-  default-space:address:array:location <- new location:type, 30
-  n:number <- next-ingredient
-  reply default-space
+recipe new-counter n:number -> default-space:address:array:location [
+  default-space <- new location:type, 30
+  load-ingredients
+  reply
 ]
 
-recipe increment-counter [
+recipe increment-counter outer:address:array:location/names:new-counter, x:number -> n:number/space:1 [
   local-scope
-  0:address:array:location/names:new-counter <- next-ingredient  # setup outer space; it *must* come from 'new-counter'
-  x:number <- next-ingredient
+  load-ingredients
+  0:address:array:location/names:new-counter <- copy outer  # setup outer space; it *must* come from 'new-counter'
   n:number/space:1 <- add n:number/space:1, x
-  reply n:number/space:1
+  reply n/space:1
 ]
 
 recipe main [
diff --git a/mu.vim b/mu.vim
index 72255940..bb77b50d 100644
--- a/mu.vim
+++ b/mu.vim
@@ -62,6 +62,7 @@ syntax match muGlobal %[^ ]\+:global/\?[^ ,]*% | highlight link muGlobal Special
 syntax keyword muControl reply reply-if reply-unless jump jump-if jump-unless loop loop-if loop-unless break break-if break-unless current-continuation continue-from create-delimited-continuation reply-delimited-continuation | highlight muControl ctermfg=3
 " common keywords
 syntax keyword muRecipe recipe recipe! before after | highlight muRecipe ctermfg=208
+syntax match muRecipe " -> "
 syntax keyword muScenario scenario | highlight muScenario ctermfg=34
 syntax keyword muData container exclusive-container | highlight muData ctermfg=226