Public
Edited
Aug 11, 2022
2 forks
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
asc = {
// adapted from https://cdn.jsdelivr.net/npm/assemblyscript@latest/dist/sdk.js
const BINARYEN_VERSION = "102.0.0-nightly.20211028";
const LONG_VERSION = "5.2.0";
const ASSEMBLYSCRIPT_VERSION = "0.19.23";
const ROOT = "https://cdn.jsdelivr.net/npm";
window.require = require;
return require.alias({
"binaryen": require(`${ROOT}/binaryen@${BINARYEN_VERSION}/index.js`),
"long": require(`${ROOT}/long@${LONG_VERSION}/dist/long.js`),
"assemblyscript": require(`${ROOT}/assemblyscript@${ASSEMBLYSCRIPT_VERSION}/dist/assemblyscript.js`)
})(`${ROOT}/assemblyscript@${ASSEMBLYSCRIPT_VERSION}/dist/asc.js`);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
addWASM = asc.compileString(addSource, { optimizeLevel: 3 })
Insert cell
Insert cell
Insert cell
{
const { instance } = await WebAssembly.instantiate(addWASM.binary, {});
return instance.exports.add(7, 4);
}
Insert cell
Insert cell
Insert cell
Insert cell
memoryWASM = asc.compileString(memorySource, { optimizeLevel: 3 })
Insert cell
Insert cell
{
const { instance } = await WebAssembly.instantiate(memoryWASM.binary, {});
const memoryArray = new Uint8Array(instance.exports.memory.buffer);
const value0 = memoryArray[0];
instance.exports.writeMemory(0, 12);
const value1 = memoryArray[0];
const value2 = instance.exports.readMemory(0);
return [value0, value1, value2];
}
Insert cell
Insert cell
Insert cell
Insert cell
ascCompile(errorSource)
Insert cell
ascCompile = source => {
const output = { stdout: asc.createMemoryStream(), stderr: asc.createMemoryStream() };
asc.main(["input.ts", "-O3", "--binaryFile", "binary", "--textFile", "text"], {
...output,
readFile: name => name === "input.ts" ? source : null,
writeFile: (name, contents) => output[name] = contents,
listFiles: () => [],
}, err => {
if (err)
throw new Error(output.stderr.toString());
});
return output;
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more