about summary refs log tree commit diff stats
path: root/020run.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-08-16 14:30:19 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-08-16 14:39:38 -0700
commit7a29cf544e73fbd516b2e6118c093fd5df81a274 (patch)
tree9a0f9b566d1d1199f72d9f6839de69c6205aa430 /020run.cc
parent6a218cff3ae7e7d5a77da493d1ba42c6be95a2fc (diff)
downloadmu-7a29cf544e73fbd516b2e6118c093fd5df81a274.tar.gz
3197
Replace an integer with a boolean across two layers of function calls.

It has long been one of the ugliest consequences of my approach with
layers that functions might need to be introduced with unnecessary
arguments simply because we have no clean way to add parameters to a
function definition after the fact -- or to add the default argument
corresponding to that parameter in calls. This problem is exacerbated by
the redundant argument having to be passed in through multiple layers of
functions. In this instance:

In layer 20 we define write_memory with an argument called
'saving_instruction_products' which isn't used yet.

In layer 36 we reveal that we use this argument in a call to
should_update_refcounts_in_write_memory() -- where it is again not used
yet.

Layer 43 finally clarifies what we're shooting for:

  a) In general when we need to update some memory, we always want to
  update refcounts.

  b) The only exception is when we're reclaiming locals in a function
  that set up its stack frame using 'local-scope' (signalling that it
  wants immediate reclamation). At that point we avoid decrementing
  refcounts of 'escaping' addresses that are being returned, and we also
  avoid incrementing refcounts of products in the caller instruction.
  The latter case is basically why we need this boolean and its dance
  across 3 layers.

In summary, write_memory() needs to update refcounts except if:
  we're writing products for an instruction,
  the instruction is not a primitive, and
  the (callee) recipe for the instruction starts with 'local-scope'.
Diffstat (limited to '020run.cc')
-rw-r--r--020run.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/020run.cc b/020run.cc
index 143cc07c..77a132a9 100644
--- a/020run.cc
+++ b/020run.cc
@@ -91,7 +91,7 @@ void run_current_routine()
     }
     else {
       for (int i = 0; i < SIZE(current_instruction().products); ++i)
-        write_memory(current_instruction().products.at(i), products.at(i), i);
+        write_memory(current_instruction().products.at(i), products.at(i), /*saving instruction products rather than some other internal uses*/true);
     }
     // End of Instruction
     finish_instruction:;
@@ -277,7 +277,7 @@ vector<double> read_memory(reagent/*copy*/ x) {
   return result;
 }
 
-void write_memory(reagent/*copy*/ x, const vector<double>& data, const int /*only when called in the run loop above to save results; -1 otherwise*/ product_index) {
+void write_memory(reagent/*copy*/ x, const vector<double>& data, const bool saving_instruction_products) {
   // Begin Preprocess write_memory(x, data)
   if (!x.type) {
     raise << "can't write to '" << to_string(x) << "'; no type\n" << end();