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 { AsmToken } from "./scripting/instructions";
import { quest_editor_store } from "./stores/QuestEditorStore";
import { asm_editor_store } from "./stores/AsmEditorStore";
const logger = quest_editor_store.get_logger("quest_editor/QuestRunner");
@ -34,16 +35,20 @@ export class QuestRunner {
}
private execution_loop = (): void => {
this.vm.vsync();
let result: ExecutionResult;
do {
exec_loop:
while (true) {
result = this.vm.execute();
} while (result == ExecutionResult.Ok);
const srcloc = this.vm.get_current_source_location();
if (srcloc && asm_editor_store.breakpoints.val.includes(srcloc.line_no)) {
break exec_loop;
}
switch (result) {
case ExecutionResult.WaitingVsync:
this.vm.vsync();
this.schedule_frame();
break;
case ExecutionResult.WaitingInput:
@ -56,7 +61,8 @@ export class QuestRunner {
this.schedule_frame();
break;
case ExecutionResult.Halted:
break;
break exec_loop;
}
}
};

View File

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