:(scenario global_space)
def main [
10:number <- copy 0
11:number <- copy 5
20:number <- copy 0
21:number <- copy 5
global-space:address:array:location <- copy 20/unsafe
default-space:address:array:location <- copy 10/unsafe
1:number <- copy 23
1:number/space:global <- copy 24
]
+mem: storing 23 in location 13
+mem: storing 24 in location 23
:(before "End is_disqualified Cases")
if (x.name == "global-space")
x.initialized = true;
:(before "End is_special_name Cases")
if (s == "global-space") return true;
:(before "End routine Fields")
int global_space;
:(before "End routine Constructor")
global_space = 0;
:(after "Begin Preprocess write_memory(x, data)")
if (x.name == "global-space") {
if (!scalar(data) || !is_space(x))
raise << maybe(current_recipe_name()) << "'global-space' should be of type address:array:location, but tried to write '" << to_string(x.type) << "'\n" << end();
if (Current_routine->global_space)
raise << "routine already has a global-space; you can't over-write your globals" << end();
Current_routine->global_space = data.at(0);
return;
}
:(after "int space_base(const reagent& x)")
if (is_global(x)) {
if (!Current_routine->global_space)
raise << "routine has no global space\n" << end();
return Current_routine->global_space + 1;
}
:(scenario global_space_with_names)
def main [
global-space:address:array:location <- new location:type, 10
x:number <- copy 23
1:number/space:global <- copy 24
]
$error: 0
:(after "bool is_numeric_location(const reagent& x)")
if (is_global(x)) return false;
:(code)
bool is_global(const reagent& x) {
string_tree* s = property(x, "space");
return s && s->atom && s->value == "global";
}