diff options
-rw-r--r-- | cpp/.traces/factorial | 4 | ||||
-rw-r--r-- | cpp/.traces/loop | 4 | ||||
-rw-r--r-- | cpp/010vm | 6 | ||||
-rw-r--r-- | cpp/018record | 11 | ||||
-rw-r--r-- | cpp/019address | 10 | ||||
-rw-r--r-- | cpp/020array | 14 | ||||
-rw-r--r-- | cpp/024brace | 12 |
7 files changed, 37 insertions, 24 deletions
diff --git a/cpp/.traces/factorial b/cpp/.traces/factorial index a1da686b..3804ea05 100644 --- a/cpp/.traces/factorial +++ b/cpp/.traces/factorial @@ -34,8 +34,8 @@ after-brace/0: jump-if 3, 3:offset after-brace/0: multiply ... after-brace/0: subtract ... after-brace/0: jump -5:offset -after-brace/0: 7: {name: "", value: -5, type: 0} -after-brace/0: 7: {name: "", value: -5, type: 0} +after-brace/0: 7: {name: "", value: -5, type: } +after-brace/0: 7: {name: "", value: -5, type: } after-brace/0: copy ... run/0: instruction factorial/0 run/0: ingredient 0 is 5 diff --git a/cpp/.traces/loop b/cpp/.traces/loop index 26d2dbc8..035d7aa9 100644 --- a/cpp/.traces/loop +++ b/cpp/.traces/loop @@ -17,5 +17,5 @@ after-brace/0: copy ... after-brace/0: copy ... after-brace/0: copy ... after-brace/0: jump -2:offset -after-brace/0: 4: {name: "", value: -2, type: 0} -after-brace/0: 4: {name: "", value: -2, type: 0} +after-brace/0: 4: {name: "", value: -2, type: } +after-brace/0: 4: {name: "", value: -2, type: } diff --git a/cpp/010vm b/cpp/010vm index c7de25b0..1d45f157 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -44,7 +44,7 @@ struct reagent { bool initialized; vector<type_number> types; reagent(string s); - reagent(type_number t); + reagent(); void set_value(int v) { value = v; initialized = true; } string to_string(); }; @@ -164,9 +164,7 @@ void setup_recipes() { types.push_back(Type_number[properties[0].second[i]]); } } - reagent::reagent(type_number t) :value(0), initialized(false) { - types.push_back(t); - } + reagent::reagent() :value(0), initialized(false) {} string reagent::to_string() { ostringstream out; out << "{name: \"" << name << "\", value: " << value << ", type: "; diff --git a/cpp/018record b/cpp/018record index 44e568cc..64cedb7a 100644 --- a/cpp/018record +++ b/cpp/018record @@ -44,14 +44,17 @@ case GET: { size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { - src += size_of(reagent(Type[base_type].elements[i][0])); + reagent tmp; + tmp.types.push_back(Type[base_type].elements[i][0]); + src += size_of(tmp); } trace("run") << "address to copy is " << src; assert(Type[base_type].elements.size() > offset); int src_type = Type[base_type].elements[offset][0]; trace("run") << "its type is " << src_type; - reagent tmp(src_type); + reagent tmp; tmp.set_value(src); + tmp.types.push_back(src_type); vector<int> result(read_memory(tmp)); trace("run") << "product 0 is " << result[0]; write_memory(instructions[pc].products[0], result); @@ -120,7 +123,9 @@ case GET_ADDRESS: { size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { - src += size_of(reagent(Type[base_type].elements[i][0])); + reagent tmp; + tmp.types.push_back(Type[base_type].elements[i][0]); + src += size_of(tmp); } trace("run") << "address to copy is " << src; vector<int> result; diff --git a/cpp/019address b/cpp/019address index c487dac6..6d697cb5 100644 --- a/cpp/019address +++ b/cpp/019address @@ -137,14 +137,16 @@ case GET: { size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { - src += size_of(reagent(Type[base_type].elements[i][0])); + reagent tmp; + tmp.types.push_back(Type[base_type].elements[i][0]); + src += size_of(tmp); } trace("run") << "address to copy is " << src; assert(Type[base_type].is_record); assert(Type[base_type].elements.size() > offset); int src_type = Type[base_type].elements[offset][0]; trace("run") << "its type is " << src_type; - reagent tmp(src_type); + reagent tmp; tmp.set_value(src); tmp.types.push_back(src_type); vector<int> result(read_memory(tmp)); @@ -178,7 +180,9 @@ case GET_ADDRESS: { size_t offset = instructions[pc].ingredients[1].value; int src = base_address; for (size_t i = 0; i < offset; ++i) { - src += size_of(reagent(Type[base_type].elements[i][0])); + reagent tmp; + tmp.types.push_back(Type[base_type].elements[i][0]); + src += size_of(tmp); } trace("run") << "address to copy is " << src; vector<int> result; diff --git a/cpp/020array b/cpp/020array index 4ee04e98..aafeacf8 100644 --- a/cpp/020array +++ b/cpp/020array @@ -32,8 +32,9 @@ recipe main [ if (t.is_array) { int base = r.value; if (Memory[base] == 0) return 0; - reagent x(t.element[0]); + reagent x; x.set_value(base+1); + x.types.push_back(t.element[0]); return 1 + Memory[base]*size_of(x); } @@ -53,12 +54,15 @@ case INDEX: { assert(Type[base_type].is_array); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; size_t offset = instructions[pc].ingredients[1].value; - int src = base_address + 1 + offset*size_of(reagent(Type[base_type].element[0])); + reagent elem; + elem.types.push_back(Type[base_type].element[0]); + int src = base_address + 1 + offset*size_of(elem); trace("run") << "address to copy is " << src; int src_type = Type[base_type].element[0]; trace("run") << "its type is " << src_type; - reagent tmp(src_type); + reagent tmp; tmp.set_value(src); + tmp.types.push_back(src_type); vector<int> result(read_memory(tmp)); trace("run") << "product 0 is " << result[0]; write_memory(instructions[pc].products[0], result); @@ -98,7 +102,9 @@ case INDEX_ADDRESS: { assert(Type[base_type].is_array); trace("run") << "ingredient 1 is " << instructions[pc].ingredients[1].name; size_t offset = instructions[pc].ingredients[1].value; - int src = base_address + 1 + offset*size_of(reagent(Type[base_type].element[0])); + reagent elem; + elem.types.push_back(Type[base_type].element[0]); + int src = base_address + 1 + offset*size_of(elem); trace("run") << "address to copy is " << src; vector<int> result; result.push_back(src); diff --git a/cpp/024brace b/cpp/024brace index f61fb6ac..fdcf12e6 100644 --- a/cpp/024brace +++ b/cpp/024brace @@ -65,7 +65,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(open_braces.top()-index); inst.ingredients.push_back(ing); trace("after-brace") << "jump " << ing.value << ":offset"; @@ -80,7 +80,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[0].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); inst.ingredients.push_back(ing); trace("after-brace") << "jump " << ing.value << ":offset"; @@ -93,7 +93,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(open_braces.top()-index); inst.ingredients.push_back(ing); trace("after-brace") << "jump-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; @@ -106,7 +106,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); inst.ingredients.push_back(ing); trace("after-brace") << "jump-if " << inst.ingredients[0].name << ", " << ing.value << ":offset"; @@ -119,7 +119,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(open_braces.top()-index); inst.ingredients.push_back(ing); trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset"; @@ -132,7 +132,7 @@ void transform_braces(const recipe_number r) { trace("after-brace") << "jump " << inst.ingredients[1].name << ":offset"; } else { - reagent ing(0); // literal + reagent ing; ing.set_value(matching_brace(open_braces.top(), braces) - index - 1); inst.ingredients.push_back(ing); trace("after-brace") << "jump-unless " << inst.ingredients[0].name << ", " << ing.value << ":offset"; |