From c5ffb6e1cc9c5ff880d037c53b8ebc8562be0008 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 25 May 2015 22:27:19 -0700 Subject: 1459 --- html/040brace.cc.html | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'html/040brace.cc.html') diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 12ed2c80..4e39311b 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -2,7 +2,7 @@ -~/Desktop/s/mu/040brace.cc +040brace.cc @@ -73,21 +73,23 @@ void transform_braces(const recipe_number r//? cout << "AAA transform_braces\n"; //? 1 //? exit(0); //? 1 const int OPEN = 0, CLOSE = 1; - list<pair<int/*OPEN/CLOSE*/, /*step*/index_t> > braces; - for (index_t index = 0; index < Recipe[r].steps.size(); ++index) { + // use signed integer for step index because we'll be doing arithmetic on it + list<pair<int/*OPEN/CLOSE*/, /*step*/long long int> > braces; + for (long long int index = 0; index < SIZE(Recipe[r].steps); ++index) { const instruction& inst = Recipe[r].steps.at(index); if (inst.label == "{") { trace("brace") << r << ": push (open, " << index << ")"; - braces.push_back(pair<int,index_t>(OPEN, index)); + braces.push_back(pair<int,long long int>(OPEN, index)); } if (inst.label == "}") { trace("brace") << "push (close, " << index << ")"; - braces.push_back(pair<int,index_t>(CLOSE, index)); + braces.push_back(pair<int,long long int>(CLOSE, index)); } } - stack</*step*/index_t> open_braces; + stack</*step*/long long int> open_braces; trace("after-brace") << "recipe " << Recipe[r].name; - for (index_t index = 0; index < Recipe[r].steps.size(); ++index) { + for (long long int index = 0; index < SIZE(Recipe[r].steps); ++index) { +//? cerr << index << '\n'; //? 1 instruction& inst = Recipe[r].steps.at(index); //? cout << "AAA " << inst.name << ": " << inst.operation << '\n'; //? 1 if (inst.label == "{") open_braces.push(index); @@ -96,7 +98,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 && isa_literal(inst.ingredients.at(0))) { + if (!inst.ingredients.empty() && isa_literal(inst.ingredients.at(0))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(0).name << ":offset"; } @@ -112,7 +114,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 && isa_literal(inst.ingredients.at(0))) { + if (!inst.ingredients.empty() && isa_literal(inst.ingredients.at(0))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(0).name << ":offset"; } @@ -126,7 +128,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 && isa_literal(inst.ingredients.at(1))) { + if (SIZE(inst.ingredients) > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } @@ -140,7 +142,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 && isa_literal(inst.ingredients.at(1))) { + if (SIZE(inst.ingredients) > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } @@ -154,7 +156,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 && isa_literal(inst.ingredients.at(1))) { + if (SIZE(inst.ingredients) > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } @@ -169,7 +171,7 @@ void transform_braces(const recipe_number r(inst.operation == Recipe_number["break-unless"]) { //? cout << "AAA break-unless\n"; //? 1 inst.operation = Recipe_number["jump-unless"]; - if (inst.ingredients.size() > 1 && isa_literal(inst.ingredients.at(1))) { + if (SIZE(inst.ingredients) > 1 && isa_literal(inst.ingredients.at(1))) { // explicit target; a later phase will handle it trace("after-brace") << "jump " << inst.ingredients.at(1).name << ":offset"; } @@ -187,9 +189,11 @@ void transform_braces(const recipe_number r} } -int matching_brace(index_t index, const list<pair<int, index_t> >& braces) { +// returns a signed integer not just so that we can return -1 but also to +// enable future signed arithmetic +long long int matching_brace(long long int index, const list<pair<int, long long int> >& braces) { int stacksize = 0; - for (list<pair<int, index_t> >::const_iterator p = braces.begin(); p != braces.end(); ++p) { + for (list<pair<int, long long int> >::const_iterator p = braces.begin(); p != braces.end(); ++p) { if (p->second < index) continue; stacksize += (p->first ? 1 : -1); if (stacksize == 0) return p->second; -- cgit 1.4.1-2-gfad0