From 4690ce81e079fc58cae8d6d583e5e3eb3ed81a83 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 9 Mar 2016 02:56:27 -0800 Subject: 2743 Looks like "TOhtml | " doesn't work on Mac OS X for some reason.. --- html/046global.cc.html | 80 ++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 41 deletions(-) (limited to 'html/046global.cc.html') diff --git a/html/046global.cc.html b/html/046global.cc.html index 75d02253..152b0d97 100644 --- a/html/046global.cc.html +++ b/html/046global.cc.html @@ -3,41 +3,40 @@ Mu - 046global.cc - - + + - - + - - -
-// So far we have local variables, and we can nest local variables of short
-// lifetimes inside longer ones. Now let's support 'global' variables that
-// last for the life of a routine. If we create multiple routines they won't
-// have access to each other's globals.
+
+//: So far we have local variables, and we can nest local variables of short
+//: lifetimes inside longer ones. Now let's support 'global' variables that
+//: last for the life of a routine. If we create multiple routines they won't
+//: have access to each other's globals.
+//:
+//: This feature is still experimental and half-baked. You can't name global
+//: variables, and so like in most tests they don't get checked for types (the
+//: only known hole in the type system, can cause memory corruption). We might
+//: fix these issues if we ever use globals. Or we might just drop the feature
+//: entirely.
 
 :(scenario global_space)
-recipe main [
+def main [
   # pretend shared:array:location; in practice we'll use new
   10:number <- copy 0  # refcount
   11:number <- copy 5  # length
@@ -46,7 +45,7 @@ recipe main [
   21:number <- copy 5  # length
   # actual start of this recipe
   global-space:address:shared:array:location <- copy 20/unsafe
-  default-space:address:shared:array:location <- copy 10/unsafe
+  default-space:address:shared:array:location <- copy 10/unsafe
   1:number <- copy 23
   1:number/space:global <- copy 24
 ]
@@ -57,19 +56,19 @@ recipe main [
 
 //: to support it, create another special variable called global space
 :(before "End is_disqualified Cases")
-if (x.name == "global-space")
+if (x.name == "global-space")
   x.initialized = true;
 :(before "End is_special_name Cases")
-if (s == "global-space") return true;
+if (s == "global-space") return true;
 
 //: writes to this variable go to a field in the current routine
 :(before "End routine Fields")
-long long int global_space;
+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") {
-    if (!scalar(data)
+  if (x.name == "global-space") {
+    if (!scalar(data)
         || !x.type
         || x.type->value != get(Type_ordinal, "address")
         || !x.type->right
@@ -79,19 +78,19 @@ global_space = 0;
         || !x.type->right->right->right
         || x.type->right->right->right->value != get(Type_ordinal, "location")
         || x.type->right->right->right->right) {
-      raise_error << maybe(current_recipe_name()) << "'global-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end();
+      raise << maybe(current_recipe_name()) << "'global-space' should be of type address:shared:array:location, but tried to write " << to_string(data) << '\n' << end();
     }
-    if (Current_routine->global_space)
-      raise_error << "routine already has a global-space; you can't over-write your globals" << 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;
   }
 
 //: now marking variables as /space:global looks them up inside this field
 :(after "long long int space_base(const reagent& x)")
-  if (is_global(x)) {
-    if (!Current_routine->global_space)
-      raise_error << "routine has no global space\n" << end();
+  if (is_global(x)) {
+    if (!Current_routine->global_space)
+      raise << "routine has no global space\n" << end();
     return Current_routine->global_space + /*skip refcount*/1;
   }
 
@@ -99,8 +98,8 @@ global_space = 0;
 //: don't want to make them too comfortable to use.
 
 :(scenario global_space_with_names)
-recipe main [
-  global-space:address:shared:array:location <- new location:type, 10
+def main [
+  global-space:address:shared:array:location <- new location:type, 10
   x:number <- copy 23
   1:number/space:global <- copy 24
 ]
@@ -108,14 +107,14 @@ recipe main [
 $error: 0
 
 :(after "bool is_numeric_location(const reagent& x)")
-  if (is_global(x)) return false;
+  if (is_global(x)) return false;
 
 //: helpers
 
 :(code)
-bool is_global(const reagent& x) {
-  for (long long int i = 0; i < SIZE(x.properties); ++i) {
-    if (x.properties.at(i).first == "space")
+bool is_global(const reagent& x) {
+  for (long long int i = 0; i < SIZE(x.properties); ++i) {
+    if (x.properties.at(i).first == "space")
       return x.properties.at(i).second && x.properties.at(i).second->value == "global";
   }
   return false;
@@ -123,4 +122,3 @@ bool is_global(const reagent& x