diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-03-26 17:03:07 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-03-26 17:03:07 -0700 |
commit | c82d01762778baeb71c26365479e3c1cddcfbf13 (patch) | |
tree | 846100fbc599414b520d5049ffa14182318a5451 | |
parent | c63e2811a14344801950d075ca89c3601e73f065 (diff) | |
download | mu-c82d01762778baeb71c26365479e3c1cddcfbf13.tar.gz |
973
-rw-r--r-- | cpp/013run | 7 | ||||
-rw-r--r-- | cpp/018record | 6 | ||||
-rw-r--r-- | cpp/019address | 8 | ||||
-rw-r--r-- | cpp/024brace | 12 | ||||
-rw-r--r-- | cpp/025name | 3 |
5 files changed, 17 insertions, 19 deletions
diff --git a/cpp/013run b/cpp/013run index 5173f6f3..33385e00 100644 --- a/cpp/013run +++ b/cpp/013run @@ -118,9 +118,8 @@ recipes_added_by_test.clear(); //: beware: overridden in later layers vector<int> read_memory(reagent x) { //? cout << "read_memory: " << x.to_string() << '\n'; //? 1 - static const int LITERAL = Type_number["literal"]; vector<int> result; - if (x.types[0] == LITERAL) { + if (isa_literal(x)) { result.push_back(x.value); return result; } @@ -157,6 +156,10 @@ bool is_dummy(const reagent& x) { return x.name == "_"; } +bool isa_literal(const reagent& r) { + return r.types.size() == 1 && r.types[0] == 0; +} + :(scenario run_label) recipe main [ +foo diff --git a/cpp/018record b/cpp/018record index 64cedb7a..91e142a3 100644 --- a/cpp/018record +++ b/cpp/018record @@ -39,8 +39,7 @@ case GET: { int base_type = instructions[pc].ingredients[0].types[0]; assert(Type[base_type].is_record); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - assert(instructions[pc].ingredients[1].types.size() == 1); - assert(instructions[pc].ingredients[1].types[0] == 0); // must be literal + assert(isa_literal(instructions[pc].ingredients[1])); size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { @@ -118,8 +117,7 @@ case GET_ADDRESS: { int base_type = instructions[pc].ingredients[0].types[0]; assert(Type[base_type].is_record); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - assert(instructions[pc].ingredients[1].types.size() == 1); - assert(instructions[pc].ingredients[1].types[0] == 0); // must be literal + assert(isa_literal(instructions[pc].ingredients[1])); size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { diff --git a/cpp/019address b/cpp/019address index 28fa4515..a642ceb1 100644 --- a/cpp/019address +++ b/cpp/019address @@ -15,7 +15,7 @@ recipe main [ :(replace{} "vector<int> read_memory(reagent x)") vector<int> read_memory(reagent x) { vector<int> result; - if (x.types[0] == 0) { // literal + if (isa_literal(x)) { result.push_back(x.value); return result; } @@ -133,8 +133,7 @@ case GET: { int base_type = base.types[0]; assert(Type[base_type].is_record); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - assert(instructions[pc].ingredients[1].types.size() == 1); - assert(instructions[pc].ingredients[1].types[0] == 0); // must be literal + assert(isa_literal(instructions[pc].ingredients[1])); size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { @@ -176,8 +175,7 @@ case GET_ADDRESS: { int base_type = base.types[0]; assert(Type[base_type].is_record); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; - assert(instructions[pc].ingredients[1].types.size() == 1); - assert(instructions[pc].ingredients[1].types[0] == 0); // must be literal + assert(isa_literal(instructions[pc].ingredients[1])); size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { diff --git a/cpp/024brace b/cpp/024brace index fdcf12e6..ec6171f7 100644 --- a/cpp/024brace +++ b/cpp/024brace @@ -60,7 +60,7 @@ void transform_braces(const recipe_number r) { ; // do nothing else if (inst.operation == Recipe_number["loop"]) { inst.operation = Recipe_number["jump"]; - if (inst.ingredients.size() > 0 && inst.ingredients[0].types[0] == 0) { + if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients[0])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } @@ -75,7 +75,7 @@ void transform_braces(const recipe_number r) { } else if (inst.operation == Recipe_number["break"]) { inst.operation = Recipe_number["jump"]; - if (inst.ingredients.size() > 0 && inst.ingredients[0].types[0] == 0) { + if (inst.ingredients.size() > 0 && isa_literal(inst.ingredients[0])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } @@ -88,7 +88,7 @@ void transform_braces(const recipe_number r) { } else if (inst.operation == Recipe_number["loop-if"]) { inst.operation = Recipe_number["jump-if"]; - if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } @@ -101,7 +101,7 @@ void transform_braces(const recipe_number r) { } else if (inst.operation == Recipe_number["break-if"]) { inst.operation = Recipe_number["jump-if"]; - if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } @@ -114,7 +114,7 @@ void transform_braces(const recipe_number r) { } else if (inst.operation == Recipe_number["loop-unless"]) { inst.operation = Recipe_number["jump-unless"]; - if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } @@ -127,7 +127,7 @@ void transform_braces(const recipe_number r) { } else if (inst.operation == Recipe_number["break-unless"]) { inst.operation = Recipe_number["jump-unless"]; - if (inst.ingredients.size() > 1 && inst.ingredients[1].types[0] == 0) { + if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients[1])) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } diff --git a/cpp/025name b/cpp/025name index d36552d3..7296881b 100644 --- a/cpp/025name +++ b/cpp/025name @@ -33,8 +33,7 @@ void transform_names(const recipe_number r) { || inst.operation == Recipe_number["get-address"]) { // at least 2 args, and second arg is offset assert(inst.ingredients.size() >= 2); - assert(!inst.ingredients[1].types.empty()); - assert(inst.ingredients[1].types[0] == 0); + assert(isa_literal(inst.ingredients[1])); if (inst.ingredients[1].name.find_first_not_of("0123456789") == string::npos) continue; // since first non-address in base type must be a record, we don't have to canonize type_number record = skip_addresses(inst.ingredients[0].types); |