diff --git a/src/node_modules/buttons.js b/src/node_modules/buttons.js index 92e6974..87a1662 100644 --- a/src/node_modules/buttons.js +++ b/src/node_modules/buttons.js @@ -39,7 +39,7 @@ class ButtonMachine { } get stack_top() { - return this.stack[0]; + return this.stack[this.stack.length - 1]; } get cur_op() { @@ -142,14 +142,16 @@ class ButtonMachine { } op_STOR(reg) { - if(!this.assert(!reg.includes(reg), `Register ${reg} is not valid. Use ${ButtonMachine.registers_names()}`)) return; + const reg_names = ButtonMachine.register_names(); + if(!this.assert(reg_names.includes(reg), `Register "${reg}" is not valid. Use ${reg_names}`)) return; this.registers[reg] = this.stack_top; this.next(); } op_RSTOR(reg) { - if(!this.assert(!reg.includes(reg), `Register ${reg} is not valid. Use ${ButtonMachine.registers_names()}`)) return; + const reg_names = ButtonMachine.register_names(); + if(!this.assert(reg_names.includes(reg), `Register "${reg}" is not valid. Use ${reg_names}`)) return; let val = this.registers[reg]; this.assert(val !== undefined, `Invalid register ${reg}`); diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 42e6d55..e3cbea7 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -11,6 +11,7 @@ let code = [ ['PUSH', -10], // start at -10 ['PUSH', 1], // increment by 1 + ['STOR', 'AX'], ['ADD'], ['JZ', 5], // if we're at 0 jumps to the end ['JUMP', 1] // the previous test fails so it jumps to loop again @@ -25,6 +26,7 @@ const data_ops = new Set(['PUSH', 'JZ', 'JNZ', 'JUMP', 'STOR', 'RSTOR', 'HALT']); const ops = ButtonMachine.operations(); + const registers = ButtonMachine.register_names(); const change_op = (i, count) => { let cur_op = code[i][0]; @@ -87,6 +89,16 @@ transition: unset; padding: 5px; } + + #reg-select { + background-color: $gray; + width: 100%; + } + + #reg-select select { + background-color: $gray; + width: 100%; + }
@@ -122,7 +134,15 @@ class="btn btn-primary input-group-btn">{op} {#if op_has_data(op)} - {#if op === 'STOR' || op === 'RSTOR' || op == 'HALT'} + {#if op === 'STOR' || op === 'RSTOR'} +
+ +
+ {:else if op == 'HALT'} {:else} @@ -170,7 +190,7 @@ - {#each machine.stack as datum, i} + {#each [...machine.stack].reverse() as datum, i} {datum}