about summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
authorarg@mig29 <unknown>2006-11-27 17:30:06 +0100
committerarg@mig29 <unknown>2006-11-27 17:30:06 +0100
commit0c97b21b6120137858f390f061d17f065b41d26e (patch)
tree9a30eeb0ce27ba02738b135c8ad220e5862c9d10 /main.c
parent19390b1a91da680a502ce5acebd086cfbe32627c (diff)
downloaddwm-0c97b21b6120137858f390f061d17f065b41d26e.tar.gz
applied patch by Jukka
Diffstat (limited to 'main.c')
0 files changed, 0 insertions, 0 deletions
:15:45 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-10-06 22:15:45 -0700 2258 - separate warnings from errors' href='/akkartik/mu/commit/047global.cc?h=main&id=5f98a10cc78829a03c9fa5a137392e7d5e9030ac'>5f98a10c ^
c6034af3 ^






5f98a10c ^

dfc6e268 ^
5f98a10c ^
385d3080 ^







5f98a10c ^
385d3080 ^


dfc6e268 ^



5f98a10c ^
dfc6e268 ^
bc643692 ^


dfc6e268 ^
5f98a10c ^

dfc6e268 ^





385d3080 ^



ae256ea1 ^
385d3080 ^


1
2
3
4
5
6
7
8
9
10
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/raw
  default-space:address:array:location <- copy 10/raw
  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 != Type_ordinal["address"]
        || !x.type->right
        || x.type->right->value != Type_ordinal["array"]
        || !x.type->right->right
        || x.type->right->right->value != 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;
}