about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-16 14:52:05 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-16 14:52:05 -0700
commit1cd2691b0637cd0ab6be6576e487c0140083ba86 (patch)
tree9ed2add37dc701bca776a9ef7efa909fbb5b7306
parent86033d4bdd44c5d50abfd6370adc026a14f8c9ae (diff)
downloadmu-1cd2691b0637cd0ab6be6576e487c0140083ba86.tar.gz
3199
Never mind, just close your nose and replace that function parameter
with a global variable.

This may not always be the solution for the problem of layers being
unable to add parameters and arguments, but here it works well and it's
unclear what problems the global might cause.
-rw-r--r--020run.cc7
-rw-r--r--036refcount.cc10
-rw-r--r--043space.cc13
-rw-r--r--074deep_copy.cc2
4 files changed, 17 insertions, 15 deletions
diff --git a/020run.cc b/020run.cc
index 77a132a9..8d769730 100644
--- a/020run.cc
+++ b/020run.cc
@@ -86,13 +86,15 @@ void run_current_routine()
         cout << "not a primitive op: " << current_instruction().operation << '\n';
       }
     }
+    // Write Products of Instruction
     if (SIZE(products) < SIZE(current_instruction().products)) {
       raise << SIZE(products) << " vs " << SIZE(current_instruction().products) << ": failed to write to all products! " << to_original_string(current_instruction()) << '\n' << end();
     }
     else {
       for (int i = 0; i < SIZE(current_instruction().products); ++i)
-        write_memory(current_instruction().products.at(i), products.at(i), /*saving instruction products rather than some other internal uses*/true);
+        write_memory(current_instruction().products.at(i), products.at(i));
     }
+    // End Write Products of Instruction
     // End of Instruction
     finish_instruction:;
     ++current_step_index();
@@ -277,7 +279,8 @@ vector<double> read_memory(reagent/*copy*/ x) {
   return result;
 }
 
-void write_memory(reagent/*copy*/ x, const vector<double>& data, const bool saving_instruction_products) {
+void write_memory(reagent/*copy*/ x, const vector<double>& data) {
+  assert(Current_routine);  // run-time only
   // Begin Preprocess write_memory(x, data)
   if (!x.type) {
     raise << "can't write to '" << to_string(x) << "'; no type\n" << end();
diff --git a/036refcount.cc b/036refcount.cc
index 51a0945a..c1a12525 100644
--- a/036refcount.cc
+++ b/036refcount.cc
@@ -17,8 +17,11 @@ def main [
 +run: {2: ("address" "number")} <- copy {0: "literal"}
 +mem: decrementing refcount of 1000: 1 -> 0
 
+:(before "End Globals")
+//: escape hatch for a later layer
+bool Update_refcounts_in_write_memory = true;
 :(before "End write_memory(x) Special-cases")
-if (should_update_refcounts_in_write_memory(saving_instruction_products)) {
+if (Update_refcounts_in_write_memory) {
   if (is_mu_address(x)) {
     assert(scalar(data));
     assert(x.value);
@@ -29,11 +32,6 @@ if (should_update_refcounts_in_write_memory(saving_instruction_products)) {
 }
 
 :(code)
-//: hook for a later layer
-bool should_update_refcounts_in_write_memory(bool conditional_update) {
-  return true;
-}
-
 void update_refcounts(const reagent& old, int new_address) {
   assert(is_mu_address(old));
   update_refcounts(get_or_insert(Memory, old.value), new_address, old.type->right, payload_size(old));
diff --git a/043space.cc b/043space.cc
index cb58d97d..9ee280d8 100644
--- a/043space.cc
+++ b/043space.cc
@@ -247,7 +247,7 @@ void try_reclaim_locals() {
       if (escaping(inst.products.at(i))) continue;
       trace(9999, "mem") << "clearing " << inst.products.at(i).original_string << end();
       zeros.resize(size_of(inst.products.at(i)));
-      write_memory(inst.products.at(i), zeros, /*always update refcounts*/false);
+      write_memory(inst.products.at(i), zeros);
     }
   }
   trace(9999, "mem") << "automatically abandoning " << current_call().default_space << end();
@@ -275,10 +275,12 @@ bool escaping(const reagent& r) {
 //: since we don't decrement refcounts for escaping values above, make sure we
 //: don't increment them when the caller saves them either
 
-:(replace{} "bool should_update_refcounts_in_write_memory(bool conditional_update)")
-bool should_update_refcounts_in_write_memory(bool conditional_update) {
-  assert(Current_routine);  // run-time only
-  if (!conditional_update) return true;
+:(after "Write Products of Instruction")
+Update_refcounts_in_write_memory = should_update_refcounts_in_write_memory();
+:(before "End Write Products of Instruction")
+Update_refcounts_in_write_memory = true;
+:(code)
+bool should_update_refcounts_in_write_memory() {
   const instruction& inst = current_instruction();
   if (inst.operation < MAX_PRIMITIVE_RECIPES) return true;
   if (!contains_key(Recipe, inst.operation)) return true;
@@ -288,7 +290,6 @@ bool should_update_refcounts_in_write_memory(bool conditional_update) {
   return caller.steps.at(0).old_name != "local-scope";
 }
 
-:(code)
 bool caller_uses_product(int product_index) {
   assert(Current_routine);  // run-time only
   assert(!Current_routine->calls.empty());
diff --git a/074deep_copy.cc b/074deep_copy.cc
index 34100de5..e47cd044 100644
--- a/074deep_copy.cc
+++ b/074deep_copy.cc
@@ -264,7 +264,7 @@ int deep_copy_address(const reagent& canonized_in, map<int, int>& addresses_copi
   payload.value = tmp.value;  // now modified for output
   vector<double> old_data = read_memory(payload);
   trace(9991, "run") << "deep-copy: really writing to " << payload.value << ' ' << to_string(payload) << " (old value " << to_string(old_data) << " new value " << to_string(data) << ")" << end();
-  write_memory(payload, data, /*always update refcounts*/false);
+  write_memory(payload, data);
   trace(9991, "run") << "deep-copy: output is " << to_string(data) << end();
   return out;
 }