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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - 031address.cc</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="cpp">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #d0d0d0; background-color: #000000; }
body { font-family: monospace; color: #d0d0d0; background-color: #000000; }
* { font-size: 1em; }
.CommentedCode { color: #6c6c6c; }
.SalientComment { color: #00ffff; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.Identifier { color: #008080; }
.traceContains { color: #008000; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Instructions can read from addresses pointing at other locations using the</span>
<span class="Comment">//: 'deref' property.</span>
<span class="Delimiter">:(scenario copy_indirect)</span>
recipe main [
<span class="Constant">1</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal
<span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal
<span class="Comment"># This loads location 1 as an address and looks up *that* location.</span>
<span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">1</span>:address:integer/deref
]
<span class="traceContains">+run: instruction main/2</span>
<span class="traceContains">+mem: location 1 is 2</span>
<span class="traceContains">+mem: location 2 is 34</span>
<span class="traceContains">+mem: storing 34 in location 3</span>
<span class="Delimiter">:(before "index_t base = x.value" following "vector<long long int> read_memory(reagent x)")</span>
x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Comment">//: similarly, write to addresses pointing at other locations using the</span>
<span class="Comment">//: 'deref' property</span>
<span class="Delimiter">:(scenario store_indirect)</span>
recipe main [
<span class="Constant">1</span>:address:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal
<span class="Constant">1</span>:address:integer/deref<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal
]
<span class="traceContains">+run: instruction main/1</span>
<span class="traceContains">+mem: location 1 is 2</span>
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="Delimiter">:(before "index_t base = x.value" following "void write_memory(reagent x, vector<long long int> data)")</span>
x = canonize<span class="Delimiter">(</span>x<span class="Delimiter">);</span>
<span class="Delimiter">:(code)</span>
reagent canonize<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>isa_literal<span class="Delimiter">(</span>x<span class="Delimiter">))</span> <span class="Identifier">return</span> x<span class="Delimiter">;</span>
<span class="CommentedCode">//? cout << "canonize\n"; //? 1</span>
reagent r = x<span class="Delimiter">;</span>
<span class="CommentedCode">//? cout << x.to_string() << " => " << r.to_string() << '\n'; //? 1</span>
while <span class="Delimiter">(</span>has_property<span class="Delimiter">(</span>r<span class="Delimiter">,</span> <span class="Constant">"deref"</span><span class="Delimiter">))</span>
r = deref<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
<span class="Identifier">return</span> r<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
reagent deref<span class="Delimiter">(</span>reagent x<span class="Delimiter">)</span> <span class="Delimiter">{</span>
<span class="CommentedCode">//? cout << "deref: " << x.to_string() << "\n"; //? 2</span>
static const type_number ADDRESS = Type_number[<span class="Constant">"address"</span>]<span class="Delimiter">;</span>
reagent result<span class="Delimiter">;</span>
assert<span class="Delimiter">(</span>x<span class="Delimiter">.</span>types[<span class="Constant">0</span>] == ADDRESS<span class="Delimiter">);</span>
<span class="Comment">// compute value</span>
result<span class="Delimiter">.</span>set_value<span class="Delimiter">(</span>Memory[x<span class="Delimiter">.</span>value]<span class="Delimiter">);</span>
trace<span class="Delimiter">(</span><span class="Constant">"mem"</span><span class="Delimiter">)</span> << <span class="Constant">"location "</span> << x<span class="Delimiter">.</span>value << <span class="Constant">" is "</span> << result<span class="Delimiter">.</span>value<span class="Delimiter">;</span>
<span class="Comment">// populate types</span>
copy<span class="Delimiter">(</span>++x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> x<span class="Delimiter">.</span>types<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> inserter<span class="Delimiter">(</span>result<span class="Delimiter">.</span>types<span class="Delimiter">,</span> result<span class="Delimiter">.</span>types<span class="Delimiter">.</span>begin<span class="Delimiter">()));</span>
<span class="Comment">// drop-one 'deref'</span>
index_t i = <span class="Constant">0</span><span class="Delimiter">;</span>
size_t len = x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span>
for <span class="Delimiter">(</span>i = <span class="Constant">0</span><span class="Delimiter">;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>first == <span class="Constant">"deref"</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span>
result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
++i<span class="Delimiter">;</span> <span class="Comment">// skip first deref</span>
for <span class="Delimiter">(;</span> i < len<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
result<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">);</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> result<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="SalientComment">//:: 'get' can read from container address</span>
<span class="Delimiter">:(scenario get_indirect)</span>
recipe main [
<span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal
<span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal
<span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal
<span class="Constant">4</span>:integer<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+run: instruction main/3</span>
<span class="traceContains">+run: address to copy is 2</span>
<span class="traceContains">+run: product 0 is 34</span>
<span class="traceContains">+mem: storing 34 in location 4</span>
<span class="Delimiter">:(scenario include_nonderef_properties)</span>
recipe main [
<span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal
<span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal
<span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal
<span class="Constant">4</span>:integer<span class="Special"> <- </span>get <span class="Constant">1</span>:address:point/deref/foo<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+run: instruction main/3</span>
<span class="traceContains">+run: address to copy is 2</span>
<span class="traceContains">+run: product 0 is 34</span>
<span class="traceContains">+mem: storing 34 in location 4</span>
<span class="Delimiter">:(after "reagent base = " following "case GET:")</span>
base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="Delimiter">:(scenario get_address_indirect)</span>
<span class="Comment"># 'get' can read from container address</span>
recipe main [
<span class="Constant">1</span>:integer<span class="Special"> <- </span>copy <span class="Constant">2</span>:literal
<span class="Constant">2</span>:integer<span class="Special"> <- </span>copy <span class="Constant">34</span>:literal
<span class="Constant">3</span>:integer<span class="Special"> <- </span>copy <span class="Constant">35</span>:literal
<span class="Constant">4</span>:integer<span class="Special"> <- </span>get-address <span class="Constant">1</span>:address:point/deref<span class="Delimiter">,</span> <span class="Constant">0</span>:offset
]
<span class="traceContains">+run: instruction main/3</span>
<span class="traceContains">+run: address to copy is 2</span>
<span class="traceContains">+run: product 0 is 2</span>
<span class="Delimiter">:(after "reagent base = " following "case GET_ADDRESS:")</span>
base = canonize<span class="Delimiter">(</span>base<span class="Delimiter">);</span>
<span class="SalientComment">//:: helpers</span>
<span class="Delimiter">:(code)</span>
bool has_property<span class="Delimiter">(</span>reagent x<span class="Delimiter">,</span> string name<span class="Delimiter">)</span> <span class="Delimiter">{</span>
for <span class="Delimiter">(</span>index_t i = <span class="Constant">0</span><span class="Delimiter">;</span> i < x<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>x<span class="Delimiter">.</span>properties[i]<span class="Delimiter">.</span>first == name<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">true</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> <span class="Constant">false</span><span class="Delimiter">;</span>
<span class="Delimiter">}</span>
vector<string> property<span class="Delimiter">(</span>const reagent& r<span class="Delimiter">,</span> const string& name<span class="Delimiter">)</span> <span class="Delimiter">{</span>
for <span class="Delimiter">(</span>index_t p = <span class="Constant">0</span><span class="Delimiter">;</span> p != r<span class="Delimiter">.</span>properties<span class="Delimiter">.</span>size<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span>
if <span class="Delimiter">(</span>r<span class="Delimiter">.</span>properties[p]<span class="Delimiter">.</span>first == name<span class="Delimiter">)</span>
<span class="Identifier">return</span> r<span class="Delimiter">.</span>properties[p]<span class="Delimiter">.</span>second<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
<span class="Identifier">return</span> vector<string><span class="Delimiter">();</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->
|