about summary refs log tree commit diff stats
path: root/cpp/027space
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-03-29 10:21:15 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-03-29 23:20:02 -0700
commit2f5f7919fd29ff05a8f182d3cb1aa9d168b58b66 (patch)
tree278fdbfdd7ec8f928ba15a24bc5b99cd4df63371 /cpp/027space
parent9c5d8413de6a6c8763446f96ce89197a80c514ba (diff)
downloadmu-2f5f7919fd29ff05a8f182d3cb1aa9d168b58b66.tar.gz
994 - spaces now check bounds
I'm not testing for bounds-check errors yet, though.
Diffstat (limited to 'cpp/027space')
-rw-r--r--cpp/027space11
1 files changed, 8 insertions, 3 deletions
diff --git a/cpp/027space b/cpp/027space
index 05703e52..11eb36c5 100644
--- a/cpp/027space
+++ b/cpp/027space
@@ -4,9 +4,10 @@
 
 :(scenarios run)
 :(scenario "set_default_space")
-# if default-space is 10, the array of locals begins at location 11
-# and so location 1 is really location 12
+# if default-space is 10, and if an array of 5 locals lies from location 11 to 15 (inclusive),
+# then location 0 is really location 11, location 1 is really location 12, and so on.
 recipe main [
+  10:integer <- copy 5:literal  # pretend array; in practice we'll use new
   default-space:address:space <- copy 10:literal
   1:integer <- copy 23:literal
 ]
@@ -41,7 +42,11 @@ int space(const reagent& x) {
 
 int address(int offset, int base) {
   if (base == 0) return offset;  // raw
-  return base+offset+1;
+  if (offset >= Memory[base]) {
+    // todo: test
+    raise << "location " << offset << " is out of bounds " << Memory[base] << '\n';
+  }
+  return base+1 + offset;
 }
 
 :(after "void write_memory(reagent x, vector<int> data)")