From f344b250f6f062a1a1902bf69b23ebf9b565de0e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 17 Sep 2016 15:01:51 -0700 Subject: 3395 --- html/038new_text.cc.html | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'html/038new_text.cc.html') diff --git a/html/038new_text.cc.html b/html/038new_text.cc.html index f9565ba4..81b50bde 100644 --- a/html/038new_text.cc.html +++ b/html/038new_text.cc.html @@ -32,40 +32,44 @@ body { font-size: 12pt; font-family: monospace; color: #eeeeee; background-color
-//: Extend 'new' to handle a unicode string literal argument.
+//: Extend 'new' to handle a unicode string literal argument or 'text'.
+
+//: A Mu text is an address to an array of characters.
+:(before "End Mu Types Initialization")
+put(Type_abbreviations, "text", new_type_tree("address:array:character"));
 
 :(scenario new_string)
 def main [
-  1:address:array:character <- new [abc def]
-  2:character <- index *1:address:array:character, 5
+  1:text <- new [abc def]
+  2:char <- index *1:text, 5
 ]
 # number code for 'e'
 +mem: storing 101 in location 2
 
 :(scenario new_string_handles_unicode)
 def main [
-  1:address:array:character <- new [a«c]
-  2:number <- length *1:address:array:character
-  3:character <- index *1:address:array:character, 1
+  1:text <- new [a«c]
+  2:num <- length *1:text
+  3:char <- index *1:text, 1
 ]
 +mem: storing 3 in location 2
 # unicode for '«'
 +mem: storing 171 in location 3
 
 :(before "End NEW Check Special-cases")
-if (is_literal_string(inst.ingredients.at(0))) break;
+if (is_literal_text(inst.ingredients.at(0))) break;
 :(before "Convert 'new' To 'allocate'")
-if (inst.name == "new" && is_literal_string(inst.ingredients.at(0))) continue;
+if (inst.name == "new" && is_literal_text(inst.ingredients.at(0))) continue;
 :(after "case NEW" following "Primitive Recipe Implementations")
-  if (is_literal_string(current_instruction().ingredients.at(0))) {
+  if (is_literal_text(current_instruction().ingredients.at(0))) {
     products.resize(1);
-    products.at(0).push_back(new_mu_string(current_instruction().ingredients.at(0).name));
+    products.at(0).push_back(new_mu_text(current_instruction().ingredients.at(0).name));
     trace(9999, "mem") << "new string alloc: " << products.at(0).at(0) << end();
     break;
   }
 
 :(code)
-int new_mu_string(const string& contents) {
+int new_mu_text(const string& contents) {
   // allocate an array just large enough for it
   int string_length = unicode_length(contents);
 //?   Total_alloc += string_length+1;
@@ -96,48 +100,48 @@ def main [
 
 :(scenario stash_string)
 def main [
-  1:address:array:character <- new [abc]
-  stash [foo:], 1:address:array:character
+  1:text <- new [abc]
+  stash [foo:], 1:text
 ]
 +app: foo: abc
 
 :(before "End print Special-cases(r, data)")
-if (is_mu_string(r)) {
+if (is_mu_text(r)) {
   assert(scalar(data));
-  return read_mu_string(data.at(0));
+  return read_mu_text(data.at(0));
 }
 
 :(scenario unicode_string)
 def main [
-  1:address:array:character <- new [♠]
-  stash [foo:], 1:address:array:character
+  1:text <- new [♠]
+  stash [foo:], 1:text
 ]
 +app: foo: ♠
 
 :(scenario stash_space_after_string)
 def main [
-  1:address:array:character <- new [abc]
-  stash 1:address:array:character, [foo]
+  1:text <- new [abc]
+  stash 1:text, [foo]
 ]
 +app: abc foo
 
 :(scenario stash_string_as_array)
 def main [
-  1:address:array:character <- new [abc]
-  stash *1:address:array:character
+  1:text <- new [abc]
+  stash *1:text
 ]
 +app: 3 97 98 99
 
 //: fixes way more than just stash
-:(before "End Preprocess is_mu_string(reagent x)")
+:(before "End Preprocess is_mu_text(reagent x)")
 if (!canonize_type(x)) return false;
 
 //: Allocate more to routine when initializing a literal string
 :(scenario new_string_overflow)
 % Initial_memory_per_routine = 3;
 def main [
-  1:address:number/raw <- new number:type
-  2:address:array:character/raw <- new [a]  # not enough room in initial page, if you take the refcount and array length into account
+  1:address:num/raw <- new number:type
+  2:text/raw <- new [a]  # not enough room in initial page, if you take the refcount and array length into account
 ]
 +new: routine allocated memory from 1000 to 1003
 +new: routine allocated memory from 1003 to 1006
@@ -156,7 +160,7 @@ def main [
   return result;
 }
 
-string read_mu_string(int address) {
+string read_mu_text(int address) {
   if (address == 0) return "";
   ++address;  // skip refcount
   int size = get_or_insert(Memory, address);
-- 
cgit 1.4.1-2-gfad0