From 1c2d788b454670bf8fa1cb65c6251a8ff6ddcaf7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Mon, 19 Jun 2017 11:29:20 -0700 Subject: 3927 --- html/038new_text.cc.html | 173 ++++++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 85 deletions(-) (limited to 'html/038new_text.cc.html') diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html index 28424176..dfa93dd8 100644 --- a/html/038new_text.cc.html +++ b/html/038new_text.cc.html @@ -95,7 +95,7 @@ if ('onhashchange' in window) { 30 if (is_literal_text(current_instruction().ingredients.at(0))) { 31 ¦ products.resize(1); 32 ¦ products.at(0).push_back(new_mu_text(current_instruction().ingredients.at(0).name)); - 33 ¦ trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end(); + 33 ¦ trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end(); 34 ¦ break; 35 } 36 @@ -106,10 +106,10 @@ if ('onhashchange' in window) { 41 //? Total_alloc += string_length+1; 42 //? ++Num_alloc; 43 int result = allocate(string_length+/*array length*/1); - 44 trace(9999, "mem") << "storing string refcount 0 in location " << result << end(); + 44 trace(9999, "mem") << "storing string refcount 0 in location " << result << end(); 45 put(Memory, result, 0); 46 int curr_address = result+/*skip refcount*/1; - 47 trace(9999, "mem") << "storing string length " << string_length << " in location " << curr_address << end(); + 47 trace(9999, "mem") << "storing string length " << string_length << " in location " << curr_address << end(); 48 put(Memory, curr_address, string_length); 49 ++curr_address; // skip length 50 int curr = 0; @@ -118,7 +118,7 @@ if ('onhashchange' in window) { 53 ¦ uint32_t curr_character; 54 ¦ assert(curr < SIZE(contents)); 55 ¦ tb_utf8_char_to_unicode(&curr_character, &raw_contents[curr]); - 56 ¦ trace(9999, "mem") << "storing string character " << curr_character << " in location " << curr_address << end(); + 56 ¦ trace(9999, "mem") << "storing string character " << curr_character << " in location " << curr_address << end(); 57 ¦ put(Memory, curr_address, curr_character); 58 ¦ curr += tb_utf8_char_length(raw_contents[curr]); 59 ¦ ++curr_address; @@ -208,87 +208,90 @@ if ('onhashchange' in window) { 143 string read_mu_text(int address) { 144 if (address == 0) return ""; 145 ++address; // skip refcount -146 int size = get_or_insert(Memory, address); -147 if (size == 0) return ""; -148 ostringstream tmp; -149 for (int curr = address+1; curr <= address+size; ++curr) { -150 ¦ tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); -151 } -152 return tmp.str(); -153 } -154 -155 //:: some miscellaneous helpers now that we have text -156 -157 //: assert: perform sanity checks at runtime -158 -159 :(scenario assert) -160 % Hide_errors = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. -161 def main [ -162 assert 0, [this is an assert in Mu] -163 ] -164 +error: this is an assert in Mu -165 -166 :(before "End Primitive Recipe Declarations") -167 ASSERT, -168 :(before "End Primitive Recipe Numbers") -169 put(Recipe_ordinal, "assert", ASSERT); -170 :(before "End Primitive Recipe Checks") -171 case ASSERT: { -172 if (SIZE(inst.ingredients) != 2) { -173 ¦ raise << maybe(get(Recipe, r).name) << "'assert' takes exactly two ingredients rather than '" << to_original_string(inst) << "'\n" << end(); -174 ¦ break; -175 } -176 if (!is_mu_scalar(inst.ingredients.at(0))) { -177 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); -178 ¦ break; -179 } -180 if (!is_literal_text(inst.ingredients.at(1)) && !is_mu_text(inst.ingredients.at(1))) { -181 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a text as its second ingredient, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); -182 ¦ break; -183 } -184 break; -185 } -186 :(before "End Primitive Recipe Implementations") -187 case ASSERT: { -188 if (!ingredients.at(0).at(0)) { -189 ¦ if (is_literal_text(current_instruction().ingredients.at(1))) -190 ¦ ¦ raise << current_instruction().ingredients.at(1).name << '\n' << end(); -191 ¦ else -192 ¦ ¦ raise << read_mu_text(ingredients.at(1).at(0)) << '\n' << end(); -193 } -194 break; -195 } -196 -197 -198 //: 'cheating' by using the host system -199 -200 :(before "End Primitive Recipe Declarations") -201 _READ, -202 :(before "End Primitive Recipe Numbers") -203 put(Recipe_ordinal, "$read", _READ); -204 :(before "End Primitive Recipe Checks") -205 case _READ: { -206 break; -207 } -208 :(before "End Primitive Recipe Implementations") -209 case _READ: { -210 skip_whitespace(cin); -211 string result; -212 if (has_data(cin)) -213 ¦ cin >> result; -214 products.resize(1); -215 products.at(0).push_back(new_mu_text(result)); -216 break; -217 } -218 -219 :(code) -220 void skip_whitespace(istream& in) { -221 while (true) { -222 ¦ if (!has_data(in)) break; -223 ¦ if (isspace(in.peek())) in.get(); -224 ¦ else break; -225 } -226 } +146 int length = get_or_insert(Memory, address); +147 if (length == 0) return ""; +148 return read_mu_characters(address+1, length); +149 } +150 +151 string read_mu_characters(int start, int length) { +152 ostringstream tmp; +153 for (int curr = start; curr < start+length; ++curr) +154 ¦ tmp << to_unicode(static_cast<uint32_t>(get_or_insert(Memory, curr))); +155 return tmp.str(); +156 } +157 +158 //:: some miscellaneous helpers now that we have text +159 +160 //: assert: perform sanity checks at runtime +161 +162 :(scenario assert) +163 % Hide_errors = true; // '%' lines insert arbitrary C code into tests before calling 'run' with the lines below. Must be immediately after :(scenario) line. +164 def main [ +165 assert 0, [this is an assert in Mu] +166 ] +167 +error: this is an assert in Mu +168 +169 :(before "End Primitive Recipe Declarations") +170 ASSERT, +171 :(before "End Primitive Recipe Numbers") +172 put(Recipe_ordinal, "assert", ASSERT); +173 :(before "End Primitive Recipe Checks") +174 case ASSERT: { +175 if (SIZE(inst.ingredients) != 2) { +176 ¦ raise << maybe(get(Recipe, r).name) << "'assert' takes exactly two ingredients rather than '" << to_original_string(inst) << "'\n" << end(); +177 ¦ break; +178 } +179 if (!is_mu_scalar(inst.ingredients.at(0))) { +180 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a boolean for its first ingredient, but got '" << inst.ingredients.at(0).original_string << "'\n" << end(); +181 ¦ break; +182 } +183 if (!is_literal_text(inst.ingredients.at(1)) && !is_mu_text(inst.ingredients.at(1))) { +184 ¦ raise << maybe(get(Recipe, r).name) << "'assert' requires a text as its second ingredient, but got '" << inst.ingredients.at(1).original_string << "'\n" << end(); +185 ¦ break; +186 } +187 break; +188 } +189 :(before "End Primitive Recipe Implementations") +190 case ASSERT: { +191 if (!ingredients.at(0).at(0)) { +192 ¦ if (is_literal_text(current_instruction().ingredients.at(1))) +193 ¦ ¦ raise << current_instruction().ingredients.at(1).name << '\n' << end(); +194 ¦ else +195 ¦ ¦ raise << read_mu_text(ingredients.at(1).at(0)) << '\n' << end(); +196 ¦ if (!Hide_errors) exit(1); +197 } +198 break; +199 } +200 +201 //: 'cheating' by using the host system +202 +203 :(before "End Primitive Recipe Declarations") +204 _READ, +205 :(before "End Primitive Recipe Numbers") +206 put(Recipe_ordinal, "$read", _READ); +207 :(before "End Primitive Recipe Checks") +208 case _READ: { +209 break; +210 } +211 :(before "End Primitive Recipe Implementations") +212 case _READ: { +213 skip_whitespace(cin); +214 string result; +215 if (has_data(cin)) +216 ¦ cin >> result; +217 products.resize(1); +218 products.at(0).push_back(new_mu_text(result)); +219 break; +220 } +221 +222 :(code) +223 void skip_whitespace(istream& in) { +224 while (true) { +225 ¦ if (!has_data(in)) break; +226 ¦ if (isspace(in.peek())) in.get(); +227 ¦ else break; +228 } +229 } -- cgit 1.4.1-2-gfad0