about summary refs log tree commit diff stats
path: root/archive
Commit message (Expand)AuthorAgeFilesLines
* 6206Kartik Agaram2020-04-176-115/+66
* 6155Kartik Agaram2020-03-201-1/+3
* 6066 - Vim syntax highlighting for Mu filesKartik Agaram2020-02-281-1/+1
* 5960Kartik Agaram2020-01-301-0/+1
* 5959Kartik Agaram2020-01-301-1/+1
* 5853Kartik Agaram2020-01-013-135/+0
* 5852Kartik Agaram2020-01-01232-3/+3
* 5787Kartik Agaram2019-12-026-18/+262
* 5494Kartik Agaram2019-07-271-0/+11
* 5485 - promote SubX to top-levelKartik Agaram2019-07-27229-0/+80488
986eebff ^
fca0ebbe ^
5b567348 ^
986eebff ^
3c435756 ^

88be3dbc ^
d672cdfc ^



6f5d7864 ^
d672cdfc ^
57699011 ^
d672cdfc ^
fca0ebbe ^
5b567348 ^
986eebff ^


b38e5819 ^
b9011f34 ^
986eebff ^
7da71d03 ^
986eebff ^




986eebff ^
a2be26c8 ^
c84640b1 ^
3076bab4 ^
05d17773 ^
986eebff ^
3ba63579 ^
827898fc ^
3ba63579 ^
986eebff ^




6673e1fc ^

b9011f34 ^
05d17773 ^

986eebff ^

b9011f34 ^
05d17773 ^
986eebff ^


5e938dc1 ^
7284d503 ^
88be3dbc ^
5e938dc1 ^





6f5d7864 ^
5e938dc1 ^
0487a30e ^
57699011 ^
5e938dc1 ^
88be3dbc ^
b9011f34 ^







0487a30e ^
57699011 ^
b9011f34 ^
f1a3be1c ^

5e938dc1 ^
88be3dbc ^
db5c9550 ^
5e938dc1 ^





6f5d7864 ^
5e938dc1 ^
0487a30e ^
5e938dc1 ^
f1a3be1c ^

c51043ab ^




a66c9ae6 ^
05d17773 ^
c51043ab ^




a66c9ae6 ^
05d17773 ^

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

                                                                              
 
                         





                                                                     
                        

                      
                              
 
                                                                                    
                
 

                                                                       
                          



                                            
                        
                     
                              
 
                                                                                                
                


                             
                               
                                 
                
                                                                     




                                  
                          
                                                       
                                                            
                 
                                   
 
                  
                                    
                                                                   




                                                                                       

                                   
                             

                                                    

                           
                        
                                                    


                
 
                                          
                        





                                                  
                        
                          
                    
                              
 
                                       







                                                      
                    
                              
 

                                                
 
                                
                                       





                                                          
                        
                          
                    
 

                                                        




                                           
                                                     
                                                      




                                                               
                                                      

                                         


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

:(scenario copy_indirect)
recipe main [
  1:address:integer <- copy 2:literal
  2:integer <- copy 34:literal
  # This loads location 1 as an address and looks up *that* location.
  3:integer <- copy 1:address:integer/deref
]
+run: instruction main/2
+mem: location 1 is 2
+mem: location 2 is 34
+mem: storing 34 in location 3

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

//: similarly, write to addresses pointing at other locations using the
//: 'deref' property
:(scenario store_indirect)
recipe main [
  1:address:integer <- copy 2:literal
  1:address:integer/deref <- copy 34:literal
]
+run: instruction main/1
+mem: location 1 is 2
+mem: storing 34 in location 2

:(before "index_t base = x.value" following "void write_memory(reagent x, vector<double> data)")
x = canonize(x);

:(code)
reagent canonize(reagent x) {
  if (isa_literal(x)) return x;
//?   cout << "canonize\n"; //? 1
  reagent r = x;
//?   cout << x.to_string() << " => " << r.to_string() << '\n'; //? 1
  while (has_property(r, "deref"))
    r = deref(r);
  return r;
}

reagent deref(reagent x) {
//?   cout << "deref: " << x.to_string() << "\n"; //? 2
  static const type_number ADDRESS = Type_number["address"];
  reagent result;
  assert(x.types.at(0) == ADDRESS);

  // compute value
  result.set_value(Memory[x.value]);
  trace("mem") << "location " << x.value << " is " << result.value;

  // populate types
  copy(++x.types.begin(), x.types.end(), inserter(result.types, result.types.begin()));

  // drop-one 'deref'
  index_t i = 0;
  size_t len = x.properties.size();
  for (i = 0; i < len; ++i) {
    if (x.properties.at(i).first == "deref") break;
    result.properties.push_back(x.properties.at(i));
  }
  ++i;  // skip first deref
  for (; i < len; ++i) {
    result.properties.push_back(x.properties.at(i));
  }
  return result;
}

//:: 'get' can read from container address
:(scenario get_indirect)
recipe main [
  1:integer <- copy 2:literal
  2:integer <- copy 34:literal
  3:integer <- copy 35:literal
  4:integer <- get 1:address:point/deref, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4
+mem: storing 34 in location 4

:(scenario include_nonderef_properties)
recipe main [
  1:integer <- copy 2:literal
  2:integer <- copy 34:literal
  3:integer <- copy 35:literal
  4:integer <- get 1:address:point/deref/foo, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4
+mem: storing 34 in location 4

:(after "reagent base = " following "case GET:")
base = canonize(base);

:(scenario get_address_indirect)
# 'get' can read from container address
recipe main [
  1:integer <- copy 2:literal
  2:integer <- copy 34:literal
  3:integer <- copy 35:literal
  4:integer <- get-address 1:address:point/deref, 0:offset
]
+run: instruction main/3
+run: address to copy is 2
+run: product 0 is 4

:(after "reagent base = " following "case GET_ADDRESS:")
base = canonize(base);

//:: helpers

:(code)
bool has_property(reagent x, string name) {
  for (index_t i = 0; i < x.properties.size(); ++i) {
    if (x.properties.at(i).first == name) return true;
  }
  return false;
}

vector<string> property(const reagent& r, const string& name) {
  for (index_t p = 0; p != r.properties.size(); ++p) {
    if (r.properties.at(p).first == name)
      return r.properties.at(p).second;
  }
  return vector<string>();
}