From 0efb15a9eb706896cdabb9ca5d2b0c295c2dffcf Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 24 Aug 2025 14:22:48 -0400 Subject: rename parser → compiler, interp → vm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reflects reality better --- main.mjs | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'main.mjs') diff --git a/main.mjs b/main.mjs index 701659f..9e3e037 100644 --- a/main.mjs +++ b/main.mjs @@ -1,4 +1,4 @@ -import init, { make_interp } from './pkg/automathon.js'; +import init, { make_vm } from './pkg/automathon.js'; function wordlistElts(wordlist) { return wordlist.map((bc, i) => { @@ -25,12 +25,12 @@ function initWordlist() { }); } -function renderStack(interp) { +function renderStack(vm) { document.querySelectorAll('#stack').forEach(e => { while (e.lastChild) { e.removeChild(e.lastChild); } - interp.stack().reverse() + vm.stack().reverse() .forEach(datum => { const elt = document.createElement('li'); elt.textContent = datum; @@ -40,12 +40,12 @@ function renderStack(interp) { }); } -function renderCallStack(interp) { +function renderCallStack(vm) { document.querySelectorAll('#callstack').forEach(e => { while (e.lastChild) { e.removeChild(e.lastChild); } - interp.callstack().reverse() + vm.callstack().reverse() .forEach(datum => { const elt = document.createElement('li'); elt.textContent = `${datum.word}@${datum.offset}`; @@ -59,9 +59,9 @@ const highRange = new Range(); const highlight = new Highlight(highRange); CSS.highlights.set('exec', highlight); -function renderTextHighlight(interp) { - const ip = interp.ip(); - const anno = interp.annotation_at(ip) +function renderTextHighlight(vm) { + const ip = vm.ip(); + const anno = vm.annotation_at(ip) const src = document.querySelector('#src'); // this assumes the text node is the first child, maybe it isn't? @@ -69,27 +69,27 @@ function renderTextHighlight(interp) { highRange.setEnd(src.childNodes[0], anno.end); } -function tick(interp) { - if (!interp.tick()) { - interp.reset_ip(); +function tick(vm) { + if (!vm.tick()) { + vm.reset_ip(); } - const { word, offset } = interp.ip(); + const { word, offset } = vm.ip(); document.querySelectorAll('#wordlist .ip').forEach(e => e.classList.remove('ip')); const sel = selectorForIP(word, offset); document.querySelectorAll(sel).forEach(e => { e.classList.add('ip'); }); - renderStack(interp); - renderCallStack(interp); - renderTextHighlight(interp); + renderStack(vm); + renderCallStack(vm); + renderTextHighlight(vm); } async function loaded() { console.debug('running init'); const mod = await init(); console.debug('init done', mod); - const interp = make_interp(); + const vm = make_vm(); document.querySelector('#compile').onclick = e => { console.debug('compile clicked', e); @@ -104,32 +104,32 @@ async function loaded() { const text = document.querySelector('#src').textContent + '\n'; console.debug('compiling', text); const start = performance.now(); - const res = interp.compile(text); + const res = vm.compile(text); const end = performance.now(); console.info(`compile took ${end-start} ms`); if (res) { - const wordlist = wordlistElts(interp.wordlist()); + const wordlist = wordlistElts(vm.wordlist()); wordlist.forEach(elt => wordlistContainer.appendChild(elt)); initWordlist(); - renderStack(interp); - renderCallStack(interp); - renderTextHighlight(interp); + renderStack(vm); + renderCallStack(vm); + renderTextHighlight(vm); } }; document.querySelector('#tick').onclick = e => { console.debug('tick clicked', e); - tick(interp); + tick(vm); }; document.querySelector('#bench').onclick = e => { console.debug('bench clicked', e); const start = performance.now(); let tickCount = 0; for (let i = 0; i < 1_000_000; i++) { - tickCount += interp.run(); + tickCount += vm.run(); } const end = performance.now(); console.info(`run took ${end-start} ms for ${tickCount} ticks (${(end-start)/tickCount * 1_000_000} ns/tick).`); - console.info('result', interp.stack()); + console.info('result', vm.stack()); }; let blinkenRun = false; @@ -144,13 +144,13 @@ async function loaded() { const frameRate = 6; const onTimeout = _ => { if (blinkenRun) { - tick(interp); + tick(vm); setTimeout(onTimeout, 1_000 / frameRate); } } setTimeout(onTimeout); } - window.interp = interp; + window.vm = vm; } document.addEventListener('DOMContentLoaded', loaded); -- cgit v1.3