about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--029tools.cc47
-rw-r--r--030container.cc9
-rw-r--r--032array.cc10
-rw-r--r--043new.cc33
-rw-r--r--081run_interactive.cc18
5 files changed, 99 insertions, 18 deletions
diff --git a/029tools.cc b/029tools.cc
index 9b090eb2..05753e4b 100644
--- a/029tools.cc
+++ b/029tools.cc
@@ -37,6 +37,53 @@ recipe main [
 ]
 +app: foo
 
+//: a smarter but more limited version of 'trace'
+
+:(before "End Primitive Recipe Declarations")
+STASH,
+:(before "End Primitive Recipe Numbers")
+Recipe_ordinal["stash"] = STASH;
+:(before "End Primitive Recipe Implementations")
+case STASH: {
+  ostringstream out;
+  for (long long int i = 0; i < SIZE(current_instruction().ingredients); ++i) {
+    out << print_mu(current_instruction().ingredients.at(i), ingredients.at(i));
+  }
+  trace(1, "app") << out.str() << end();
+  break;
+}
+
+:(scenario stash_literal_string)
+recipe main [
+  stash [foo]
+]
++app: foo
+
+:(scenario stash_literal_number)
+recipe main [
+  stash [foo: ], 4
+]
++app: foo: 4
+
+:(scenario stash_number)
+recipe main [
+  1:number <- copy 34
+  stash [foo: ], 1:number
+]
++app: foo: 34
+
+:(code)
+string print_mu(const reagent& r, const vector<double>& data) {
+  if (is_literal(r))
+    return r.name;
+  // End print Special-cases(reagent r, data)
+  ostringstream out;
+  for (long long i = 0; i < SIZE(data); ++i) {
+    out << data.at(i) << ' ';
+  }
+  return out.str();
+}
+
 :(before "End Primitive Recipe Declarations")
 HIDE_WARNINGS,
 :(before "End Primitive Recipe Numbers")
diff --git a/030container.cc b/030container.cc
index f7fe8e3a..5bc81a5f 100644
--- a/030container.cc
+++ b/030container.cc
@@ -100,6 +100,15 @@ if (t.kind == container) {
   return result;
 }
 
+:(scenario stash_container)
+recipe main [
+  1:number <- copy 34  # first
+  2:number <- copy 35
+  3:number <- copy 36
+  stash [foo: ], 1:point-number/raw
+]
++app: foo: 34 35 36
+
 //:: To access elements of a container, use 'get'
 :(scenario get)
 recipe main [
diff --git a/032array.cc b/032array.cc
index 7220e0f0..bf51382d 100644
--- a/032array.cc
+++ b/032array.cc
@@ -37,6 +37,16 @@ recipe main [
 +mem: storing 15 in location 8
 +mem: storing 16 in location 9
 
+:(scenario stash_array)
+recipe main [
+  1:number <- copy 3  # length
+  2:number <- copy 14
+  3:number <- copy 15
+  4:number <- copy 16
+  stash [foo: ], 1:array:number
+]
++app: foo: 3 14 15 16
+
 //: disable the size mismatch check since the destination array need not be initialized
 :(before "End size_mismatch(x) Cases")
 if (x.types.at(0) == Type_ordinal["array"]) return false;
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();
+}
diff --git a/081run_interactive.cc b/081run_interactive.cc
index e627b0f6..6ef85afd 100644
--- a/081run_interactive.cc
+++ b/081run_interactive.cc
@@ -240,17 +240,6 @@ string strip_comments(string in) {
   return result.str();
 }
 
-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();
-}
-
 long long int stringified_value_of_location(long long int address) {
   // convert to string
   ostringstream out;
@@ -258,13 +247,6 @@ long long int stringified_value_of_location(long long int address) {
   return new_mu_string(out.str());
 }
 
-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"];
-}
-
 long long int trace_contents(const string& layer) {
   if (!Trace_stream) return 0;
 //?   cerr << "trace stream exists\n"; //? 1