phasm/examples/crc32.html
Johan B.W. de Vries e589223dbb Static Arrays. CRC32 compiles \o/
Doesn't give right answer yet and out of bound check fails.
No constructor yet for static arrays, but module constants
work. Which don't work yet for tuples and structs.

Also, u32 for indexing please.

Also, more module constant types.
2022-08-18 20:53:21 +02:00

48 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Examples - CRC32</title>
</head>
<body>
<h1>Buffer</h1>
<a href="index.html">List</a> - <a href="crc32.py.html">Source</a> - <a href="crc32.wat.html">WebAssembly</a>
<div style="white-space: pre;" id="results"></div>
<script type="text/javascript">
let importObject = {};
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('crc32.wasm'), importObject)
.then(app => {
// Allocate room within the memory of the WebAssembly class
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);
// Write into allocated memory
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] = 0x61;
log('crc32([' + i8arr0 + ']) = ' + app.instance.exports.crc32(offset0));
log('crc32([' + i8arr1 + ']) = ' + app.instance.exports.crc32(offset1));
});
</script>
</body>
</html>