From 805d58c6aeeeba3e4989c0eed6781b3861e8fae0 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 25 Jan 2018 22:39:31 -0800 Subject: 4199 --- html/041jump_target.cc.html | 125 ++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 63 deletions(-) (limited to 'html/041jump_target.cc.html') diff --git a/html/041jump_target.cc.html b/html/041jump_target.cc.html index 8119c8da..0b8bfbc3 100644 --- a/html/041jump_target.cc.html +++ b/html/041jump_target.cc.html @@ -15,19 +15,18 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } -.traceContains { color: #008000; } -.Conceal { color: #4e4e4e; } .traceAbsent { color: #c00000; } +.traceContains { color: #008000; } .LineNr { color: #444444; } -.Identifier { color: #c0a020; } .Constant { color: #00a0a0; } +.muRecipe { color: #ff8700; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.Delimiter { color: #800080; } -.Special { color: #c00000; } .cSpecial { color: #008000; } -.muRecipe { color: #ff8700; } --> @@ -96,64 +95,64 @@ if ('onhashchange' in window) { 32 void transform_labels(const recipe_ordinal r) { 33 map<string, int> offset; 34 for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { - 35 ¦ const instruction& inst = get(Recipe, r).steps.at(i); - 36 ¦ if (!inst.is_label) continue; - 37 ¦ if (is_jump_target(inst.label)) { - 38 ¦ ¦ if (!contains_key(offset, inst.label)) { - 39 ¦ ¦ ¦ put(offset, inst.label, i); - 40 ¦ ¦ } - 41 ¦ ¦ else { - 42 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "duplicate label '" << inst.label << "'" << end(); - 43 ¦ ¦ ¦ // have all jumps skip some random but noticeable and deterministic amount of code - 44 ¦ ¦ ¦ put(offset, inst.label, 9999); - 45 ¦ ¦ } - 46 ¦ } + 35 const instruction& inst = get(Recipe, r).steps.at(i); + 36 if (!inst.is_label) continue; + 37 if (is_jump_target(inst.label)) { + 38 if (!contains_key(offset, inst.label)) { + 39 put(offset, inst.label, i); + 40 } + 41 else { + 42 raise << maybe(get(Recipe, r).name) << "duplicate label '" << inst.label << "'" << end(); + 43 // have all jumps skip some random but noticeable and deterministic amount of code + 44 put(offset, inst.label, 9999); + 45 } + 46 } 47 } 48 for (int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { - 49 ¦ instruction& inst = get(Recipe, r).steps.at(i); - 50 ¦ if (inst.name == "jump") { - 51 ¦ ¦ if (inst.ingredients.empty()) { - 52 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' expects an ingredient but got 0\n" << end(); - 53 ¦ ¦ ¦ return; - 54 ¦ ¦ } - 55 ¦ ¦ replace_offset(inst.ingredients.at(0), offset, i, r); - 56 ¦ } - 57 ¦ if (inst.name == "jump-if" || inst.name == "jump-unless") { - 58 ¦ ¦ if (SIZE(inst.ingredients) < 2) { - 59 ¦ ¦ ¦ raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); - 60 ¦ ¦ ¦ return; - 61 ¦ ¦ } - 62 ¦ ¦ replace_offset(inst.ingredients.at(1), offset, i, r); - 63 ¦ } - 64 ¦ if ((inst.name == "loop" || inst.name == "break") - 65 ¦ ¦ ¦ && SIZE(inst.ingredients) >= 1) { - 66 ¦ ¦ replace_offset(inst.ingredients.at(0), offset, i, r); - 67 ¦ } - 68 ¦ if ((inst.name == "loop-if" || inst.name == "loop-unless" - 69 ¦ ¦ ¦ ¦ ¦ || inst.name == "break-if" || inst.name == "break-unless") - 70 ¦ ¦ ¦ && SIZE(inst.ingredients) >= 2) { - 71 ¦ ¦ replace_offset(inst.ingredients.at(1), offset, i, r); - 72 ¦ } + 49 instruction& inst = get(Recipe, r).steps.at(i); + 50 if (inst.name == "jump") { + 51 if (inst.ingredients.empty()) { + 52 raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' expects an ingredient but got 0\n" << end(); + 53 return; + 54 } + 55 replace_offset(inst.ingredients.at(0), offset, i, r); + 56 } + 57 if (inst.name == "jump-if" || inst.name == "jump-unless") { + 58 if (SIZE(inst.ingredients) < 2) { + 59 raise << maybe(get(Recipe, r).name) << "'" << to_original_string(inst) << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); + 60 return; + 61 } + 62 replace_offset(inst.ingredients.at(1), offset, i, r); + 63 } + 64 if ((inst.name == "loop" || inst.name == "break") + 65 && SIZE(inst.ingredients) >= 1) { + 66 replace_offset(inst.ingredients.at(0), offset, i, r); + 67 } + 68 if ((inst.name == "loop-if" || inst.name == "loop-unless" + 69 || inst.name == "break-if" || inst.name == "break-unless") + 70 && SIZE(inst.ingredients) >= 2) { + 71 replace_offset(inst.ingredients.at(1), offset, i, r); + 72 } 73 } 74 } 75 76 void replace_offset(reagent& x, /*const*/ map<string, int>& offset, const int current_offset, const recipe_ordinal r) { 77 if (!is_literal(x)) { - 78 ¦ raise << maybe(get(Recipe, r).name) << "jump target must be offset or label but is '" << x.original_string << "'\n" << end(); - 79 ¦ x.set_value(0); // no jump by default - 80 ¦ return; + 78 raise << maybe(get(Recipe, r).name) << "jump target must be offset or label but is '" << x.original_string << "'\n" << end(); + 79 x.set_value(0); // no jump by default + 80 return; 81 } 82 if (x.initialized) return; 83 if (is_integer(x.name)) return; // non-labels will be handled like other number operands 84 if (!is_jump_target(x.name)) { - 85 ¦ raise << maybe(get(Recipe, r).name) << "can't jump to label '" << x.name << "'\n" << end(); - 86 ¦ x.set_value(0); // no jump by default - 87 ¦ return; + 85 raise << maybe(get(Recipe, r).name) << "can't jump to label '" << x.name << "'\n" << end(); + 86 x.set_value(0); // no jump by default + 87 return; 88 } 89 if (!contains_key(offset, x.name)) { - 90 ¦ raise << maybe(get(Recipe, r).name) << "can't find label '" << x.name << "'\n" << end(); - 91 ¦ x.set_value(0); // no jump by default - 92 ¦ return; + 90 raise << maybe(get(Recipe, r).name) << "can't find label '" << x.name << "'\n" << end(); + 91 x.set_value(0); // no jump by default + 92 return; 93 } 94 x.set_value(get(offset, x.name) - current_offset); 95 } @@ -161,10 +160,10 @@ if ('onhashchange' in window) { 97 :(scenario break_to_label) 98 def main [ 99 { -100 ¦ { -101 ¦ ¦ break +target:label -102 ¦ ¦ 1:num <- copy 0 -103 ¦ } +100 { +101 break +target:label +102 1:num <- copy 0 +103 } 104 } 105 +target 106 ] @@ -173,10 +172,10 @@ if ('onhashchange' in window) { 109 :(scenario jump_if_to_label) 110 def main [ 111 { -112 ¦ { -113 ¦ ¦ jump-if 1, +target:label -114 ¦ ¦ 1:num <- copy 0 -115 ¦ } +112 { +113 jump-if 1, +target:label +114 1:num <- copy 0 +115 } 116 } 117 +target 118 ] @@ -185,10 +184,10 @@ if ('onhashchange' in window) { 121 :(scenario loop_unless_to_label) 122 def main [ 123 { -124 ¦ { -125 ¦ ¦ loop-unless 0, +target:label # loop/break with a label don't care about braces -126 ¦ ¦ 1:num <- copy 0 -127 ¦ } +124 { +125 loop-unless 0, +target:label # loop/break with a label don't care about braces +126 1:num <- copy 0 +127 } 128 } 129 +target 130 ] -- cgit 1.4.1-2-gfad0