about summary refs log tree commit diff stats
path: root/html/000organization.cc.html
Commit message (Expand)AuthorAgeFilesLines
* 5704Kartik Agaram2019-10-191-71/+73
* 5490Kartik Agaram2019-07-271-2/+2
* 5485 - promote SubX to top-levelKartik Agaram2019-07-271-32/+59
* 4891Kartik Agaram2018-12-301-0/+1
* 4890 - new html renderingsKartik Agaram2018-12-291-14/+9
* 4814Kartik Agaram2018-12-011-10/+13
* 4539Kartik Agaram2018-09-071-4/+4
* 4447Kartik Agaram2018-07-271-7/+6
* 4239Kartik Agaram2018-05-081-4/+4
* 4199Kartik K. Agaram2018-01-251-3/+3
* 4161Kartik K. Agaram2017-12-151-5/+5
* 4061Kartik K. Agaram2017-10-131-4/+4
* 4010Kartik K. Agaram2017-10-041-15/+15
* 3971Kartik K. Agaram2017-08-191-7/+3
* 3764 - better colors for cross-linksKartik K. Agaram2017-03-081-4/+5
* 3716Kartik K. Agaram2016-12-261-0/+2
* 3713 - cross-link calls with definitions in htmlKartik K. Agaram2016-12-261-4/+4
* 3710Kartik K. Agaram2016-12-261-140/+140
* 3709 - line numbers in htmlKartik K. Agaram2016-12-261-142/+166
* 3558Kartik K. Agaram2016-10-221-4/+4
* 3544Kartik K. Agaram2016-10-221-1/+1
* 3543Kartik K. Agaram2016-10-221-1/+1
* 3416Kartik K. Agaram2016-09-251-1/+1
* 3315Kartik K. Agaram2016-09-101-1/+14
* 3102Kartik K. Agaram2016-07-051-1/+1
* 2996Kartik K. Agaram2016-05-211-2/+2
* 2812Kartik K. Agaram2016-03-271-8/+17
* 2744Kartik K. Agaram2016-03-091-4/+4
* 2743Kartik K. Agaram2016-03-091-19/+11
* 2611Kartik K. Agaram2015-11-291-0/+1
* 2062Kartik K. Agaram2015-08-231-5/+4
* 1949Kartik K. Agaram2015-08-061-5/+6
* 1885Kartik K. Agaram2015-07-291-6/+5
* 1853Kartik K. Agaram2015-07-251-5/+6
* 1631 - update html versionsKartik K. Agaram2015-06-231-4/+4
* 1556Kartik K. Agaram2015-06-121-1/+1
* 1549Kartik K. Agaram2015-06-091-2/+2
* 1517Kartik K. Agaram2015-05-301-4/+4
* 1461 - descriptions/table of contents for the layersKartik K. Agaram2015-05-261-1/+1
* 1459Kartik K. Agaram2015-05-251-1/+1
* 1376 - update github docsKartik K. Agaram2015-05-141-10/+15
* 1291Kartik K. Agaram2015-05-061-1/+1
* 1279 - colorized rendering of the source filesKartik K. Agaram2015-05-061-0/+156
>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83







                                                                            

                     
                               

                                                        

                                  

















                                                                      
                     
                  
                                                        
                         
                                                             
                                
                                                                       
                                         

                                                                                                                                                                        
                                      
                                                                                                      







                                                                          
                                                              


                                         



                                                           
                     
             


                                                              
 

                                                         





                                                     



                                                                            
                                                                                       


               
// 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.

:(scenario global_space)
recipe main [
  # pretend arrays; in practice we'll use new
  10:number <- copy 5
  20:number <- copy 5
  # actual start of this recipe
  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 12
+mem: storing 24 in location 22

//: to support it, create another special variable called global space
:(before "End Disqualified Reagents")
if (x.name == "global-space")
  x.initialized = true;
:(before "End is_special_name Cases")
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;
:(before "End routine Constructor")
global_space = 0;
:(after "void write_memory(reagent x, vector<double> data)")
  if (x.name == "global-space") {
    if (!scalar(data)
        || !x.type
        || x.type->value != get(Type_ordinal, "address")
        || !x.type->right
        || x.type->right->value != get(Type_ordinal, "array")
        || !x.type->right->right
        || x.type->right->right->value != get(Type_ordinal, "location")
        || x.type->right->right->right) {
      raise_error << maybe(current_recipe_name()) << "'global-space' should be of type address: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();
    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();
    return Current_routine->global_space;
  }

//: for now let's not bother giving global variables names.
//: don't want to make them too comfortable to use.

:(scenario global_space_with_names)
% Hide_errors = true;
recipe main [
  global-space:address:array:location <- new location:type, 10
  x:number <- copy 23
  1:number/space:global <- copy 24
]
# don't complain about mixing numeric addresses and names
$error: 0

:(after "bool is_numeric_location(const reagent& x)")
  if (is_global(x)) return false;

//: helpers

:(code)
bool is_global(const reagent& x) {
  for (long long int i = /*skip name:type*/1; 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;
}