How to use @assemblyscript/loader - 3 common examples

To help you get started, we’ve selected a few @assemblyscript/loader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ColinEberhardt / atari2600-wasm / web / main.js View on Github external
const run = async () => {
  const WIDTH = 160;
  const HEIGHT = 192;

  const imports = {
    env: {
      abort(_msg, _file, line, column) {
        console.error("abort called at index.ts:" + line + ":" + column);
      }
    }
  };

  const module = await loader.instantiateStreaming(fetch("../build/untouched.wasm"));
  const memory = module.Memory.wrap(module.consoleMemory);
  const tia = module.TIA.wrap(module.tia);
  const buffer = module.__getArrayView(memory.buffer);
  result.data.forEach((byte, index) => {
    buffer[index + 0x1000] = byte;
  });

  // initialise the canvas
  const canvas = document.getElementById("canvas");
  const ctx = canvas.getContext("2d");
  ctx.fillStyle = "black";
  ctx.fillRect(0, 0, WIDTH, HEIGHT);

  const updateDisplay = () => {
    const screenBuffer = module.__getArray(tia.display);
    const imageData = ctx.createImageData(WIDTH, HEIGHT);
github ColinEberhardt / atari2600-wasm / test / cpu.js View on Github external
beforeEach(() => {
  wasmModule = loader.instantiateSync(compiled, {
    env: {
      trace: () => {}
    }
  });
  cpu = wasmModule.CPU.wrap(wasmModule.cpu);
  statusRegister = wasmModule.StatusRegister.wrap(cpu.statusRegister);
});
github alangpierce / sucrase / assemblyscript-prototype / index.js View on Github external
require("sucrase/register");
const fs = require("fs");

const {loadProjectFiles} = require("../benchmark/loadProjectFiles");
const {parse} = require("../src/parser");

let wasmModule;
try {
  wasmModule = new WebAssembly.Module(fs.readFileSync(__dirname + "/build/optimized.wasm"));
} catch (e) {
  console.error(e);
  throw e;
}
const {instantiate} = require("@assemblyscript/loader");
const instance = instantiate(wasmModule, {
  env: {
    abort: () => {
      throw new Error();
    },
    trace: (s, n) => {
      try {
        console.log(instance.getString(s), n);
      } catch {
        console.log(n);
      }
    },
  },
});

async function run() {
  const files = await loadProjectFiles("./src");

@assemblyscript/loader

A convenient loader for AssemblyScript modules.

Apache-2.0
Latest version published 1 month ago

Package Health Score

88 / 100
Full package analysis