From 20a7d37f74625962c946f027074031d7cd2cbbcb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 13 Nov 2016 09:37:50 -0800 Subject: 3673 --- html/029tools.cc.html | 11 ++--- html/038new_text.cc.html | 38 ++++++++++++++++- html/058to_text.cc.html | 2 +- html/061text.mu.html | 83 +++++++++++++++++++++++++++++++++++++ html/089scenario_filesystem.cc.html | 8 ---- 5 files changed, 127 insertions(+), 15 deletions(-) diff --git a/html/029tools.cc.html b/html/029tools.cc.html index a6322f9c..da2f41ab 100644 --- a/html/029tools.cc.html +++ b/html/029tools.cc.html @@ -70,7 +70,7 @@ put(Recipe_ordinal,; for (int i = 2; i < SIZE(current_instruction().ingredients); ++i) { if (i > 2) out << ' '; - out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i)); + out << inspect(current_instruction().ingredients.at(i), ingredients.at(i)); } trace(depth, label) << out.str() << end(); break; @@ -91,7 +91,7 @@ put(Recipe_ordinal,; for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) { if (i) out << ' '; - out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i)); + out << inspect(current_instruction().ingredients.at(i), ingredients.at(i)); } trace(2, "app") << out.str() << end(); break; @@ -117,10 +117,10 @@ put(Recipe_ordinal,+app: foo: 34 :(code) -string print_mu(const reagent& r, const vector<double>& data) { +string inspect(const reagent& r, const vector<double>& data) { if (is_literal(r)) return r.name; - // End print Special-cases(r, data) + // End inspect Special-cases(r, data) ostringstream out; for (long long i = 0; i < SIZE(data); ++i) { if (i) out << ' '; @@ -285,6 +285,7 @@ put(Recipe_ordinal,'\n'; } } + // End $print Special-cases else { for (int j = 0; j < SIZE(ingredients.at(i)); ++j) { trace(9998, "run") << "$print: " << ingredients.at(i).at(j) << end(); @@ -368,7 +369,7 @@ put(Recipe_ordinal,case _LOG: { ostringstream out; for (int i = 0; i < SIZE(current_instruction().ingredients); ++i) { - out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i)); + out << inspect(current_instruction().ingredients.at(i), ingredients.at(i)); } LOG << out.str() << '\n'; break; diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html index 0cd1e165..f86c1683 100644 --- a/html/038new_text.cc.html +++ b/html/038new_text.cc.html @@ -16,6 +16,7 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color .Constant { color: #00a0a0; } .CommentedCode { color: #6c6c6c; } .muRecipe { color: #ff8700; } +.SalientComment { color: #00ffff; } .Comment { color: #9090ff; } .Delimiter { color: #800080; } .Special { color: #c00000; } @@ -106,12 +107,17 @@ put(Type_abbreviations,+app: foo: abc -:(before "End print Special-cases(r, data)") +:(before "End inspect Special-cases(r, data)") if (is_mu_text(r)) { assert(scalar(data)); return read_mu_text(data.at(0)); } +:(before "End $print Special-cases") +else if (is_mu_text(current_instruction().ingredients.at(i))) { + cout << read_mu_text(ingredients.at(i).at(0)); +} + :(scenario unicode_string) def main [ 1:text <- new [♠] @@ -172,6 +178,36 @@ string read_mu_text(int} return tmp.str(); } + +//:: 'cheating' by using the host system + +:(before "End Primitive Recipe Declarations") +_READ, +:(before "End Primitive Recipe Numbers") +put(Recipe_ordinal, "$read", _READ); +:(before "End Primitive Recipe Checks") +case _READ: { + break; +} +:(before "End Primitive Recipe Implementations") +case _READ: { + skip_whitespace(cin); + string result; + if (has_data(cin)) + cin >> result; + products.resize(1); + products.at(0).push_back(new_mu_text(result)); + break; +} + +:(code) +void skip_whitespace(istream& in) { + while (true) { + if (!has_data(in)) break; + if (isspace(in.peek())) in.get(); + else break; + } +} diff --git a/html/058to_text.cc.html b/html/058to_text.cc.html index 961df126..e2be9a6f 100644 --- a/html/058to_text.cc.html +++ b/html/058to_text.cc.html @@ -50,7 +50,7 @@ put(Recipe_ordinal,:(before "End Primitive Recipe Implementations") case TO_TEXT: { products.resize(1); - products.at(0).push_back(new_mu_text(print_mu(current_instruction().ingredients.at(0), ingredients.at(0)))); + products.at(0).push_back(new_mu_text(inspect(current_instruction().ingredients.at(0), ingredients.at(0)))); break; } diff --git a/html/061text.mu.html b/html/061text.mu.html index e438b576..08a836b3 100644 --- a/html/061text.mu.html +++ b/html/061text.mu.html @@ -1341,6 +1341,89 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color 1:array:character <- [] ] ] + +def parse-whole-number in:text -> out:num, error?:bool [ + local-scope + load-ingredients + out:num <- copy 0 + result:num <- copy 0 # temporary location + i:num <- copy 0 + len:num <- length *in + { + done?:bool <- greater-or-equal i, len + break-if done? + c:char <- index *in, i + x:num <- character-to-code c + digit:num, error?:bool <- character-code-to-digit x + reply-if error? + result <- multiply result, 10 + result <- add result, digit + i <- add i, 1 + loop + } + # no error; all digits were valid + out <- copy result +] + +# (contributed by Ella Couch) +recipe character-code-to-digit character-code:number -> result:number, error?:boolean [ + local-scope + load-ingredients + result <- copy 0 + error? <- lesser-than character-code, 48 # '0' + reply-if error? + error? <- greater-than character-code, 57 # '9' + reply-if error? + result <- subtract character-code, 48 +] + +scenario character-code-to-digit-contain-only-digit [ + local-scope + a:number <- copy 48 # character code for '0' + run [ + 10:number/raw, 11:boolean/raw <- character-code-to-digit a + ] + memory-should-contain [ + 10 <- 0 + 11 <- 0 # no error + ] +] + +scenario character-code-to-digit-contain-only-digit-2 [ + local-scope + a:number <- copy 57 # character code for '9' + run [ + 1:number/raw, 2:boolean/raw <- character-code-to-digit a + ] + memory-should-contain [ + 1 <- 9 + 2 <- 0 # no error + ] +] + +scenario character-code-to-digit-handles-codes-lower-than-zero [ + local-scope + a:number <- copy 47 + run [ + 10:number/raw, 11:boolean/raw <- character-code-to-digit a + ] + memory-should-contain [ + 10 <- 0 + 11 <- 1 # error + ] +] + +scenario character-code-to-digit-handles-codes-larger-than-nine [ + local-scope + a:number <- copy 58 + run [ + 10:number/raw, 11:boolean/raw <- character-code-to-digit a + ] + memory-should-contain [ + 10 <- 0 + 11 <- 1 # error + ] +] diff --git a/html/089scenario_filesystem.cc.html b/html/089scenario_filesystem.cc.html index d0cc5e17..13cc4a90 100644 --- a/html/089scenario_filesystem.cc.html +++ b/html/089scenario_filesystem.cc.html @@ -278,14 +278,6 @@ string munge_resources_contents(delete type; return result; } - -void skip_whitespace(istream& in) { - while (true) { - if (!has_data(in)) break; - if (isspace(in.peek())) in.get(); - else break; - } -} -- cgit 1.4.1-2-gfad0