diff options
author | Austin Adams <git@austinjadams.com> | 2020-06-03 22:17:00 -0700 |
---|---|---|
committer | Austin Adams <git@austinjadams.com> | 2020-06-03 22:17:00 -0700 |
commit | f20db296461976de41d0ca97696a5f49a77990ba (patch) | |
tree | d64eb94a74442fc9711b7bd6d4d813ea51300949 | |
parent | 6493957f568b7a18898080e41d11ffb524fb8758 (diff) | |
download | novice-f20db296461976de41d0ca97696a5f49a77990ba.tar.gz novice-f20db296461976de41d0ca97696a5f49a77990ba.tar.xz |
Pretend to get "stuck" on halts
4 files changed, 24 insertions, 2 deletions
diff --git a/packages/novice-web/novice-web/components/GuiDebugger.tsx b/packages/novice-web/novice-web/components/GuiDebugger.tsx index baa62f2..f34f480 100644 --- a/packages/novice-web/novice-web/components/GuiDebugger.tsx +++ b/packages/novice-web/novice-web/components/GuiDebugger.tsx @@ -59,6 +59,10 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps, } public render() { + // Be a little dishonest: to avoid confusing users, get 'stuck' on halts + const pc = this.state.state.halted ? this.state.state.pc - this.isa.spec.pc.increment + : this.state.state.pc; + const registers = this.isa.spec.regs.map(reg => { let values; @@ -80,7 +84,7 @@ export class GuiDebugger extends React.Component<GuiDebuggerProps, const rowHeight = 20; const cols = [20, 80, 80, 80, 200]; const colVal: ((addr: number) => string)[] = [ - addr => (this.state.state.pc === addr) ? '►' : '', + addr => (pc === addr) ? '►' : '', addr => this.fmtAddr(addr), addr => this.fmtWord(this.isa.stateLoad(this.state.state, addr)), addr => this.isa.stateLoad(this.state.state, addr).toString(10), diff --git a/packages/novice-web/novice-web/index.tsx b/packages/novice-web/novice-web/index.tsx index 213b51f..6de52cd 100644 --- a/packages/novice-web/novice-web/index.tsx +++ b/packages/novice-web/novice-web/index.tsx @@ -8,7 +8,7 @@ const ASSEMBLER_WORKER_BUNDLE_URL = 'dist/assemblerWorker.bundle.js'; ReactDOM.render( <GuiDebugger isaName='lc3' - initialAssemblyCode={'; write LC-3 assembly code here\n'} + initialAssemblyCode={'.orig x3000\n; write LC-3 assembly code here\n\nhalt\n.end\n'} debuggerWorkerBundleUrl={DEBUGGER_WORKER_BUNDLE_URL} assemblerWorkerBundleUrl={ASSEMBLER_WORKER_BUNDLE_URL} />, document.getElementById('root'), diff --git a/packages/novice-web/novice-web/workers/debugger/debugger-worker.ts b/packages/novice-web/novice-web/workers/debugger/debugger-worker.ts index 90934cb..df12bdb 100644 --- a/packages/novice-web/novice-web/workers/debugger/debugger-worker.ts +++ b/packages/novice-web/novice-web/workers/debugger/debugger-worker.ts @@ -57,6 +57,20 @@ class DebuggerWorker extends BaseWorker<DebuggerFrontendMessage, throw new Error('must reset before unstepping'); } + // Maintain the lie that the debugger "freezes" on a halt by + // double-unstepping on halts. Without this, after executing a + // halt, it seems like nothing happened. + // + // We do this here instead of the frontend in case the + // frontend batches up n unstep requests while sitting + // on a halt before getting any machine state updates + // from the debugger worker. In such a case, if we did + // this check in the frontend, we would send 2n unstep + // requests instead of correctly sending n + 1. + if (this.dbg.isHalted() && this.dbg.getLogLength() > 1) { + this.dbg.unstep(); + } + this.dbg.unstep(); break; diff --git a/packages/novice/novice/simulator/simulator.ts b/packages/novice/novice/simulator/simulator.ts index f0620bf..3e21a80 100644 --- a/packages/novice/novice/simulator/simulator.ts +++ b/packages/novice/novice/simulator/simulator.ts @@ -29,6 +29,10 @@ class Simulator implements Memory { public getNumExec() { return this.numExec; } + public getLogLength(): number { + return this.log.length; + } + public loadSections(sections: MachineCodeSection[]): void { const updates: MachineStateUpdate[] = []; |