about summary refs log tree commit diff stats
path: root/043new.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-08-10 23:15:00 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-08-10 23:15:00 -0700
commit9edabeaa21186c089a9b11f63ba3164f9fa753fb (patch)
treebf02bd60f67c53ea49ecd15fb67f3fd58b7138f2 /043new.cc
parentae2b59cf25e2cae2694af1974e550dd1bc5dd137 (diff)
downloadmu-9edabeaa21186c089a9b11f63ba3164f9fa753fb.tar.gz
1975 - let's start using traces in lessons
More friendly way to 'stash' stuff in the trace so that you can toggle
lines of code to see their stashed traces.
Diffstat (limited to '043new.cc')
-rw-r--r--043new.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/043new.cc b/043new.cc
index 89c3cc23..74083660 100644
--- a/043new.cc
+++ b/043new.cc
@@ -346,6 +346,21 @@ long long int new_mu_string(const string& contents) {
   return result;
 }
 
+//: stash recognizes strings
+
+:(scenario stash_string)
+recipe main [
+  x:address:array:character <- new [abc]
+  stash [foo: ], x:address:array:character
+]
++app: foo: abc
+
+:(before "End print Special-cases(reagent r, data)")
+if (is_mu_string(r)) {
+  assert(scalar(data));
+  return read_mu_string(data.at(0));
+}
+
 //: Allocate more to routine when initializing a literal string
 :(scenario new_string_overflow)
 % Initial_memory_per_routine = 2;
@@ -369,3 +384,21 @@ long long int unicode_length(const string& s) {
   }
   return result;
 }
+
+bool is_mu_string(const reagent& x) {
+  return SIZE(x.types) == 3
+      && x.types.at(0) == Type_ordinal["address"]
+      && x.types.at(1) == Type_ordinal["array"]
+      && x.types.at(2) == Type_ordinal["character"];
+}
+
+string read_mu_string(long long int address) {
+  long long int size = Memory[address];
+  if (size == 0) return "";
+  ostringstream tmp;
+  for (long long int curr = address+1; curr <= address+size; ++curr) {
+    // todo: unicode
+    tmp << (char)(int)Memory[curr];
+  }
+  return tmp.str();
+}