1
2
3
4
5
6
7
8
9
10
11
12 :(scenario global_space)
13 def main [
14
15 10:num <- copy 0
16 11:num <- copy 5
17
18 20:num <- copy 0
19 21:num <- copy 5
20
21 global-space:space <- copy 20/unsafe
22 default-space:space <- copy 10/unsafe
23 1:num <- copy 23
24 1:num/space:global <- copy 24
25 ]
26
27 +mem: storing 23 in location 13
28
29 +mem: storing 24 in location 23
30
31
32 :(before "End is_disqualified Special-cases")
33 if (x.name == "global-space")
34 x.initialized = true;
35 :(before "End is_special_name Special-cases")
36 if (s == "global-space") return true;
37
38
39 :(before "End routine Fields")
40 int global_space;
41 :(before "End routine Constructor")
42 global_space = 0;
43 :(after "Begin Preprocess write_memory(x, data)")
44 if (x.name == "global-space") {
45 if (!scalar(data) || !is_space(x))
46 raise << maybe(current_recipe_name()) << "'global-space' should be of type address:array:location, but tried to write '" << to_string(x.type) << "'\n" << end();
47 if (Current_routine->global_space)
48 raise << "routine already has a global-space; you can't over-write your globals" << end();
49 Current_routine->global_space = data.at(0);
50 return;
51 }
52
53
54 :(after "int space_base(const reagent& x)")
55 if (is_global(x)) {
56 if (!Current_routine->global_space)
57 raise << "routine has no global space\n" << end();
58 return Current_routine->global_space + 1;
59 }
60
61
62
63
64 :(scenario global_space_with_names)
65 def main [
66 global-space:space <- new location:type, 10
67 x:num <- copy 23
68 1:num/space:global <- copy 24
69 ]
70
71 $error: 0
72
73 :(after "bool is_numeric_location(const reagent& x)")
74 if (is_global(x)) return false;
75
76
77
78 :(code)
79 bool is_global(const reagent& x) {
80 string_tree* s = property(x, "space");
81 return s && s->atom && s->value == "global";
82 }