about summary refs log tree commit diff stats
path: root/035lookup.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
committerKartik Agaram <vc@akkartik.com>2018-06-15 22:12:03 -0700
commit0edd9b9fc60440213e4df926ea511419ee291f1e (patch)
tree84b22f7afdeb9110ad7105c5fc070dacff178502 /035lookup.cc
parent3f34ac9369978b396d00a4fd02c9fb06b8eea621 (diff)
downloadmu-0edd9b9fc60440213e4df926ea511419ee291f1e.tar.gz
4257 - abortive attempt at safe fat pointers
I've been working on this slowly over several weeks, but it's too hard
to support 0 as the null value for addresses. I constantly have to add
exceptions for scalar value corresponding to an address type (now
occupying 2 locations). The final straw is the test for 'reload':

  x:num <- reload text

'reload' returns an address. But there's no way to know that for
arbitrary instructions.

New plan: let's put this off for a bit and first create support for
literals. Then use 'null' instead of '0' for addresses everywhere. Then
it'll be easy to just change what 'null' means.
Diffstat (limited to '035lookup.cc')
-rw-r--r--035lookup.cc106
1 files changed, 59 insertions, 47 deletions
diff --git a/035lookup.cc b/035lookup.cc
index a2647f5d..9708ce5b 100644
--- a/035lookup.cc
+++ b/035lookup.cc
@@ -6,7 +6,8 @@
 :(scenario copy_indirect)
 def main [
   1:address:num <- copy 10/unsafe
-  10:num <- copy 34
+  # skip alloc id
+  11:num <- copy 34
   # This loads location 1 as an address and looks up *that* location.
   2:num <- copy 1:address:num/lookup
 ]
@@ -22,7 +23,7 @@ def main [
   1:address:num <- copy 10/unsafe
   1:address:num/lookup <- copy 34
 ]
-+mem: storing 34 in location 10
++mem: storing 34 in location 11
 
 :(before "End Preprocess write_memory(x, data)")
 canonize(x);
@@ -35,7 +36,7 @@ def main [
   1:address:num/lookup <- copy 34
 ]
 -mem: storing 34 in location 0
-+error: can't write to location 0 in '1:address:num/lookup <- copy 34'
++error: main: tried to lookup 0 in '1:address:num/lookup <- copy 34'
 
 //: attempts to /lookup address 0 always loudly fail
 :(scenario lookup_0_fails)
@@ -82,7 +83,7 @@ void lookup_memory(reagent& x) {
 }
 
 void lookup_memory_core(reagent& x, bool check_for_null) {
-  double address = x.value;
+  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();
   if (check_for_null && new_value == 0) {
@@ -94,12 +95,18 @@ void lookup_memory_core(reagent& x, bool check_for_null) {
       raise << "tried to lookup 0\n" << end();
     }
   }
-  x.set_value(new_value);
+  x.set_value(new_value+/*skip alloc id in payload*/1);
   drop_from_type(x, "address");
   drop_one_lookup(x);
 }
 
-:(before "End Preprocess types_strictly_match(reagent to, reagent from)")
+:(after "Begin types_coercible(reagent to, reagent from)")
+if (!canonize_type(to)) return false;
+if (!canonize_type(from)) return false;
+:(after "Begin types_match(reagent to, reagent from)")
+if (!canonize_type(to)) return false;
+if (!canonize_type(from)) return false;
+:(after "Begin types_strictly_match(reagent to, reagent from)")
 if (!canonize_type(to)) return false;
 if (!canonize_type(from)) return false;
 
@@ -157,30 +164,33 @@ void drop_one_lookup(reagent& r) {
 :(scenario get_indirect)
 def main [
   1:address:point <- copy 10/unsafe
-  10:num <- copy 34
-  11:num <- copy 35
-  2:num <- get 1:address:point/lookup, 0:offset
+  # skip alloc id
+  11:num <- copy 34
+  12:num <- copy 35
+  20:num <- get 1:address:point/lookup, 0:offset
 ]
-+mem: storing 34 in location 2
++mem: storing 34 in location 20
 
 :(scenario get_indirect2)
 def main [
   1:address:point <- copy 10/unsafe
-  10:num <- copy 34
-  11:num <- copy 35
-  2:address:num <- copy 20/unsafe
-  2:address:num/lookup <- get 1:address:point/lookup, 0:offset
+  # skip alloc id
+  11:num <- copy 94
+  12:num <- copy 95
+  20:address:num <- copy 30/unsafe
+  20:address:num/lookup <- get 1:address:point/lookup, 0:offset
 ]
-+mem: storing 34 in location 20
++mem: storing 94 in location 31
 
 :(scenario include_nonlookup_properties)
 def main [
   1:address:point <- copy 10/unsafe
-  10:num <- copy 34
-  11:num <- copy 35
-  2:num <- get 1:address:point/lookup/foo, 0:offset
+  # skip alloc id
+  11:num <- copy 34
+  12:num <- copy 35
+  20:num <- get 1:address:point/lookup/foo, 0:offset
 ]
-+mem: storing 34 in location 2
++mem: storing 34 in location 20
 
 :(after "Update GET base in Check")
 if (!canonize_type(base)) break;
@@ -192,11 +202,12 @@ canonize(base);
 :(scenario put_indirect)
 def main [
   1:address:point <- copy 10/unsafe
-  10:num <- copy 34
-  11:num <- copy 35
+  # skip alloc id
+  11:num <- copy 34
+  12:num <- copy 35
   1:address:point/lookup <- put 1:address:point/lookup, 0:offset, 36
 ]
-+mem: storing 36 in location 10
++mem: storing 36 in location 11
 
 :(after "Update PUT base in Check")
 if (!canonize_type(base)) break;
@@ -241,7 +252,7 @@ def main [
   11:num <- copy 14
   12:num <- copy 15
   13:num <- copy 16
-  1:address:array:num <- copy 10/unsafe
+  1:address:array:num <- copy 9/unsafe/skip-alloc-id
   2:array:num <- copy 1:address:array:num/lookup
 ]
 +mem: storing 3 in location 2
@@ -254,7 +265,7 @@ def main [
   1:address:array:num:3 <- copy 1000/unsafe  # pretend allocation
   1:address:array:num:3/lookup <- create-array
 ]
-+mem: storing 3 in location 1000
++mem: storing 3 in location 1001
 
 :(after "Update CREATE_ARRAY product in Check")
 if (!canonize_type(product)) break;
@@ -267,7 +278,7 @@ def main [
   11:num <- copy 14
   12:num <- copy 15
   13:num <- copy 16
-  1:address:array:num <- copy 10/unsafe
+  1:address:array:num <- copy 9/unsafe/skip-alloc-id
   2:num <- index 1:address:array:num/lookup, 1
 ]
 +mem: storing 15 in location 2
@@ -290,7 +301,7 @@ def main [
   11:num <- copy 14
   12:num <- copy 15
   13:num <- copy 16
-  1:address:array:num <- copy 10/unsafe
+  1:address:array:num <- copy 9/unsafe/skip-alloc-id
   1:address:array:num/lookup <- put-index 1:address:array:num/lookup, 1, 34
 ]
 +mem: storing 34 in location 12
@@ -301,7 +312,7 @@ def main [
   2:num <- copy 14
   3:num <- copy 15
   4:num <- copy 16
-  5:address:num <- copy 10/unsafe
+  5:address:num <- copy 9/unsafe/skip-alloc-id
   10:num <- copy 1
   1:array:num:3 <- put-index 1:array:num:3, 5:address:num/lookup, 34
 ]
@@ -314,7 +325,7 @@ def main [
   11:num <- copy 14
   12:num <- copy 15
   13:num <- copy 16
-  1:address:array:num <- copy 10/unsafe
+  1:address:array:num <- copy 9/unsafe/skip-alloc-id
   1:address:array:num <- put-index 1:address:array:num/lookup, 1, 34
 ]
 +error: main: product of 'put-index' must be first ingredient '1:address:array:num/lookup', but got '1:address:array:num'
@@ -337,7 +348,7 @@ def main [
   *5:address:num <- copy 34
   6:num <- copy *5:address:num
 ]
-+run: creating array of size 4
++run: creating array from 7 locations
 +mem: storing 34 in location 6
 
 :(before "Update PUT_INDEX base in Check")
@@ -358,7 +369,7 @@ def main [
   11:num <- copy 14
   12:num <- copy 15
   13:num <- copy 16
-  1:address:array:num <- copy 10/unsafe
+  1:address:array:num <- copy 9/unsafe/skip-alloc-id
   2:num <- length 1:address:array:num/lookup
 ]
 +mem: storing 3 in location 2
@@ -370,8 +381,8 @@ canonize(array);
 
 :(scenario maybe_convert_indirect)
 def main [
-  10:number-or-point <- merge 0/number, 34
-  1:address:number-or-point <- copy 10/unsafe
+  11:number-or-point <- merge 0/number, 34
+  1:address:number-or-point <- copy 10/unsafe/skip-alloc-id
   2:num, 3:bool <- maybe-convert 1:address:number-or-point/lookup, i:variant
 ]
 +mem: storing 1 in location 3
@@ -379,23 +390,23 @@ def main [
 
 :(scenario maybe_convert_indirect_2)
 def main [
-  10:number-or-point <- merge 0/number, 34
-  1:address:number-or-point <- copy 10/unsafe
-  2:address:num <- copy 20/unsafe
-  2:address:num/lookup, 3:bool <- maybe-convert 1:address:number-or-point/lookup, i:variant
+  11:number-or-point <- merge 0/number, 34
+  1:address:number-or-point <- copy 10/unsafe/skip-alloc-id
+  3:address:num <- copy 20/unsafe
+  3:address:num/lookup, 5:bool <- maybe-convert 1:address:number-or-point/lookup, i:variant
 ]
-+mem: storing 1 in location 3
-+mem: storing 34 in location 20
++mem: storing 1 in location 5
++mem: storing 34 in location 21
 
 :(scenario maybe_convert_indirect_3)
 def main [
-  10:number-or-point <- merge 0/number, 34
-  1:address:number-or-point <- copy 10/unsafe
-  2:address:bool <- copy 20/unsafe
-  3:num, 2:address:bool/lookup <- maybe-convert 1:address:number-or-point/lookup, i:variant
+  11:number-or-point <- merge 0/number, 34
+  1:address:number-or-point <- copy 10/unsafe/skip-alloc-id
+  3:address:bool <- copy 20/unsafe
+  5:num, 3:address:bool/lookup <- maybe-convert 1:address:number-or-point/lookup, i:variant
 ]
-+mem: storing 1 in location 20
-+mem: storing 34 in location 3
++mem: storing 1 in location 21
++mem: storing 34 in location 5
 
 :(before "Update MAYBE_CONVERT base in Check")
 if (!canonize_type(base)) break;
@@ -416,8 +427,9 @@ def main [
   1:address:number-or-point <- copy 10/unsafe
   1:address:number-or-point/lookup <- merge 0/number, 34
 ]
-+mem: storing 0 in location 10
-+mem: storing 34 in location 11
+# skip alloc id
++mem: storing 0 in location 11
++mem: storing 34 in location 12
 
 :(before "Update size_mismatch Check for MERGE(x)
 canonize(x);
@@ -427,7 +439,7 @@ canonize(x);
 :(scenario lookup_abbreviation)
 def main [
   1:address:number <- copy 10/unsafe
-  10:number <- copy 34
+  11:number <- copy 34
   3:number <- copy *1:address:number
 ]
 +parse: ingredient: {1: ("address" "number"), "lookup": ()}