diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-03-14 01:09:20 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-03-14 01:09:20 -0700 |
commit | f6d47435664c1d4f222736fee9e2d17755dd91ad (patch) | |
tree | f3f5b44f322e6fe5a1e02b9b2032e7d7901a8991 | |
parent | 9b187f3f1e944a68331b1579771dae8a35a0e281 (diff) | |
download | mu-f6d47435664c1d4f222736fee9e2d17755dd91ad.tar.gz |
904 - c++: replying from recipes
-rw-r--r-- | cpp/.traces/calling_recipe | 2 | ||||
-rw-r--r-- | cpp/.traces/next_ingredient | 2 | ||||
-rw-r--r-- | cpp/.traces/reply | 30 | ||||
-rw-r--r-- | cpp/012run | 1 | ||||
-rw-r--r-- | cpp/020call | 40 |
5 files changed, 73 insertions, 2 deletions
diff --git a/cpp/.traces/calling_recipe b/cpp/.traces/calling_recipe index ab7089e0..3c220e09 100644 --- a/cpp/.traces/calling_recipe +++ b/cpp/.traces/calling_recipe @@ -1,4 +1,4 @@ -parse/0: instruction: 24 +parse/0: instruction: 25 parse/0: instruction: 2 parse/0: ingredient: {name: "2", type: 0} parse/0: ingredient: {name: "2", type: 0} diff --git a/cpp/.traces/next_ingredient b/cpp/.traces/next_ingredient index 5dccf578..8ded3d51 100644 --- a/cpp/.traces/next_ingredient +++ b/cpp/.traces/next_ingredient @@ -1,4 +1,4 @@ -parse/0: instruction: 24 +parse/0: instruction: 25 parse/0: ingredient: {name: "2", type: 0} parse/0: instruction: 22 parse/0: product: {name: "12", type: 1} diff --git a/cpp/.traces/reply b/cpp/.traces/reply new file mode 100644 index 00000000..6b7b7417 --- /dev/null +++ b/cpp/.traces/reply @@ -0,0 +1,30 @@ +parse/0: instruction: 25 +parse/0: ingredient: {name: "2", type: 0} +parse/0: product: {name: "3", type: 1} +parse/0: product: {name: "4", type: 1} +parse/0: instruction: 22 +parse/0: product: {name: "12", type: 1} +parse/0: instruction: 2 +parse/0: ingredient: {name: "1", type: 0} +parse/0: ingredient: {name: "12", type: 1} +parse/0: product: {name: "13", type: 1} +parse/0: instruction: 23 +parse/0: ingredient: {name: "12", type: 1} +parse/0: ingredient: {name: "13", type: 1} +run/0: instruction main/0 +run/0: instruction f/0 +run/0: product 0 is 2 +mem/0: storing in location 12 +run/0: instruction f/1 +run/0: ingredient 0 is 1 +run/0: ingredient 1 is 12 +mem/0: location 12 is 2 +run/0: product 0 is 3 +mem/0: storing in location 13 +run/0: instruction f/2 +mem/0: location 12 is 2 +mem/0: location 13 is 3 +run/0: result 0 is 1[2...] +mem/0: storing in location 3 +run/0: result 1 is 1[3...] +mem/0: storing in location 4 diff --git a/cpp/012run b/cpp/012run index 70317745..1a95f408 100644 --- a/cpp/012run +++ b/cpp/012run @@ -86,6 +86,7 @@ void run(routine rr) { callee.incoming_atoms.push_back(read_memory(*p)); } rr.calls.push(callee); + continue; // not done with caller; don't increment pc }} ++pc; } diff --git a/cpp/020call b/cpp/020call index c0401cbe..18c54e63 100644 --- a/cpp/020call +++ b/cpp/020call @@ -36,3 +36,43 @@ case NEXT_INGREDIENT: { } break; } + +:(scenario "reply") +recipe main [ + 3:integer, 4:integer <- f 2:literal +] +recipe f [ + 12:integer <- next_ingredient + 13:integer <- add 1:literal, 12:integer + reply 12:integer, 13:integer +] ++run: instruction main/0 ++run: result 0 is 1[2...] ++mem: storing in location 3 ++run: result 1 is 1[3...] ++mem: storing in location 4 + +:(before "End Globals") +const int REPLY = 23; +:(before "End Primitive Recipe Numbers") +Recipe_number["reply"] = REPLY; +assert(Next_recipe_number == REPLY); +Next_recipe_number++; +:(before "End Primitive Recipe Implementations") +case REPLY: { + vector<vector<int> > callee_results; + for (size_t i = 0; i < instructions[pc].ingredients.size(); ++i) { + callee_results.push_back(read_memory(instructions[pc].ingredients[i])); + } + rr.calls.pop(); + size_t& new_pc = rr.calls.top().pc; +//? cout << new_pc << ": " << instructions[new_pc].products.size() << " <=> " << callee_results.size(); //? 2 + assert(instructions[new_pc].products.size() <= callee_results.size()); + for (size_t i = 0; i < instructions[new_pc].products.size(); ++i) { +//? cout << "AAA " << i << '\n'; //? 1 + trace("run") << "result " << i << " is " << callee_results[i].size() << "[" << callee_results[i][0] << "...]"; + write_memory(instructions[new_pc].products[i], callee_results[i]); + } + ++new_pc; + break; +} |