import init, { make_vm } from './wasm/automathon.js'; let vm; function compile(text) { const start = performance.now(); const res = vm.compile(text); const end = performance.now(); console.info(`compile took ${end-start} ms`); postMessage({ kind: 'compile', res, trans: vm.trans() }); } function tick() { if (!vm.tick()) { vm.reset_ip(); } postMessage({ kind: 'tick', trans: vm.trans() }); } async function messageHandler(e) { const { kind } = e.data; switch (kind) { case 'compile': compile(e.data.text); break; case 'tick': tick(); break; default: console.error('invalid message to robo worker', e.data); postMessage({ kind: 'error', error: 'badmsg' }); } } let mod; async function loaded() { console.debug('loading robo worker'); if (mod === undefined) { console.debug('worker running init'); mod = await init(); console.debug('worker init done'); vm = make_vm(); console.debug('worker vm made'); } addEventListener('message', messageHandler); console.debug('bjc loaded robo'); } loaded();