about summary refs log tree commit diff stats
path: root/cpp/019address
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-26 17:20:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-26 17:20:16 -0700
commit5b56734835099488220b82fe5f08fda8efb67899 (patch)
treee50dadf561b15175f1609a66c6f505bcb1a49582 /cpp/019address
parentfae7033152eebfa7d860146afbfd58f1fb2e7556 (diff)
downloadmu-5b56734835099488220b82fe5f08fda8efb67899.tar.gz
976
Diffstat (limited to 'cpp/019address')
-rw-r--r--cpp/019address35
1 files changed, 4 insertions, 31 deletions
diff --git a/cpp/019address b/cpp/019address
index a642ceb1..07487499 100644
--- a/cpp/019address
+++ b/cpp/019address
@@ -12,24 +12,8 @@ recipe main [
 +mem: location 2 is 34
 +mem: storing 34 in location 3
 
-:(replace{} "vector<int> read_memory(reagent x)")
-vector<int> read_memory(reagent x) {
-  vector<int> result;
-  if (isa_literal(x)) {
-    result.push_back(x.value);
-    return result;
-  }
-  x = canonize(x);
-  int base = x.value;
-//?   cout << "base: " << base << '\n'; //? 1
-  size_t size = size_of(x);
-  for (size_t offset = 0; offset < size; ++offset) {
-    int val = Memory[base+offset];
-    trace("mem") << "location " << base+offset << " is " << val;
-    result.push_back(val);
-  }
-  return result;
-}
+:(before "int base = x.value" following "vector<int> read_memory(reagent x)")
+x = canonize(x);
 
 //: similarly, write to addresses pointing at other locations using the
 //: 'deref' property
@@ -42,19 +26,8 @@ recipe main [
 +mem: location 1 is 2
 +mem: storing 34 in location 2
 
-:(replace{} "void write_memory(reagent x, vector<int> data)")
-void write_memory(reagent x, vector<int> data) {
-  if (x.name == "_") return;  // dummy results are never stored
-  x = canonize(x);
-//?   cout << x.to_string() << '\n'; //? 1
-  int base = x.value;
-  if (!Type[x.types[0]].is_array && size_of(x) != data.size())
-    raise << "size mismatch in storing to " << x.to_string();
-  for (size_t offset = 0; offset < data.size(); ++offset) {
-    trace("mem") << "storing " << data[offset] << " in location " << base+offset;
-    Memory[base+offset] = data[offset];
-  }
-}
+:(before "int base = x.value" following "void write_memory(reagent x, vector<int> data)")
+x = canonize(x);
 
 :(code)
 reagent canonize(reagent x) {