https://github.com/akkartik/mu/blob/master/035lookup.cc
1
2
3
4
5
6 :(scenario copy_indirect)
7 def main [
8
9 11:num <- copy 20
10
11 21:num <- copy 94
12
13
14 30:num <- copy 10:&:num/lookup
15 ]
16 +mem: storing 94 in location 30
17
18 :(before "End Preprocess read_memory(x)")
19 canonize(x);
20
21
22
23 :(scenario store_indirect)
24 def main [
25
26 11:num <- copy 10
27 10:&:num/lookup <- copy 94
28 ]
29 +mem: storing 94 in location 11
30
31 :(before "End Preprocess write_memory(x, data)")
32 canonize(x);
33
34
35 :(scenario store_to_0_fails)
36 % Hide_errors = true;
37 def main [
38 10:&:num <- copy null
39 10:&:num/lookup <- copy 94
40 ]
41 -mem: storing 94 in location 0
42 +error: main: tried to lookup 0 in '10:&:num/lookup <- copy 94'
43
44
45 :(scenario lookup_0_fails)
46 % Hide_errors = true;
47 def main [
48 10:&:num <- copy null
49 20:num <- copy 10:&:num/lookup
50 ]
51 +error: main: tried to lookup 0 in '20:num <- copy 10:&:num/lookup'
52
53 :(scenario lookup_0_dumps_callstack)
54 % Hide_errors = true;
55 def main [
56 foo null
57 ]
58 def foo [
59 10:&:num <- next-input
60 20:num <- copy 10:&:num/lookup
61 ]
62 +error: foo: tried to lookup 0 in '20:num <- copy 10:&:num/lookup'
63 +error: called from main: foo null
64
65 :(code)
66 void canonize(reagent& x) {
67 if (is_literal(x)) return;
68
69 while (has_property(x, "lookup"))
70 lookup_memory(x);
71 }
72
73 void lookup_memory(reagent& x) {
74 if (!x.type || x.type->atom || x.type->left->value != Address_type_ordinal) {
75 raise << maybe(current_recipe_name()) << "tried to lookup '" << x.original_string << "' but it isn't an address\n" << end();
76 dump_callstack();
77 return;
78 }
79
80 if (x.value == 0) {
81 raise << maybe(current_recipe_name()) << "tried to lookup 0\n" << end();
82 dump_callstack();
83 return;
84 }
85 lookup_memory_core(x, true);
86 }
87
88 void lookup_memory_core(reagent& x, bool check_for_null) {
89 double generated by cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2024-12-03 20:06:06 +0000