blob: 674ab1e0bbb93419d8a4411c79429c5f61021047 (
plain) (
blame)
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
|
<!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 - 020run.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; }
.cSpecial { color: #008000; }
.CommentedCode { color: #6c6c6c; }
.traceAbsent { color: #c00000; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.Identifier { color: #008080; }
.SalientComment { color: #00ffff; }
.traceContains { color: #008000; }
-->
</style>
<script type='text/javascript'>
<!--
-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: Phase 3: Start running a loaded and transformed recipe.</span>
<span class="Comment">//:</span>
<span class="Comment">//: So far we've seen recipes as lists of instructions, and instructions point</span>
<span class="Comment">//: at other recipes. To kick things off mu needs to know how to run certain</span>
<span class="Comment">//: 'primitive' recipes. That will then give the ability to run recipes</span>
<span class="Comment">//: containing these primitives.</span>
<span class="Comment">//:</span>
<span class="Comment">//: This layer defines a skeleton with just two primitive recipes: IDLE which</span>
<span class="Comment">//: does nothing, and COPY, which can copy numbers from one memory location to</span>
<span class="Comment">//: another. Later layers will add more primitives.</span>
<span class="Delimiter">:(scenario copy_literal)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
]
<span class="traceContains">+run: 1:number <- copy 23:literal</span>
<span class="traceContains">+mem: storing 23 in location 1</span>
<span class="Delimiter">:(scenario copy)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal
<span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">1</span>:number
]
<span class="traceContains">+run: 2:number <- copy 1:number</span>
<span class="traceContains">+mem: location 1 is 23</span>
<span class="traceContains">+mem: storing 23 in location 2</span>
<span class="Delimiter">:(scenario copy_multiple)</span>
recipe main [
<span class="Constant">1</span>:number<span class="Delimiter">,</span> <span class="Constant">2</span>:number<span class="Special"> <- </span>copy <span class="Constant">23</span>:literal<span class="Delimiter">,</span> <span class="Constant">24</span>:literal
]
<span class="traceContains">+mem: storing 23 in location 1</span>
<span class="traceContains">+mem: storing 24 in location 2</span>
<span class="Delimiter">:(before "End Types")</span>
<span class="Comment">// Book-keeping while running a recipe.</span>
<span class="Comment">//: Later layers will change this.</span>
struct routine <span class="Delimiter">{</span>
recipe_number running_recipe<span class="Delimiter">;</span>
long long int running_step_index<span class="Delimiter">;</span>
routine<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> :running_recipe<span class="Delimiter">(</span>r<span class="Delimiter">),</span> running_step_index<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{}</span>
bool completed<span class="Delimiter">()</span> const<span class="Delimiter">;</span>
<span class="Delimiter">};</span>
<span class="Delimiter">:(before "End Globals")</span>
routine* Current_routine = <span class="Constant">NULL</span><span class="Delimiter">;</span>
<span class="Delimiter">:(code)</span>
void run<span class="Delimiter">(</span>recipe_number r<span class="Delimiter">)</span> <span class="Delimiter">{</span>
routine rr<span class="Delimiter">(</span>r<span class="Delimiter">);</span>
Current_routine = &rr<span class="Delimiter">;</span>
run_current_routine<span class="Delimiter">();</span>
<span class="Delimiter">}</span>
void run_current_routine<span class="Delimiter">()</span>
<span class="Delimiter">{</span> <span class="Comment">// curly on a separate line, because later layers will modify header</span>
while <span class="Delimiter">(</span>!Current_routine<span class="Delimiter">-></span>completed<span class="Delimiter">())</span> <span class="Comment">// later layers will modify condition</span>
<span class="Delimiter">{</span>
<span class="Comment">// Running One Instruction.</span>
if <
|