From fc55fea025bdb1c6945e6812d49a6d41e8f3c062 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 20 Mar 2015 20:27:01 -0700 Subject: 959 --- cpp/.traces/convert_names_passes_dummy | 9 +++++++++ cpp/.traces/run_dummy | 7 +++++++ cpp/010vm | 1 + cpp/013run | 10 ++++++++++ cpp/019address | 1 + cpp/025name | 22 ++++++++++++++++++---- 6 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 cpp/.traces/convert_names_passes_dummy create mode 100644 cpp/.traces/run_dummy diff --git a/cpp/.traces/convert_names_passes_dummy b/cpp/.traces/convert_names_passes_dummy new file mode 100644 index 00000000..08f69ed6 --- /dev/null +++ b/cpp/.traces/convert_names_passes_dummy @@ -0,0 +1,9 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "_", value: 0, type: , properties: [_: ]} +parse/0: product: {name: "x", value: 0, type: 1, properties: [x: integer]} +name/0: assign x 1 +after-brace/0: recipe main +after-brace/0: copy ... +run/0: instruction main/0 +run/0: ingredient 0 is 0 diff --git a/cpp/.traces/run_dummy b/cpp/.traces/run_dummy new file mode 100644 index 00000000..b6aa736f --- /dev/null +++ b/cpp/.traces/run_dummy @@ -0,0 +1,7 @@ +parse/0: instruction: 1 +parse/0: ingredient: {name: "0", value: 0, type: 0, properties: [0: literal]} +parse/0: product: {name: "_", value: 0, type: , properties: [_: ]} +after-brace/0: recipe main +after-brace/0: copy ... +run/0: instruction main/0 +run/0: ingredient 0 is 0 diff --git a/cpp/010vm b/cpp/010vm index d8394fdb..45b4c3e5 100644 --- a/cpp/010vm +++ b/cpp/010vm @@ -104,6 +104,7 @@ struct type_info { bool is_array; vector > elements; // only if is_record vector element; // only if is_array + // End type_info Fields. type_info() :size(0), is_record(false), is_array(false) {} }; diff --git a/cpp/013run b/cpp/013run index 102a7dfb..b26ce56f 100644 --- a/cpp/013run +++ b/cpp/013run @@ -111,6 +111,7 @@ for (size_t i = 0; i < recipes_added_by_test.size(); ++i) { recipes_added_by_test.clear(); :(code) +//: beware: overridden in later layers vector read_memory(reagent x) { //? cout << "read_memory: " << x.to_string() << '\n'; //? 1 vector result; @@ -127,7 +128,9 @@ vector read_memory(reagent x) { return result; } +//: beware: overridden in later layers void write_memory(reagent x, vector data) { + if (x.name == "_") return; // dummy results are never stored int base = x.value; size_t size = size_of(x); if (size != data.size()) raise << "size mismatch in storing to " << x.to_string(); @@ -153,3 +156,10 @@ recipe main [ ] +run: instruction main/1 +run: instruction main/2 +-run: instruction main/0 + +:(scenario run_dummy) +recipe main [ + _ <- copy 0:literal +] ++run: instruction main/0 diff --git a/cpp/019address b/cpp/019address index 608e5e69..540f18e6 100644 --- a/cpp/019address +++ b/cpp/019address @@ -43,6 +43,7 @@ recipe main [ :(replace{} "void write_memory(reagent x, vector data)") void write_memory(reagent x, vector data) { + if (x.name == "_") return; // dummy results are never stored x = canonize(x); int base = x.value; if (!Type[x.types[0]].is_array && size_of(x) != data.size()) diff --git a/cpp/025name b/cpp/025name index 73406a81..24822afb 100644 --- a/cpp/025name +++ b/cpp/025name @@ -1,5 +1,5 @@ //: A big convenience high-level languages provide is the ability to name memory -//: locations. In mu, a lightweight tool called 'convert-names' provides this +//: locations. In mu, a transform called 'convert-names' provides this //: convenience. :(scenarios run) @@ -16,6 +16,8 @@ Transform.push_back(transform_names); :(before "End Globals") unordered_map > Name; +:(before "End Setup") +Name.clear(); :(code) void transform_names(const recipe_number r) { @@ -26,9 +28,11 @@ void transform_names(const recipe_number r) { for (size_t i = 0; i < Recipe[r].steps.size(); ++i) { //? cout << "instruction " << i << '\n'; //? 2 instruction& inst = Recipe[r].steps[i]; + // map names to addresses for (size_t in = 0; in < inst.ingredients.size(); ++in) { //? cout << "ingredient " << inst.ingredients[in].name << '\n'; //? 1 - if (inst.ingredients[in].types[0] + if (!inst.ingredients[in].types.empty() + && inst.ingredients[in].types[0] && inst.ingredients[in].name.find_first_not_of("0123456789-.") != string::npos) { if (names.find(inst.ingredients[in].name) == names.end()) { // todo: test @@ -38,10 +42,12 @@ void transform_names(const recipe_number r) { inst.ingredients[in].initialized = true; } } + // replace names with addresses for (size_t out = 0; out < inst.products.size(); ++out) { -//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 2 +//? cout << "product " << out << '/' << inst.products.size() << " " << inst.products[out].name << '\n'; //? 3 //? cout << inst.products[out].types[0] << '\n'; //? 1 - if (inst.products[out].types[0] + if (!inst.products[out].types.empty() + && inst.products[out].types[0] && inst.products[out].name.find_first_not_of("0123456789-.") != string::npos) { if (names.find(inst.products[out].name) == names.end()) { trace("name") << "assign " << inst.products[out].name << " " << curr_idx; @@ -54,3 +60,11 @@ void transform_names(const recipe_number r) { } } } + +:(scenario "convert_names_passes_dummy") +# _ is just a dummy result that never gets consumed +recipe main [ + _, x:integer <- copy 0:literal +] ++name: assign x 1 +-name: assign _ 1 -- cgit 1.4.1-2-gfad0