From e4ac3c9e6e5464a0fc0f8fd3763a572e0e180c04 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sat, 1 Dec 2018 14:13:33 -0800 Subject: 4814 --- html/040brace.cc.html | 78 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) (limited to 'html/040brace.cc.html') diff --git a/html/040brace.cc.html b/html/040brace.cc.html index 79eb6f63..2b5062ae 100644 --- a/html/040brace.cc.html +++ b/html/040brace.cc.html @@ -11,20 +11,21 @@ @@ -59,6 +60,7 @@ if ('onhashchange' in window) { +https://github.com/akkartik/mu/blob/master/040brace.cc
   1 //: Structured programming
   2 //:
@@ -94,18 +96,18 @@ if ('onhashchange' in window) {
  32 +transform: copy ...
  33 
  34 :(before "End Instruction Modifying Transforms")
- 35 Transform.push_back(transform_braces);  // idempotent
+ 35 Transform.push_back(transform_braces);  // idempotent
  36 
  37 :(code)
  38 void transform_braces(const recipe_ordinal r) {
  39   const bool OPEN = false, CLOSE = true;
  40   // use signed integer for step index because we'll be doing arithmetic on it
  41   list<pair<bool/*OPEN/CLOSE*/, /*step*/int> > braces;
- 42   trace(9991, "transform") << "--- transform braces for recipe " << get(Recipe, r).name << end();
- 43   for (int index = 0;  index < SIZE(get(Recipe, r).steps);  ++index) {
- 44     const instruction& inst = get(Recipe, r).steps.at(index);
+ 42   trace(9991, "transform") << "--- transform braces for recipe " << get(Recipe, r).name << end();
+ 43   for (int index = 0;  index < SIZE(get(Recipe, r).steps);  ++index) {
+ 44     const instruction& inst = get(Recipe, r).steps.at(index);
  45     if (inst.label == "{") {
- 46       trace(9993, "transform") << maybe(get(Recipe, r).name) << "push (open, " << index << ")" << end();
+ 46       trace(9993, "transform") << maybe(get(Recipe, r).name) << "push (open, " << index << ")" << end();
  47       braces.push_back(pair<bool,int>(OPEN, index));
  48     }
  49     if (inst.label == "}") {
@@ -114,15 +116,15 @@ if ('onhashchange' in window) {
  52     }
  53   }
  54   stack</*step*/int> open_braces;
- 55   for (int index = 0;  index < SIZE(get(Recipe, r).steps);  ++index) {
- 56     instruction& inst = get(Recipe, r).steps.at(index);
+ 55   for (int index = 0;  index < SIZE(get(Recipe, r).steps);  ++index) {
+ 56     instruction& inst = get(Recipe, r).steps.at(index);
  57     if (inst.label == "{") {
  58       open_braces.push(index);
  59       continue;
  60     }
  61     if (inst.label == "}") {
  62       if (open_braces.empty()) {
- 63         raise << maybe(get(Recipe, r).name) << "unbalanced '}'\n" << end();
+ 63         raise << maybe(get(Recipe, r).name) << "unbalanced '}'\n" << end();
  64         return;
  65       }
  66       open_braces.pop();
@@ -141,7 +143,7 @@ if ('onhashchange' in window) {
  79     // check for errors
  80     if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) {
  81       if (inst.ingredients.empty()) {
- 82         raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end();
+ 82         raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 1 or 2 ingredients, but got none\n" << end();
  83         continue;
  84       }
  85     }
@@ -163,14 +165,14 @@ if ('onhashchange' in window) {
 101     if (inst.name.find("-if") != string::npos || inst.name.find("-unless") != string::npos) {
 102       // conditional branches check arg 1
 103       if (SIZE(inst.ingredients) > 1 && is_literal(inst.ingredients.at(1))) {
-104         trace(9992, "transform") << inst.name << ' ' << inst.ingredients.at(1).name << ":offset" << end();
+104         trace(9992, "transform") << inst.name << ' ' << inst.ingredients.at(1).name << ":offset" << end();
 105         continue;
 106       }
 107     }
 108     else {
 109       // unconditional branches check arg 0
 110       if (!inst.ingredients.empty() && is_literal(inst.ingredients.at(0))) {
-111         trace(9992, "transform") << "jump " << inst.ingredients.at(0).name << ":offset" << end();
+111         trace(9992, "transform") << "jump " << inst.ingredients.at(0).name << ":offset" << end();
 112         continue;
 113       }
 114     }
@@ -178,7 +180,7 @@ if ('onhashchange' in window) {
 116     reagent target(new type_tree("offset"));
 117     target.set_value(0);
 118     if (open_braces.empty())
-119       raise << maybe(get(Recipe, r).name) << "'" << old_name << "' needs a '{' before\n" << end();
+119       raise << maybe(get(Recipe, r).name) << "'" << old_name << "' needs a '{' before\n" << end();
 120     else if (old_name.find("loop") != string::npos)
 121       target.set_value(open_braces.top()-index);
 122     else  // break instruction
@@ -186,9 +188,9 @@ if ('onhashchange' in window) {
 124     inst.ingredients.push_back(target);
 125     // log computed target
 126     if (inst.name == "jump")
-127       trace(9992, "transform") << "jump " << no_scientific(target.value) << ":offset" << end();
+127       trace(9992, "transform") << "jump " << no_scientific(target.value) << ":offset" << end();
 128     else
-129       trace(9992, "transform") << inst.name << ' ' << inst.ingredients.at(0).name << ", " << no_scientific(target.value) << ":offset" << end();
+129       trace(9992, "transform") << inst.name << ' ' << inst.ingredients.at(0).name << ", " << no_scientific(target.value) << ":offset" << end();
 130   }
 131 }
 132 
@@ -201,8 +203,8 @@ if ('onhashchange' in window) {
 139     stacksize += (p->first ? 1 : -1);
 140     if (stacksize == 0) return p->second;
 141   }
-142   raise << maybe(get(Recipe, r).name) << "unbalanced '{'\n" << end();
-143   return SIZE(get(Recipe, r).steps);  // exit current routine
+142   raise << maybe(get(Recipe, r).name) << "unbalanced '{'\n" << end();
+143   return SIZE(get(Recipe, r).steps);  // exit current routine
 144 }
 145 
 146 :(scenario loop)
@@ -458,7 +460,7 @@ if ('onhashchange' in window) {
 396     curr.clear();
 397   }
 398   else {
-399     raise << "'" << curr.name << "' never yields any products\n" << end();
+399     raise << "'" << curr.name << "' never yields any products\n" << end();
 400   }
 401 }
 402 // rewrite 'return-unless a, b, c, ...' to
@@ -474,7 +476,7 @@ if ('onhashchange' in window) {
 412     curr.clear();
 413   }
 414   else {
-415     raise << "'" << curr.name << "' never yields any products\n" << end();
+415     raise << "'" << curr.name << "' never yields any products\n" << end();
 416   }
 417 }
 418 
@@ -491,14 +493,14 @@ if ('onhashchange' in window) {
 429 
 430   // <break command> <condition>
 431   instruction break_inst;
-432   break_inst.operation = get(Recipe_ordinal, break_command);
+432   break_inst.operation = get(Recipe_ordinal, break_command);
 433   break_inst.name = break_command;
 434   break_inst.ingredients.push_back(condition);
 435   out.steps.push_back(break_inst);
 436 
 437   // return <return ingredients>
 438   instruction return_inst;
-439   return_inst.operation = get(Recipe_ordinal, "return");
+439   return_inst.operation = get(Recipe_ordinal, "return");
 440   return_inst.name = "return";
 441   return_inst.ingredients.swap(return_ingredients);
 442   return_inst.original_string = inst.original_string;
@@ -521,12 +523,12 @@ if ('onhashchange' in window) {
 459 LOOP_IF,
 460 LOOP_UNLESS,
 461 :(before "End Primitive Recipe Numbers")
-462 put(Recipe_ordinal, "break", BREAK);
-463 put(Recipe_ordinal, "break-if", BREAK_IF);
-464 put(Recipe_ordinal, "break-unless", BREAK_UNLESS);
-465 put(Recipe_ordinal, "loop", LOOP);
-466 put(Recipe_ordinal, "loop-if", LOOP_IF);
-467 put(Recipe_ordinal, "loop-unless", LOOP_UNLESS);
+462 put(Recipe_ordinal, "break", BREAK);
+463 put(Recipe_ordinal, "break-if", BREAK_IF);
+464 put(Recipe_ordinal, "break-unless", BREAK_UNLESS);
+465 put(Recipe_ordinal, "loop", LOOP);
+466 put(Recipe_ordinal, "loop-if", LOOP_IF);
+467 put(Recipe_ordinal, "loop-unless", LOOP_UNLESS);
 468 :(before "End Primitive Recipe Checks")
 469 case BREAK: break;
 470 case BREAK_IF: break;
-- 
cgit 1.4.1-2-gfad0