summaryrefslogtreecommitdiffstats
path: root/main.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-08-24 14:22:48 -0400
committerBrian Cully <bjc@spork.org>2025-08-24 15:36:55 -0400
commit0efb15a9eb706896cdabb9ca5d2b0c295c2dffcf (patch)
treed4bb89acd2ab1dd45ee40d9dffed5a4b73554b12 /main.mjs
parent57f32dc1d36650a5f282f1ba3906e9772b89709d (diff)
downloadautomathon-0efb15a9eb706896cdabb9ca5d2b0c295c2dffcf.tar.gz
automathon-0efb15a9eb706896cdabb9ca5d2b0c295c2dffcf.zip
rename parser → compiler, interp → vm
reflects reality better
Diffstat (limited to 'main.mjs')
-rw-r--r--main.mjs52
1 files changed, 26 insertions, 26 deletions
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);