Breakpoints now cause VM to pause.

This commit is contained in:
jtuu 2019-11-14 00:31:20 +02:00
parent 144e9513ac
commit 90ad66e96d
2 changed files with 37 additions and 20 deletions

View File

@ -3,6 +3,7 @@ import { QuestModel } from "./model/QuestModel";
import { VirtualMachineIO } from "./scripting/vm/io"; import { VirtualMachineIO } from "./scripting/vm/io";
import { AsmToken } from "./scripting/instructions"; import { AsmToken } from "./scripting/instructions";
import { quest_editor_store } from "./stores/QuestEditorStore"; import { quest_editor_store } from "./stores/QuestEditorStore";
import { asm_editor_store } from "./stores/AsmEditorStore";
const logger = quest_editor_store.get_logger("quest_editor/QuestRunner"); const logger = quest_editor_store.get_logger("quest_editor/QuestRunner");
@ -34,29 +35,34 @@ export class QuestRunner {
} }
private execution_loop = (): void => { private execution_loop = (): void => {
this.vm.vsync();
let result: ExecutionResult; let result: ExecutionResult;
do { exec_loop:
while (true) {
result = this.vm.execute(); result = this.vm.execute();
} while (result == ExecutionResult.Ok);
switch (result) { const srcloc = this.vm.get_current_source_location();
case ExecutionResult.WaitingVsync: if (srcloc && asm_editor_store.breakpoints.val.includes(srcloc.line_no)) {
this.schedule_frame(); break exec_loop;
break; }
case ExecutionResult.WaitingInput:
// TODO: implement input from gui switch (result) {
this.schedule_frame(); case ExecutionResult.WaitingVsync:
break; this.vm.vsync();
case ExecutionResult.WaitingSelection: this.schedule_frame();
// TODO: implement input from gui break;
this.vm.list_select(0); case ExecutionResult.WaitingInput:
this.schedule_frame(); // TODO: implement input from gui
break; this.schedule_frame();
case ExecutionResult.Halted: break;
break; case ExecutionResult.WaitingSelection:
// TODO: implement input from gui
this.vm.list_select(0);
this.schedule_frame();
break;
case ExecutionResult.Halted:
break exec_loop;
}
} }
}; };

View File

@ -158,6 +158,7 @@ export class VirtualMachine {
private set_episode_called = false; private set_episode_called = false;
private list_open = false; private list_open = false;
private selection_reg = 0; private selection_reg = 0;
private cur_srcloc?: AsmToken;
constructor(private io: VirtualMachineIO = new VMIOStub()) { constructor(private io: VirtualMachineIO = new VMIOStub()) {
srand(GetTickCount()); srand(GetTickCount());
@ -187,6 +188,7 @@ export class VirtualMachine {
this.set_episode_called = false; this.set_episode_called = false;
this.list_open = false; this.list_open = false;
this.selection_reg = 0; this.selection_reg = 0;
this.cur_srcloc = undefined;
let i = 0; let i = 0;
@ -239,7 +241,10 @@ export class VirtualMachine {
execute(): ExecutionResult { execute(): ExecutionResult {
let srcloc: AsmToken | undefined; let srcloc: AsmToken | undefined;
if (this.thread.length === 0) return ExecutionResult.Halted; if (this.thread.length === 0) {
this.cur_srcloc = undefined;
return ExecutionResult.Halted
}
try { try {
const exec = this.thread[this.thread_idx]; const exec = this.thread[this.thread_idx];
@ -249,6 +254,8 @@ export class VirtualMachine {
srcloc = inst.asm.mnemonic; srcloc = inst.asm.mnemonic;
} }
this.cur_srcloc = srcloc;
return this.execute_instruction(exec, inst, srcloc); return this.execute_instruction(exec, inst, srcloc);
} catch (err) { } catch (err) {
if (!(err instanceof Error)) { if (!(err instanceof Error)) {
@ -1141,6 +1148,10 @@ export class VirtualMachine {
return template; return template;
} }
public get_current_source_location(): AsmToken | undefined {
return this.cur_srcloc;
}
} }
class ExecutionLocation { class ExecutionLocation {