summaryrefslogtreecommitdiffstats
path: root/main.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-08-23 10:22:11 -0400
committerBrian Cully <bjc@spork.org>2025-08-23 11:36:31 -0400
commit5b8962e35836cf7ccbfdbca312f6b0eb9269e2a6 (patch)
treee537f04279c4b1ef27f7040c25beff2551c8bf84 /main.mjs
parent12c06171b3f94696e852c3910c116f56cbfc5b64 (diff)
downloadautomathon-5b8962e35836cf7ccbfdbca312f6b0eb9269e2a6.tar.gz
automathon-5b8962e35836cf7ccbfdbca312f6b0eb9269e2a6.zip
show wordlist in html on compile
Diffstat (limited to 'main.mjs')
-rw-r--r--main.mjs43
1 files changed, 35 insertions, 8 deletions
diff --git a/main.mjs b/main.mjs
index a555a60..908aaa2 100644
--- a/main.mjs
+++ b/main.mjs
@@ -1,26 +1,53 @@
-import init, { compile, run, tick, wordlist, ip, interp } from './pkg/automathon.js';
+import init, { make_interp } from './pkg/automathon.js';
+
+function wordlistElts(wordlist) {
+ return wordlist.map((bc, i) => {
+ const bcElt = document.createElement('x-bytecode');
+ bcElt.setAttribute('x-index', i);
+ for (let i = 0; i < bc.len(); i++) {
+ const opElt = document.createElement('x-op');
+ opElt.setAttribute('x-index', i);
+ opElt.textContent = bc.at(i);
+ bcElt.appendChild(opElt);
+ }
+ return bcElt;
+ })
+}
async function loaded() {
console.debug('running init');
const mod = await init();
console.debug('init done', mod);
+ const interp = make_interp();
document.querySelector('#compile').onclick = e => {
console.debug('compile clicked', e);
- let text = document.querySelector('textarea').textContent;
- compile(text);
+
+ let wordlistContainer = document.querySelector('#wordlist');
+ while (wordlistContainer.lastChild) {
+ console.debug('removing child', wordlistContainer.lastChild)
+ wordlistContainer.removeChild(wordlistContainer.lastChild);
+ }
+ console.debug('container has firstchild', wordlistContainer.firstChild)
+
+ // always add a newline until i decide what to do with the parser.
+ const text = document.querySelector('textarea').value + '\n';
+ const start = performance.now();
+ const res = interp.compile(text);
+ const end = performance.now();
+ console.info(`compile took ${end-start} ms`);
+ if (res) {
+ const wordlist = wordlistElts(interp.wordlist());
+ wordlist.forEach(elt => wordlistContainer.appendChild(elt));
+ }
};
document.querySelector('#tick').onclick = e => {
console.debug('tick clicked', e);
- tick();
- console.debug('result of ip', ip());
- console.debug('result of wordlist', wordlist());
- console.debug('result of interp', interp());
};
document.querySelector('#run').onclick = e => {
console.debug('run clicked', e);
- run();
};
+ window.interp = interp;
}
document.addEventListener('DOMContentLoaded', loaded);