66 lines
1.9 KiB
HTML
66 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Examples - Fold</title>
|
|
</head>
|
|
<body>
|
|
<h1>Fold</h1>
|
|
|
|
<a href="index.html">List</a> - <a href="fold.py.html">Source</a> - <a href="fold.wat.html">WebAssembly</a>
|
|
|
|
<div style="white-space: pre;" id="results"></div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
let importObject = {
|
|
'imports': {
|
|
'log': log,
|
|
}
|
|
};
|
|
|
|
let results = document.getElementById('results');
|
|
|
|
function log(txt)
|
|
{
|
|
let span = document.createElement('span');
|
|
span.innerHTML = txt;
|
|
results.appendChild(span);
|
|
let br = document.createElement('br');
|
|
results.appendChild(br);
|
|
}
|
|
|
|
WebAssembly.instantiateStreaming(fetch('fold.wasm'), importObject)
|
|
.then(app => {
|
|
stdlib_alloc___init__ = app.instance.exports['stdlib.alloc.__init__']
|
|
stdlib_alloc___init__()
|
|
|
|
stdlib_types___alloc_bytes__ = app.instance.exports['stdlib.types.__alloc_bytes__']
|
|
|
|
let offset0 = stdlib_types___alloc_bytes__(0);
|
|
let offset1 = stdlib_types___alloc_bytes__(1);
|
|
let offset2 = stdlib_types___alloc_bytes__(2);
|
|
let offset4 = stdlib_types___alloc_bytes__(4);
|
|
|
|
var i8arr0 = new Uint8Array(app.instance.exports.memory.buffer, offset0 + 4, 0);
|
|
var i8arr1 = new Uint8Array(app.instance.exports.memory.buffer, offset1 + 4, 1);
|
|
i8arr1[0] = 0x20;
|
|
var i8arr2 = new Uint8Array(app.instance.exports.memory.buffer, offset2 + 4, 2);
|
|
i8arr2[0] = 0x20;
|
|
i8arr2[1] = 0x10;
|
|
var i8arr4 = new Uint8Array(app.instance.exports.memory.buffer, offset4 + 4, 4);
|
|
i8arr4[0] = 0x20;
|
|
i8arr4[1] = 0x10;
|
|
i8arr4[2] = 0x08;
|
|
i8arr4[3] = 0x04;
|
|
i8arr4[4] = 0x02;
|
|
|
|
log('foldl(or, 1, [' + i8arr0 + ']) = ' + app.instance.exports.foldl_u8_or_1(offset0));
|
|
log('foldl(or, 1, [' + i8arr1 + ']) = ' + app.instance.exports.foldl_u8_or_1(offset1));
|
|
log('foldl(or, 1, [' + i8arr2 + ']) = ' + app.instance.exports.foldl_u8_or_1(offset2));
|
|
log('foldl(or, 1, [' + i8arr4 + ']) = ' + app.instance.exports.foldl_u8_or_1(offset4));
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|