about summary refs log tree commit diff stats
path: root/html/048call_variable.cc.html
blob: 286c83c10a8c68e0f5c20472fd4bbb76a0402978 (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
<!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 - 048call_variable.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; }
.Identifier { color: #008080; }
.Constant { color: #008080; }
.Comment { color: #8080ff; }
.Delimiter { color: #c000c0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.traceContains { color: #008000; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment">//: push a variable recipe on the call stack</span>

<span class="Delimiter">:(scenario call_literal_recipe)</span>
recipe main [
  <span class="Constant">1</span>:number<span class="Special"> &lt;- </span>call f:recipe<span class="Delimiter">,</span> <span class="Constant">34</span>:literal
]
recipe f [
  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>next-ingredient
  reply <span class="Constant">2</span>:number
]
<span class="traceContains">+mem: storing 34 in location 1</span>

<span class="Delimiter">:(scenario call_variable)</span>
recipe main [
  <span class="Constant">1</span>:number/recipe<span class="Special"> &lt;- </span>copy <span class="Constant">1001</span>:literal/f  <span class="Comment"># hack: assumes tests start recipes at 1000</span>
  <span class="Constant">2</span>:number<span class="Special"> &lt;- </span>call <span class="Constant">1</span>:number/recipe<span class="Delimiter">,</span> <span class="Constant">34</span>:literal
]
recipe f [  <span class="Comment"># recipe 1001</span>
  <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>next-ingredient
  reply <span class="Constant">3</span>:number
]
<span class="traceContains">+mem: storing 34 in location 2</span>
<span class="CommentedCode">#? ?</span>

<span class="Delimiter">:(before &quot;End Primitive Recipe Declarations&quot;)</span>
CALL<span class="Delimiter">,</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Numbers&quot;)</span>
Recipe_number[<span class="Constant">&quot;call&quot;</span>] = CALL<span class="Delimiter">;</span>
<span class="Delimiter">:(before &quot;End Primitive Recipe Implementations&quot;)</span>
case CALL: <span class="Delimiter">{</span>
  recipe_number r = <span class="Constant">0</span><span class="Delimiter">;</span>
  if <span class="Delimiter">(</span>current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>initialized<span class="Delimiter">)</span> <span class="Delimiter">{</span>
    assert<span class="Delimiter">(</span>scalar<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)));</span>
    <span class="Comment">// 'call' received an integer recipe_number</span>
    r = ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span>
  <span class="Delimiter">}</span>
  else <span class="Delimiter">{</span>
    <span class="Comment">// 'call' received a literal recipe name</span>
    r = Recipe_number[current_instruction<span class="Delimiter">().</span>ingredients<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>name]<span class="Delimiter">;</span>
  <span class="Delimiter">}</span>
  Current_routine<span class="Delimiter">-&gt;</span>calls<span class="Delimiter">.</span>push_front<span class="Delimiter">(</span>call<span class="Delimiter">(</span>r<span class="Delimiter">));</span>
  ingredients<span class="Delimiter">.</span>erase<span class="Delimiter">(</span>ingredients<span class="Delimiter">.</span>begin<span class="Delimiter">());</span>  <span class="Comment">// drop the callee</span>
  <span class="Identifier">goto</span> complete_call<span class="Delimiter">;</span>
<span class="Delimiter">}</span>
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->