-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
170 lines (140 loc) · 4.84 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
<!doctype html>
<html>
<head lang="en-US" dir="ltr">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Pointfree</title>
<meta name="author" content="Sergey Vinokurov">
<meta name="description" content="Pointfree conversion in your browser through WASM">
<meta name="keywords" content="Haskell, Pointfree, WASM">
<style>
* {
padding: 0;
margin: 0;
font-family: sans-serif;
border-radius: 0;
}
body {
padding-top: 2rem;
display: flex;
flex-direction: column;
height: 100%;
background-color: #333;
color: #fefefe;
text-align: center;
}
main {
margin: 0 auto;
}
#input, #output {
margin-top: 1rem;
padding: 0.5rem;
width: min(80vw, 35rem);
font-family: monospace;
font-size: 1rem;
border: 0;
}
#input-process {
margin-top: 1rem;
padding: 0.5rem;
font-family: sans-serif;
font-size: 120%;
color: #000;
border-radius: 0 !important;
}
a {
color: #eb82dc;
}
a:visited {
color: #d5c5ff;
}
@media (pointer:coarse) {
h1 {
font-size: 300%;
}
#input, #output {
margin-top: 2rem;
width: max(95vw, 35rem);
font-size: 200%;
padding: 2rem 1.5rem;
box-sizing: border-box;
}
#input-process {
font-size: 200%;
padding: 2rem !important;
margin: 3rem 0 1rem 0;
}
}
</style>
</head>
<body>
<main>
<h1>Pointfree.wasm</h1>
<input id="input" type="text" autofocus="true" value="\xs ys -> sum (zipWith (*) xs ys)" spellcheck="false" />
<br/>
<button id="input-process" onclick="process()">
Convert to pointfree
</button>
<br/>
<textarea id="output" type="text" readonly="true" placeholder="pointfree result" spellcheck="false" rows="1"></textarea>
<br/>
<br/>
<p>
You can learn more about pointfree programming at <a href="https://wiki.haskell.org/Pointfree">Haskell wiki</a>.
</p>
<p>
Built by <a href="https://github.com/sergv">Sergey Vinokurov</a> with significant contributions by <a href="https://github.com/TerrorJack">Cheng Shao</a>.
</p>
<p>
This project is made possible thanks to the <a href="https://hackage.haskell.org/package/pointfree">pointfree</a> package and all the contributions to the WASM support in GHC.
</p>
<p>
The sources for this project are on github at <a href="https://github.com/pointfree-wasm/pointfree-wasm.github.io">https://github.com/pointfree-wasm/pointfree-wasm.github.io</a>.
</p>
</main>
<script type="module">
globalThis.realWorker = function () {
return "WASM not ready yet, please try again in a few moments";
};
async function process() {
const input = document.getElementById("input");
const output = document.getElementById("output");
const result = await globalThis.realWorker(input.value);
if (Array.isArray(result)) {
if (result.length == 0) {
output.rows = 2;
output.value = "No results, most likely the input expression is malformed but specific problem cannot be shown by this application.\nPlease double check the input or try feeding it to a Haskell REPL, e.g. GHCi, to find out the specific problem.";
} else {
output.rows = result.length;
output.value = result.join("\n");
}
} else {
output.value = result;
}
return true;
}
globalThis.process = process;
</script>
<script type="module">
import { WASI, OpenFile, File, ConsoleStdout } from "https://cdn.jsdelivr.net/npm/@bjorn3/browser_wasi_shim@0.2.21/dist/index.js"
import ghc_wasm_jsffi from "./pointfree-wasm.js";
const fds = [
new OpenFile(new File([])), // stdin
ConsoleStdout.lineBuffered((msg) => console.log(`[WASI stdout] ${msg}`)),
ConsoleStdout.lineBuffered((msg) => console.warn(`[WASI stderr] ${msg}`)),
];
const options = {};
const wasi = new WASI([], [], fds, options);
var memory = new WebAssembly.Memory({ initial: 1 });
const instance_exports = {};
var importObject = {
wasi_snapshot_preview1: wasi.wasiImport,
ghc_wasm_jsffi: ghc_wasm_jsffi(instance_exports)
};
const { instance } = await WebAssembly.instantiateStreaming(fetch("pointfree-wasm.wasm"), importObject);
Object.assign(instance_exports, instance.exports);
wasi.initialize(instance);
globalThis.realWorker = instance.exports.pointfreeWasm;
</script>
</body>
</html>