-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
49 lines (49 loc) · 1.46 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title></title>
<script>
let buffer = "";
function printChar(c) {
const s = String.fromCharCode(c);
buffer += s;
if (s === "\n") {
console.log(buffer);
buffer = "";
}
}
let importObj = {
"js-ffi": {print: printChar},
};
let rt;
let prog;
fetch('webml-rt/target/wasm32-unknown-unknown/release/webml_rt.wasm').then(response =>
response.arrayBuffer()
).then(buffer =>
WebAssembly.instantiate(buffer, {})
).then(({module, instance}) => {
rt = instance;
importObj["webml-rt"] = {
alloc: instance.exports.alloc,
init: instance.exports.init,
memory: instance.exports.memory,
};
}).then(_ =>
fetch('out.wasm')
).then(response =>
response.arrayBuffer()
).then(buffer =>
WebAssembly.instantiate(buffer, importObj)
).then(({module, instance}) => {
/* const scriptElem = document.createElement('script');
* scriptElem.src = 'out.js';
* document.body.appendChild(scriptElem); */
prog = instance
}
)
;
</script>
</head>
<body></body>
</html>