about summary refs log tree commit diff stats
path: root/035lookup.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-24 09:38:44 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-24 09:38:44 -0700
commitd82c16098e4f7454b79ee4cad6393949d6f32b18 (patch)
tree42c557bfaff1ce9c30f2c678e6fc453f19d4a2e4 /035lookup.cc
parent7f04b09a97f7ea1aa64a957ca420881bad73484c (diff)
downloadmu-d82c16098e4f7454b79ee4cad6393949d6f32b18.tar.gz
4268 - add a simple validation of the alloc-id
Tautological for now since all alloc-ids are zero.
Diffstat (limited to '035lookup.cc')
-rw-r--r--035lookup.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/035lookup.cc b/035lookup.cc
index ebed6b4d..3b9ae6a2 100644
--- a/035lookup.cc
+++ b/035lookup.cc
@@ -89,6 +89,7 @@ void lookup_memory_core(reagent& x, bool check_for_null) {
   double address = x.value + /*skip alloc id in address*/1;
   double new_value = get_or_insert(Memory, address);
   trace("mem") << "location " << address << " contains " << no_scientific(new_value) << end();
+  // check for null
   if (check_for_null && new_value == 0) {
     if (Current_routine) {
       raise << maybe(current_recipe_name()) << "tried to lookup 0 in '" << to_original_string(current_instruction()) << "'\n" << end();
@@ -98,6 +99,14 @@ void lookup_memory_core(reagent& x, bool check_for_null) {
       raise << "tried to lookup 0\n" << end();
     }
   }
+  // validate alloc-id
+  double alloc_id_in_address = get_or_insert(Memory, x.value);
+  double alloc_id_in_payload = get_or_insert(Memory, new_value);
+  if (alloc_id_in_address != alloc_id_in_payload) {
+      raise << maybe(current_recipe_name()) << "address is already abandoned in '" << to_original_string(current_instruction()) << "'\n" << end();
+      dump_callstack();
+  }
+  // all well; complete the lookup
   x.set_value(new_value+/*skip alloc id in payload*/1);
   drop_from_type(x, "address");
   drop_one_lookup(x);