Stabel

test_expression.js at tip
Login

File test_expression.js from the latest check-in


// Execute with: node --inspect-brk ./test_expression.js
// Then open chrome and go to: chrome://inspect

const compiler = require('./wasm_tests/compiler.wrapper');
const wabtInit = require('wabt');

const memory = new WebAssembly.Memory({
    initial: 1
});

global.memView = new Uint32Array(memory.buffer, 0, 512);

async function init() {
    const wabt = await wabtInit();
    const wat = await compiler.toWat('main', `
        def: main
        : { 5 6 7 }
          1 array-get
          swap drop
    `);

    const wasmModule = wabt.parseWat('tmp', wat, {
        bulk_memory: true
    }).toBinary({}).buffer;

    const imports = {
        host: {
            memory: memory
        }
    };

    const program = await WebAssembly.instantiate(wasmModule, imports);
    program.instance.exports.main();
}

init();