/
index.html
299 lines (255 loc) · 11.6 KB
/
index.html
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>FunTAL: mixing a functional language with assembly.</title>
<link rel="stylesheet" type="text/css" href="codemirror.css">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="holder">
<h1>FunTAL: mixing a functional language with assembly.</h1>
<h3>Daniel Patterson, Jamie Perconti, Christos Dimoulas, Amal Ahmed.</h3>
<h4>To appear in Programming Language Design and Implementation (PLDI) 2017.</h4>
<h3>Draft <a href="https://dbp.io/pubs/2017/funtal.pdf">paper</a> and <a href="https://dbp.io/pubs/2017/funtal-tr.pdf">technical appendix</a>.</h3>
<p>We present FunTAL, the first multi-language system to
formalize safe interoperability between a high-level
functional language and low-level assembly code while
supporting compositional reasoning about the mix. A central
challenge in developing such a multi-language is how to
bridge the gap between assembly, which is staged into calls
to continuations, and high-level code, where subterms return
a result. We present a compositional stack-based typed
assembly language that supports components, comprised of one
or more basic blocks, that may be embedded in high-level
contexts. We also present a logical relation for FunTAL that
supports reasoning about equivalence of high-level components
and their assembly replacements, mixed-language programs with
callbacks between languages, and assembly components
comprised of different numbers of basic blocks.</p>
<hr/>
<h2>Artifact: a FunTAL type checker and small-step machine.</h2>
<h3>Daniel Patterson and Gabriel Scherer.</h3>
<h4>Source code and build instructions: <a href="https://github.com/dbp/funtal">github.com/dbp/funtal</a></h4>
<p>
We present a type checker and stepper for the FunTAL machine
semantics. We include <strong>well-typed, runnable examples
from
the <a href="https://dbp.io/pubs/2017/funtal.pdf">paper</a></strong>,
as well as a few smaller examples to start with. With our
artifact, you write programs and then type check / load them
into a FunTAL machine. You can then step forward and backwards
through the evaluation. At each step, the machine shows the
registers, stack, and heap, as well as the redex and the
context.</p>
<p>
<strong>Important:</strong> the programs entered
into the editor should be Fun programs at the top; a pure
TAL component <code>C</code>
can be embedded as <code>FT[t,?]C</code> where <code>t</code> is
the return type, as we see in examples below. We do this so
that all programs run through the stepper have a return value.
</p>
<p><strong>Note:</strong> there are some syntactic differences
from the presentation in
the <a href="https://dbp.io/pubs/2017/funtal.pdf">paper</a>,
which nonetheless we expect will be the primary reference for
the language. These changes were made to eliminate the
necessity of unicode, reduce ambiguity in the grammar, and
make the type checking algorithm syntax-directed. We summarize
these changes at the bottom of this page.</p>
<p>
<strong>Examples from <a href="https://dbp.io/pubs/2017/funtal.pdf">paper</a>:</strong>
</p>
<ul>
<li><a href="#" id="call_to_call">Call to call</a> (Fig. 3 & 4, pg. 6)</li>
<li><a href="#" id="higher_order">JIT</a> (Fig. 11 & 12, pg. 10)</li>
<li><a href="#" id="blocks_1">Blocks 1</a> (Fig. 16, top, pg. 12)</li>
<li><a href="#" id="blocks_2">Blocks 2</a> (Fig. 16, bottom, pg. 12)</li>
<li><a href="#" id="factorial_f">Factorial (functional)</a> (Fig. 17, top, pg. 13)</li>
<li><a href="#" id="factorial_t">Factorial (imperative)</a> (Fig. 17, bottom, pg. 13)</li>
</ul>
<p>
<strong>Additional examples:</strong>
<a href="#" id="import">Import</a>
| <a href="#" id="simple">Simple call</a>
| <a href="#" id="omega">Omega</a>
| <a href="#" id="with_ref">Mutable reference</a>
</p>
<p>
<strong>Examples with errors:</strong>
</p>
<ul>
<li><a href="#" id="stack_error">Missing <code>sfree 1</code> after line 8</a></li>
<li><a href="#" id="call_error">Trying to <code>jmp ra</code> instead of <code>ret ra {r1}</code> on line 14</a></li>
</ul>
<div class="box">
<textarea id="input">
</textarea>
<div id="error"></div>
</div>
<div class="buttons">
<button id="load">↓ Type check & load ↓</button>
</div>
<div class="box">
<div class="cm-s-default" id="machine">
<div class="buttons left">
<button title="one step backward" id="prev">Step ←</button>
<button id="pc"> </button>
<button title="one step forward" id="next">Step →</button>
<button title="up to 100 steps" id="many">Step →*</button>
</div>
<hr/>
<h5>Registers:</h5>
<pre id="registers"></pre>
<hr/>
<h5>Stack:</h5>
<pre id="stack"></pre>
<hr/>
<h5>Redex:</h5>
<pre id="focus"></pre>
<hr/>
<h5>Context/Result:</h5>
<pre id="context"></pre>
<hr/>
<h5>Heap:</h5>
<pre id="heap"></pre>
</div>
</div>
<br/><br/>
<h3>Syntactic differences from the <a href="https://dbp.io/pubs/2017/funtal.pdf">paper</a>:</h3>
<table>
<tr><th>Paper</th><th>Artifact</th><th>Description</th></tr>
<tr>
<td><code>(ι; ..., l → h, ...)</code></td>
<td><code>([instr; ...],[l -> h, ...])</code></td>
<td>TAL components use brackets around instructions and the heap fragment.</td>
</tr>
<tr>
<td><code><sup>τ</sup>FT e</code></td>
<td><code>FT[t,s] e</code></td>
<td><code>FT</code> (Fun outside, TAL inside) boundary
specifies the type s that the stack has after running e.</td>
</tr>
<tr>
<td><code><sup>τ</sup>FT e</code></td>
<td><code>FT[t,?] e</code></td>
<td><code>FT</code> boundaries can use <code>?</code> to indicate
that running <code>e</code> will not modify the type of
the stack (though values may be modified), allowing <code>s</code>
to be inferred.</td>
</tr>
<tr>
<td><code>import r,<sup>σ</sup>TF<sup>τ</sup> e</code></td>
<td><code>import r1, s as z, t TF{e};</code></td>
<td><code>import</code> binds the stack <code>s</code> on
return as <code>z</code> with Fun expression <code>e</code> of
type <code>t</code>.</td>
</tr>
<tr>
<td><code>α, ζ, ε</code></td>
<td><code>a1, z21, e5</code></td>
<td>TAL type variables must begin with <code>a</code>, stack
variables with <code>z</code>, and return marker variables
with <code>e</code>.</td>
</tr>
<tr>
<td><code>· | τ :: ... </code></td>
<td><code>:: | t :: ... ::</code></td>
<td>Empty stack prefixes (in protect, stack modifying
lambdas) are written as <code>::</code>, and stack prefixes
end with <code>::</code>.</td>
</tr>
<tr>
<td><code>∀, μ, λ, ∃, •</code></td>
<td><code>forall, mu, lam, exists, *</code></td>
<td>Greek letters and quantifiers are replaced by english keywords.</td>
</tr>
<tr>
<td><code>•</code></td>
<td><code>*</code></td>
<td>The concrete stack symbol <code>•</code> is written <code>*</code>.</td>
</tr>
<tr>
<td><code>u[ω]</code></td>
<td><code>u[ω, ω...]</code></td>
<td>TAL instantiation is n-ary. (This was mentioned as syntactic sugar.)</td>
</tr>
<tr>
<td><code>{χ; σ}<sup>q</sup></code></td>
<td><code>{χ; σ} q</code></td>
<td>The return marker superscript is just written in line.</td>
</tr>
<tr>
<td><code>λ<sup>φ</sup><sub>φ</sub>(x:τ...).t</code></td>
<td><code>lam[φ][φ](x:τ...).e</code>,<br/>
<code>(τ...) [φ] -> [φ] τ</code></td>
<td>The stack prefixes of stack-modifying functions are bracketed, in line.</td>
</tr>
<tr>
<td><code>unpack <α, r<sub>d</sub>> u</code></td>
<td><code>unpack <α, r<sub>d</sub>>, u</code></td>
<td>The TAL instruction <code>unpack</code> has comma-separated argument,
for consistency with other instructions.</td>
</tr>
<tr>
<td><code>l -> <1, 2>,<br/> l' -> (code[δ]...)</code></td>
<td><code>[l -> ref <1, 2>,<br/> l' -> box (code[δ]...)]</code></td>
<td>Heap values are preceded by an explicit mutability marker <code>box</code> or <code>ref</code>.</td>
</tr>
</table>
<div class="footer">
Powered by OCaml and js_of_ocaml.
</div>
</div>
<script type="text/javascript" src="codemirror.js"></script>
<script type="text/javascript" src="simple.js"></script>
<script type="text/javascript" src="matchbrackets.js"></script>
<script type="text/javascript" src="runmode.js"></script>
<script type="text/javascript">
CodeMirror.defineSimpleMode("funtal", {
start: [
{regex: /forall|code|box|ref|add|sub|mul|bnz|ld|st|ralloc|balloc|mv|unpack|unfold|salloc|sfree|sld|sst|jmp|call|ret|halt|protect|import|as|pack|fold|if0|pi|FT/, token: "keyword"},
{regex: /unit|int|exists|mu|\*|\:\:|end|out|r1|r2|r3|r4|r5|r6|r7|r8|r9|ra/, token: "atom"}
],
meta:
{ dontIndentStates: ["start"]
}});
window.highlighted_lines = [];
window.codemirror = CodeMirror.fromTextArea(document.getElementById("input"), {
lineNumbers: true,
matchBrackets: true,
viewportMargin: Infinity,
gutters: ["CodeMirror-linenumbers","errors"],
mode: "funtal"
});
window.seterror = function(line, msg) {
clearerrors();
if (line > 0) {
var n = document.createElement("div");
n.className = "error-marker";
n.setAttribute("title", msg);
window.codemirror.setGutterMarker(line-1, "errors", n);
window.codemirror.addLineClass(line-1, "wrap", "error-line");
}
function esc(s) {
return s.replace(/\</g,"<").replace(/\>/g,">");
}
var holder = document.getElementById("error");
holder.innerHTML = "<div class='error-marker'></div><span>" + esc(msg) + "</span>";
};
window.clearerrors = function() {
window.codemirror.clearGutter("errors");
document.getElementById("error").innerHTML = "";
window.codemirror.eachLine(function (lh) {
window.codemirror.removeLineClass(lh,"wrap");
});
}
window.settext = function(i, t) {
var n = document.getElementById(i);
CodeMirror.runMode(t, "funtal", n);
}
</script>
<script type="text/javascript" src="web.js"></script>
</body>
</html>