diff options
Diffstat (limited to 'cpp/021arithmetic')
-rw-r--r-- | cpp/021arithmetic | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/cpp/021arithmetic b/cpp/021arithmetic index 8f4b9c3b..7f7ab0f0 100644 --- a/cpp/021arithmetic +++ b/cpp/021arithmetic @@ -6,16 +6,16 @@ ADD, Recipe_number["add"] = ADD; :(before "End Primitive Recipe Implementations") case ADD: { - trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name; - vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); + trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; + vector<int> arg0 = read_memory(current_instruction().ingredients[0]); assert(arg0.size() == 1); - trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - vector<int> arg1 = read_memory(instructions[pc].ingredients[1]); + trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name; + vector<int> arg1 = read_memory(current_instruction().ingredients[1]); assert(arg1.size() == 1); vector<int> result; result.push_back(arg0[0] + arg1[0]); trace("run") << "product 0 is " << result[0]; - write_memory(instructions[pc].products[0], result); + write_memory(current_instruction().products[0], result); break; } @@ -49,16 +49,16 @@ SUBTRACT, Recipe_number["subtract"] = SUBTRACT; :(before "End Primitive Recipe Implementations") case SUBTRACT: { - trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name; - vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); + trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; + vector<int> arg0 = read_memory(current_instruction().ingredients[0]); assert(arg0.size() == 1); - trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - vector<int> arg1 = read_memory(instructions[pc].ingredients[1]); + trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name; + vector<int> arg1 = read_memory(current_instruction().ingredients[1]); assert(arg1.size() == 1); vector<int> result; result.push_back(arg0[0] - arg1[0]); trace("run") << "product 0 is " << result[0]; - write_memory(instructions[pc].products[0], result); + write_memory(current_instruction().products[0], result); break; } @@ -92,17 +92,17 @@ MULTIPLY, Recipe_number["multiply"] = MULTIPLY; :(before "End Primitive Recipe Implementations") case MULTIPLY: { - trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name; - vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); + trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; + vector<int> arg0 = read_memory(current_instruction().ingredients[0]); assert(arg0.size() == 1); - trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - vector<int> arg1 = read_memory(instructions[pc].ingredients[1]); + trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name; + vector<int> arg1 = read_memory(current_instruction().ingredients[1]); assert(arg1.size() == 1); trace("run") << "ingredient 1 is " << arg1[0]; vector<int> result; result.push_back(arg0[0] * arg1[0]); trace("run") << "product 0 is " << result[0]; - write_memory(instructions[pc].products[0], result); + write_memory(current_instruction().products[0], result); break; } @@ -136,17 +136,17 @@ DIVIDE, Recipe_number["divide"] = DIVIDE; :(before "End Primitive Recipe Implementations") case DIVIDE: { - trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name; - vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); + trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; + vector<int> arg0 = read_memory(current_instruction().ingredients[0]); assert(arg0.size() == 1); - trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - vector<int> arg1 = read_memory(instructions[pc].ingredients[1]); + trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name; + vector<int> arg1 = read_memory(current_instruction().ingredients[1]); assert(arg1.size() == 1); trace("run") << "ingredient 1 is " << arg1[0]; vector<int> result; result.push_back(arg0[0] / arg1[0]); trace("run") << "product 0 is " << result[0]; - write_memory(instructions[pc].products[0], result); + write_memory(current_instruction().products[0], result); break; } @@ -180,20 +180,20 @@ DIVIDE_WITH_REMAINDER, Recipe_number["divide-with-remainder"] = DIVIDE_WITH_REMAINDER; :(before "End Primitive Recipe Implementations") case DIVIDE_WITH_REMAINDER: { - trace("run") << "ingredient 0 is " << instructions[pc].ingredients[0].name; - vector<int> arg0 = read_memory(instructions[pc].ingredients[0]); + trace("run") << "ingredient 0 is " << current_instruction().ingredients[0].name; + vector<int> arg0 = read_memory(current_instruction().ingredients[0]); assert(arg0.size() == 1); - trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - vector<int> arg1 = read_memory(instructions[pc].ingredients[1]); + trace("run") << "ingredient 1 is " << current_instruction().ingredients[1].name; + vector<int> arg1 = read_memory(current_instruction().ingredients[1]); assert(arg1.size() == 1); vector<int> result0; result0.push_back(arg0[0] / arg1[0]); trace("run") << "product 0 is " << result0[0]; - write_memory(instructions[pc].products[0], result0); + write_memory(current_instruction().products[0], result0); vector<int> result1; result1.push_back(arg0[0] % arg1[0]); trace("run") << "product 1 is " << result1[0]; - write_memory(instructions[pc].products[1], result1); + write_memory(current_instruction().products[1], result1); break; } |