- }
-})
-
-const channels = [{
- read: (writeAddr, maxBytes) => {
- const maxChars = maxBytes >> 1
- const bufView = new Uint16Array(wasmMem.buffer, writeAddr, maxChars)
- let i
- for (i = 0; i < maxChars && i < stdin.length; i++)
- bufView[i] = stdin.charCodeAt(i)
- stdin = stdin.substring(maxChars)
- return i << 1
- },
- write: (readAddr, maxBytes) =>
- output.print(String.fromCharCode.apply(
- null,
- new Uint16Array(wasmMem.buffer, readAddr, maxBytes >> 1)
- ))
-}]
-const simstack = []
-const rstack = []
-const dictionary = {
- ';': 1,
- 'LIT': 2,
- RINIT: 3,
- WORD: 16500,
- KEY: 5,
- DUP: 6,
- '+': 7,
- 'NOOP2': 8,
- '.': 9,
- '@': 10,
- '!': 11,
- EXECUTE: 12,
- NOOP: 13,
- 'JZ:': 14,
- 'JNZ:': 15,
- DROP: 16,
- 'WS?': 17,
- 'JMP:': 18,
- 'WPUTC': 19,
- 'WB0': 20,
- 'FIND': 21,
- 'NUMBER': 22,
- 'W!LEN': 23,
- 'J-1:': 24,
- 'BYE': 25,
- 'SWAP': 26,
- 'WORDS': 27,
- 'HERE': 28,
- 'DEFINE': 29,
- '2DUP': 30,
- 'ROT': 31,
- '2DROP': 32,
- ',': 33,
- '-': 34,
- 'CHANNEL!': 35,
- 'HERE!': 36,
- '=?': 37,
- '.s': 38,
- ':': 16800,
- 'MODE': 14336,
- 'EXECUTE-MODE': 16680,
- 'QUIT': 16384,
- 'INTERPRET': 16400
-}
-const wasmImport = {
- env: {
- pop: () => simstack.pop(),
- push: (val) => simstack.push(val),
- rinit: () => rstack.length = 0,
- rpop: () => rstack.pop(),
- rpush: (val) => rstack.push(val),
- sys_write: (channel, addr, u) => {
- if (channels[channel] === undefined)
- return
- console.log(`write ch:${channel} addr:${addr} len:${u}`)
- channels[channel].write(addr, u)
- },
- sys_read: (channel, toBuffer) => {
- console.log(`read ch:${channel} buf:${toBuffer} current: ${stdin}`)
- const lenView = new DataView(wasmMem.buffer, toBuffer, 8)
- const maxBytes = lenView.getUint32(0,true)
- console.log(`read blen:${lenView.getUint32(0,true)} cstrlen:${lenView.getUint32(4,true)}`)
- /* If the channel is undefined, or if there isn't enough room in
- * toBuffer for even one character, then, if there is enough
- * room for an int write a zero, exit */
- if (channels[channel] === undefined || maxBytes < 6) {
- if (maxBytes >= 4)
- lenView.setUint32(4,0,true)
+ })
+/* document.addEventListener('keydown', (event) => {
+ //console.log(`keydown: ${event.key}`)
+ if (event.key != "F5") {
+ event.preventDefault()
+ event.stopPropagation()
+ switch (event.key) {
+ case "Enter":
+ txtoutput.textContent += '\n'
+ stdin += '\n'
+ forth()
+ output.print(" _ok.")
+ outframe.scrollTop = outframe.scrollHeight;
+ txtoutput.textContent += '\n'
+ break
+ case "Backspace":
+ stdin = stdin.substring(0, stdin.length - 1)
+ txtoutput.textContent = txtoutput.textContent.substring(0, txtoutput.textContent.length - 1)
+ break
+ default:
+ if (event.key.length == 1) {
+ const input = event.ctrlKey ? ` \\\^${event.key} ` : event.key
+ stdin += input
+ output.print(input)
+ }
+ break