https://github.com/akkartik/mu/blob/master/044space_surround.cc
1
2
3
4
5
6
7 :(scenario surrounding_space)
8
9
10 def main [
11
12 10:num/alloc-id, 11:num <- copy 0, 1000
13
14 1000:num <- copy 0
15 1001:num <- copy 5
16
17 20:num/alloc-id, 21:num <- copy 0, 2000
18
19 2000:num <- copy 0
20 2001:num <- copy 5
21
22 default-space:space <- copy 10:space
23
24 0:space/names:dummy <- copy 20:space/raw
25 2:num <- copy 94
26 2:num/space:1 <- copy 95
27 ]
28 def dummy [
29 ]
30
31 +mem: storing 0 in location 1002
32 +mem: storing 2000 in location 1003
33
34 +mem: storing 94 in location 1004
35
36 +mem: storing 95 in location 2004
37
38
39
40
41
42 :(replace{} "int space_base(const reagent& x)")
43 int space_base(const reagent& x) {
44 int base = current_call().default_space ? (current_call().default_space+1) : 0;
45 return space_base(x, space_index(x), base);
46 }
47
48 int space_base(const reagent& x, int space_index, int base) {
49 if (space_index == 0)
50 return base;
51 double chained_space_address = base+1+1;
52 double chained_space_base = get_or_insert(Memory, chained_space_address) + 1;
53 return space_base(x, space_index-1, chained_space_base);
54 }
55
56 int space_index(const reagent& x) {
57 for (int i = 0; i < SIZE(x.properties); ++i) {
58 if (x.properties.at(i).first == "space") {
59 if (!x.properties.at(i).second || x.properties.at(i).second->right)
60 raise << maybe(current_recipe_name()) << "/space metadata should take exactly one value in '" << x.original_string << "'\n" << end();
61 return to_integer(x.properties.at(i).second->value);
62 }
63 }
64 return 0;
65 }
66
67 :(scenario permit_space_as_variable_name)
68 def main [
69 space:num <- copy 0
70 ]