diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-24 00:49:53 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-24 00:49:53 -0700 |
commit | 8ec13146e814500853954cce76d6d8a7d8338813 (patch) | |
tree | b8b9e3182238fd8b4d7fa40a2e68e8093533e07c | |
parent | e179282540758494a1a82db3aabf21179aedf1ac (diff) | |
download | mu-8ec13146e814500853954cce76d6d8a7d8338813.tar.gz |
1447
-rw-r--r-- | 048call_variable.cc | 53 | ||||
-rw-r--r-- | 049continuation.cc (renamed from 048continuation.cc) | 22 |
2 files changed, 55 insertions, 20 deletions
diff --git a/048call_variable.cc b/048call_variable.cc new file mode 100644 index 00000000..0d4e3cc6 --- /dev/null +++ b/048call_variable.cc @@ -0,0 +1,53 @@ +//: push a variable recipe on the call stack + +:(scenario call_literal_recipe) +recipe main [ + 1:number <- call f:recipe, 34:literal +] +recipe f [ + 2:number <- next-ingredient + reply 2:number +] ++mem: storing 34 in location 1 + +:(scenario call_variable) +recipe main [ + 1:number/recipe <- copy 1001:literal/f # hack: assumes tests start recipes at 1000 + 2:number <- call 1:number/recipe, 34:literal +] +recipe f [ # recipe 1001 + 3:number <- next-ingredient + reply 3:number +] ++mem: storing 34 in location 2 +#? ? + +:(before "End Primitive Recipe Declarations") +CALL, +:(before "End Primitive Recipe Numbers") +Recipe_number["call"] = CALL; +:(before "End Primitive Recipe Implementations") +case CALL: { + ++Callstack_depth; + assert(Callstack_depth < 9000); // 9998-101 plus cushion + recipe_number r = 0; +//? cerr << current_instruction().to_string() << '\n'; //? 1 +//? cerr << current_instruction().ingredients.at(0).to_string() << '\n'; //? 1 + if (current_instruction().ingredients.at(0).initialized) { + assert(scalar(ingredients.at(0))); +//? cerr << current_instruction().ingredients.at(0).value << '\n'; //? 1 + // 'call' received an integer recipe_number + r = ingredients.at(0).at(0); + } + else { + // 'call' received a literal recipe name + r = Recipe_number[current_instruction().ingredients.at(0).name]; + } + call callee(r); + for (long long int i = 1; i < SIZE(ingredients); ++i) { +//? cerr << ingredients.at(i).at(0) << '\n'; //? 1 + callee.ingredient_atoms.push_back(ingredients.at(i)); + } + Current_routine->calls.push_front(callee); + continue; // not done with caller; don't increment current_step_index() +} diff --git a/048continuation.cc b/049continuation.cc index 2732ad0f..019c075e 100644 --- a/048continuation.cc +++ b/049continuation.cc @@ -135,27 +135,9 @@ recipe g [ +mem: storing 8 in location 2 -mem: storing 9 in location 2 -//: push a variable recipe on the call stack -//: todo: doesn't really belong in this layer +//: 'reset-and-call' is like 'call' except it inserts a label to the call stack +//: before performing the call -:(before "End Primitive Recipe Declarations") -CALL, -:(before "End Primitive Recipe Numbers") -Recipe_number["call"] = CALL; -:(before "End Primitive Recipe Implementations") -case CALL: { - ++Callstack_depth; - assert(Callstack_depth < 9000); // 9998-101 plus cushion - call callee(Recipe_number[current_instruction().ingredients.at(0).name]); - for (long long int i = 0; i < SIZE(ingredients); ++i) { - callee.ingredient_atoms.push_back(ingredients.at(i)); - } - Current_routine->calls.push_front(callee); - continue; // not done with caller; don't increment current_step_index() -} - -// 'reset-and-call' is like 'call' except it inserts a label to the call stack -// before performing the call :(before "End call Fields") bool is_reset; :(before "End call Constructor") |