about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-24 09:16:17 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-24 09:18:20 -0700
commit23d3a02226973f80188e84fa5dcedb14413c5b7f (patch)
tree3c73284cb795e74d78e53b72df470cafca4c70cf /020run.cc
parent377b00b045289a3fa8e88d4b2f129d797c687e2f (diff)
downloadmu-23d3a02226973f80188e84fa5dcedb14413c5b7f.tar.gz
4266 - space for alloc-id in heap allocations
This has taken me almost 6 weeks :(
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc39
1 files changed, 38 insertions, 1 deletions
diff --git a/020run.cc b/020run.cc
index 3739ad2c..740f881b 100644
--- a/020run.cc
+++ b/020run.cc
@@ -87,6 +87,10 @@ void run_current_routine() {
       // Primitive Recipe Implementations
       case COPY: {
         copy(ingredients.begin(), ingredients.end(), inserter(products, products.begin()));
+        for (int i = 0;  i < SIZE(current_instruction().products);  ++i) {
+          if (is_mu_scalar(current_instruction().products.at(i)) && is_mu_address(current_instruction().ingredients.at(i)))
+            products.at(i).erase(products.at(i).begin());  // ignore alloc id
+        }
         break;
       }
       // End Primitive Recipe Implementations
@@ -125,6 +129,33 @@ bool should_copy_ingredients() {
   return true;
 }
 
+bool is_mu_scalar(reagent/*copy*/ r) {
+  return is_mu_scalar(r.type);
+}
+bool is_mu_scalar(const type_tree* type) {
+  if (!type) return false;
+  if (is_mu_address(type)) return false;
+  if (!type->atom) return false;
+  if (is_literal(type))
+    return type->name != "literal-string";
+  return size_of(type) == 1;
+}
+
+bool is_mu_address(reagent/*copy*/ r) {
+  // End Preprocess is_mu_address(reagent r)
+  return is_mu_address(r.type);
+}
+bool is_mu_address(const type_tree* type) {
+  if (!type) return false;
+  if (is_literal(type)) return false;
+  if (type->atom) return false;
+  if (!type->left->atom) {
+    raise << "invalid type " << to_string(type) << '\n' << end();
+    return false;
+  }
+  return type->left->value == Address_type_ordinal;
+}
+
 //: Some helpers.
 //: Important that they return references into the current routine.
 
@@ -299,6 +330,7 @@ bool ends_with(const string& s, const string& pat) {
 vector<double> read_memory(reagent/*copy*/ x) {
   // Begin Preprocess read_memory(x)
   vector<double> result;
+  if (x.name == "null") result.push_back(/*alloc id*/0);
   if (is_literal(x)) {
     result.push_back(x.value);
     return result;
@@ -358,7 +390,7 @@ int size_of(const type_tree* type) {
       raise << "invalid type " << to_string(type) << '\n' << end();
       return 0;
     }
-    if (type->left->value == Address_type_ordinal) return 1;
+    if (type->left->value == Address_type_ordinal) return 2;  // address and alloc id
     // End size_of(type) Non-atom Special-cases
   }
   // End size_of(type) Special-cases
@@ -421,6 +453,11 @@ def main [
 ]
 +run: _ <- copy {0: "literal"}
 
+:(scenario run_null)
+def main [
+  1:&:num <- copy null
+]
+
 :(scenario write_to_0_disallowed)
 % Hide_errors = true;
 def main [