-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdoh.txt
103 lines (88 loc) · 2.66 KB
/
doh.txt
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
= Do Haskell =
Type:
+++<pre id='line0'>primes = f [2..] where f (p:xs) = p : f [x | x <- xs, x `mod` p /= 0]</pre>+++
Then:
+++<pre id='line1'>take 100 primes</pre>+++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<style type="text/css">
.term {
font-family: 'Inconsolata', monospace;
font-size: 90%;
color: #e6e6fa;
background: #301934;
border: 0;
margin: 0;
}
.term .termReverse {
background: #cbc3e3;
color: #301934;
}
table{border:0;}
</style>
<div id="termDiv"></div>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Another example:
+++<pre id='line2'>fibs = 0 : 1 : zipWith (+) fibs (tail fibs)</pre>+++
Then:
+++<pre id='line3'>fibs !! (fibs !! 11)</pre>+++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<script src="/~blynn/termlib.js"></script>
<script defer>
"use strict";
const repl = {};
function doLine(s) {
repl.buf = [];
repl.out = [];
repl.inp = teen(s);
repl.cursor = 0;
repl.eval_in = [], repl.eval_out = [];
repl.instance.exports.chat();
return tede(Uint8Array.from(repl.out));
}
function teen(s) { return (new TextEncoder()).encode(s); }
function tede(s) { return (new TextDecoder()).decode(s); }
var term = new Terminal( {handler: termHandler,
initHandler: loadingMessage,
cols: 80, rows: 25} );
function loadingMessage() {
term.write('Loading...');
}
function termHandler() {
this.newLine();
var line = doLine(this.lineBuffer);
if (line != "") this.write(line);
this.prompt();
}
term.open();
const lines = [0,1,2,3].map(k => document.getElementById("line" + k));
async function loadRepl() {
try {
repl.instance = (await WebAssembly.instantiateStreaming(fetch('doh.wasm'), {env:
{ putchar: c => repl.out.push(c)
, eof : () => repl.cursor == repl.inp.length
, getchar: () => repl.inp[repl.cursor++]
, nextout: () => { repl.buf.push(repl.out); repl.out = []; }
, argc : () => repl.args.length
, argvlen: i => repl.args[i].length
, argvat : (i, j) => repl.args[i][j]
, eval_put : c => repl.eval_in.push(c)
, eval_run : () => {
repl.eval_out = teen(eval(tede(Uint8Array.from(repl.eval_in))));
repl.eval_in = [];
}
, eval_size: () => repl.eval_out.length
, eval_at: i => repl.eval_out[i]
}})).instance;
repl.args = [teen("Main")];
repl.instance.exports.chat_new();
doLine("");
term.clear();
term.prompt();
lines.map(x => x.onclick = ev => { term.globals.insertText(x.textContent); });
} catch(err) {
console.log(err);
}
}
loadRepl();
</script>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++