about summary refs log tree commit diff stats
path: root/profrc.example
Commit message (Expand)AuthorAgeFilesLines
* Added example profrc configJames Booth2014-06-291-0/+58
7'>^
286ca5a4 ^
2199940a ^
88be3dbc ^
986eebff ^
a0fc38c9 ^
bc643692 ^
986eebff ^
286ca5a4 ^
986eebff ^
57699011 ^
986eebff ^
ac0e9db5 ^
c6034af3 ^
986eebff ^
3c435756 ^
286ca5a4 ^
88be3dbc ^
d672cdfc ^
a0fc38c9 ^
286ca5a4 ^
d672cdfc ^
57699011 ^
d672cdfc ^
ac0e9db5 ^
c6034af3 ^
1fbebe73 ^
5f98a10c ^
1fbebe73 ^



5f98a10c ^

1fbebe73 ^




5f98a10c ^
986eebff ^

c6034af3 ^




986eebff ^

c6034af3 ^

5f98a10c ^
e4630643 ^
3ba63579 ^
e4630643 ^
5f98a10c ^
e4630643 ^
cdd6fd09 ^
c6034af3 ^


986eebff ^
5e938dc1 ^
a0fc38c9 ^
4f333377 ^

a0fc38c9 ^
4f333377 ^
a0fc38c9 ^
a0fc38c9 ^
4f333377 ^
a0fc38c9 ^
a0fc38c9 ^
a0d7a155 ^


a0fc38c9 ^


c6034af3 ^
5f98a10c ^
a0fc38c9 ^

c6034af3 ^
a0fc38c9 ^




c6034af3 ^






a0fc38c9 ^
ae256ea1 ^
a0fc38c9 ^







7284d503 ^
88be3dbc ^
5e938dc1 ^
bc643692 ^


286ca5a4 ^
5e938dc1 ^
57699011 ^
5e938dc1 ^
286ca5a4 ^
b9011f34 ^
bc643692 ^


286ca5a4 ^
b9011f34 ^
57699011 ^
b9011f34 ^
900e6a0e ^

af7a5722 ^

900e6a0e ^
c6034af3 ^
5e938dc1 ^
88be3dbc ^
db5c9550 ^
5e938dc1 ^
bc643692 ^


fb5470bc ^
5e938dc1 ^
d7494165 ^
5e938dc1 ^
900e6a0e ^

29057ed9 ^

900e6a0e ^
c6034af3 ^
c51043ab ^
7002b921 ^



a0fc38c9 ^
7002b921 ^








ae256ea1 ^
7002b921 ^

5f98a10c ^
7002b921 ^

d619db37 ^







c6034af3 ^

b1cf3bc9 ^
d619db37 ^

1fad5eef ^

d619db37 ^
1fad5eef ^








4082acd2 ^
1fad5eef ^


c6034af3 ^


c51043ab ^
1fad5eef ^
c51043ab ^
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
                                                                              
                      
 
                         
             
                                
                     
                                                                     
                                          
 
                              
 
                                                                                          
            
 
                                                                       
                     
                          
             
                                
                                    
 
                              
 
                                                                                                      
            
                   
                                                                                                         



                                          

                            




                                    
                                                                         

       




                                   

 

                                                            
                                                                                                                                     
   
                  
                     
                                                                                   
   
                                                                                                    


                               
 
 
                                                     

                                        
 
                                      
                                      
 
                                        
                                      
 


                                       


                                     
                                                              
                                                                                        

                   
                              




                       






                                         
                                  
                                                                                                              







                               
                                          
                        
             


                     
                                                  
 
                              
 
                                        
             


                     
                                                      
 
                              
 

                                   

                                      
                                 
               
 
                                
                                       
             


                     
                                                                  
 
                             
 

                                           

                                              
                                         
               
 



                                             
                                








                                              
                                                                     

                   
                                                                       

 







                                                

                                                                   
                                                                                                                                                                                                                                                                                

        

                                                         
                                                                                    








                                                  
                                                                             


                      


                                                          
   
        
 
//: Instructions can read from addresses pointing at other locations using the
//: 'lookup' property.

:(scenario copy_indirect)
recipe main [
  1:address:number <- copy 2/raw
  2:number <- copy 34
  # This loads location 1 as an address and looks up *that* location.
  3:number <- copy 1:address:number/lookup
]
+mem: storing 34 in location 3

:(before "long long int base = x.value" following "vector<double> read_memory(reagent x)")
canonize(x);

//: similarly, write to addresses pointing at other locations using the
//: 'lookup' property
:(scenario store_indirect)
recipe main [
  1:address:number <- copy 2/raw
  1:address:number/lookup <- copy 34
]
+mem: storing 34 in location 2

:(before "long long int base = x.value" following "void write_memory(reagent x, vector<double> data)")
canonize(x);
if (x.value == 0) {
  raise_error << "can't write to location 0 in '" << current_instruction().to_string() << "'\n" << end();
  return;
}

//: writes to address 0 always loudly fail
:(scenario store_to_0_fails)
% Hide_errors = true;
recipe main [
  1:address:number <- copy 0
  1:address:number/lookup <- copy 34
]
-mem: storing 34 in location 0
+error: can't write to location 0 in '1:address:number/lookup <- copy 34'

:(code)
void canonize(reagent& x) {
  if (is_literal(x)) return;
  // End canonize(x) Special-cases
  while (has_property(x, "lookup"))
    lookup_memory(x);
}

void lookup_memory(reagent& x) {
  if (!x.type || x.type->value != Type_ordinal["address"]) {
    raise_error << maybe(current_recipe_name()) << "tried to /lookup " << x.original_string << " but it isn't an address\n" << end();
  }
  // compute value
  if (x.value == 0) {
    raise_error << maybe(current_recipe_name()) << "tried to /lookup 0\n" << end();
  }
  trace(9999, "mem") << "location " << x.value << " is " << no_scientific(Memory[x.value]) << end();
  x.set_value(Memory[x.value]);
  drop_address_from_type(x);
  drop_one_lookup(x);
}

:(after "bool types_match(reagent lhs, reagent rhs)")
  if (!canonize_type(lhs)) return false;
  if (!canonize_type(rhs)) return false;

:(after "bool is_mu_array(reagent r)")
  if (!canonize_type(r)) return false;

:(after "bool is_mu_address(reagent r)")
  if (!canonize_type(r)) return false;

:(after "bool is_mu_number(reagent r)")
  if (!canonize_type(r)) return false;

:(code)
bool canonize_type(reagent& r) {
  while (has_property(r, "lookup")) {
    if (!r.type || r.type->value != Type_ordinal["address"]) {
      raise_error << "can't lookup non-address: " << r.original_string << '\n' << end();
      return false;
    }
    drop_address_from_type(r);
    drop_one_lookup(r);
  }
  return true;
}

void drop_address_from_type(reagent& r) {
  type_tree* tmp = r.type;
  r.type = tmp->right;
  tmp->right = NULL;
  delete tmp;
}

void drop_one_lookup(reagent& r) {
  for (vector<pair<string, string_tree*> >::iterator p = r.properties.begin(); p != r.properties.end(); ++p) {
    if (p->first == "lookup") {
      r.properties.erase(p);
      return;
    }
  }
  assert(false);
}

//:: 'get' can read from container address
:(scenario get_indirect)
recipe main [
  1:number <- copy 2
  2:number <- copy 34
  3:number <- copy 35
  4:number <- get 1:address:point/lookup, 0:offset
]
+mem: storing 34 in location 4

:(scenario include_nonlookup_properties)
recipe main [
  1:number <- copy 2
  2:number <- copy 34
  3:number <- copy 35
  4:number <- get 1:address:point/lookup/foo, 0:offset
]
+mem: storing 34 in location 4

:(after "Update GET base in Check")
if (!canonize_type(base)) break;
:(after "Update GET product in Check")
if (!canonize_type(product)) break;
:(after "Update GET base in Run")
canonize(base);

:(scenario get_address_indirect)
# 'get' can read from container address
recipe main [
  1:number <- copy 2
  2:number <- copy 34
  3:number <- copy 35
  4:address:number <- get-address 1:address:point/lookup, 0:offset
]
+mem: storing 2 in location 4

:(after "Update GET_ADDRESS base in Check")
if (!canonize_type(base)) break;
:(after "Update GET_ADDRESS product in Check")
if (!canonize_type(base)) break;
:(after "Update GET_ADDRESS base in Run")
canonize(base);

//:: abbreviation for '/lookup': a prefix '*'

:(scenario lookup_abbreviation)
recipe main [
  1:address:number <- copy 2/raw
  2:number <- copy 34
  3:number <- copy *1:address:number
]
+mem: storing 34 in location 3

:(before "End Parsing reagent")
{
  while (!name.empty() && name.at(0) == '*') {
    name.erase(0, 1);
    properties.push_back(pair<string, string_tree*>("lookup", NULL));
  }
  if (name.empty())
    raise_error << "illegal name " << original_string << '\n' << end();
}

//:: helpers for debugging

:(before "End Primitive Recipe Declarations")
_DUMP,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["$dump"] = _DUMP;
:(before "End Primitive Recipe Implementations")
case _DUMP: {
  reagent after_canonize = current_instruction().ingredients.at(0);
  canonize(after_canonize);
  cerr << maybe(current_recipe_name()) << current_instruction().ingredients.at(0).name << ' ' << no_scientific(current_instruction().ingredients.at(0).value) << " => " << no_scientific(after_canonize.value) << " => " << no_scientific(Memory[after_canonize.value]) << '\n';
  break;
}

//: grab an address, and then dump its value at intervals
//: useful for tracking down memory corruption (writing to an out-of-bounds address)
:(before "End Globals")
long long int foo = -1;
:(before "End Primitive Recipe Declarations")
_FOO,
:(before "End Primitive Recipe Numbers")
Recipe_ordinal["$foo"] = _FOO;
:(before "End Primitive Recipe Implementations")
case _FOO: {
  if (current_instruction().ingredients.empty()) {
    if (foo != -1) cerr << foo << ": " << no_scientific(Memory[foo]) << '\n';
    else cerr << '\n';
  }
  else {
    reagent tmp = current_instruction().ingredients.at(0);
    canonize(tmp);
    foo = tmp.value;
  }
  break;
}