From 5b8962e35836cf7ccbfdbca312f6b0eb9269e2a6 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sat, 23 Aug 2025 10:22:11 -0400 Subject: show wordlist in html on compile --- main.mjs | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'main.mjs') 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); -- cgit v1.3