:(scenario global_space)
recipe main [
10:number <- copy 5:literal
20:number <- copy 5:literal
global-space:address:array:location <- copy 20:literal
default-space:address:array:location <- copy 10:literal
1:number <- copy 23:literal
1:number/space:global <- copy 24:literal
]
+mem: storing 23 in location 12
+mem: storing 24 in location 22
:(before "End Disqualified Reagents")
if (x.name == "global-space")
x.initialized = true;
:(before "End is_special_name Cases")
if (s == "global-space") return true;
:(before "End routine Fields")
long long int global_space;
:(before "End routine Constructor")
global_space = 0;
:(after "void write_memory(reagent x, vector<double> data)")
if (x.name == "global-space") {
assert(scalar(data));
if (Current_routine->global_space)
raise << "routine already has a global-space; you can't over-write your globals";
Current_routine->global_space = data.at(0);
return;
}
:(after "long long int space_base(const reagent& x)")
if (is_global(x)) {
if (!Current_routine->global_space)
raise << "routine has no global space\n" << die();
return Current_routine->global_space;
}
:(scenario global_space_with_names)
% Hide_warnings = true;
recipe main [
global-space:address:array:location <- new location:type, 10:literal
x:number <- copy 23:literal
1:number/space:global <- copy 24:literal
]
$warn: 0
:(after "bool is_numeric_location(const reagent& x)")
if (is_global(x)) return false;
:(code)
bool is_global(const reagent& x) {
for (long long int i = 1; i < SIZE(x.properties); ++i) {
if (x.properties.at(i).first == "space")
return !x.properties.at(i).second.empty() && x.properties.at(i).second.at(0) == "global";
}
return false;
}