Add breakpoints and ack-based comms to worker

This commit is contained in:
Nilay Majorwar
2021-12-15 15:19:44 +05:30
parent c9afb3a68b
commit 29b243d6f2
5 changed files with 87 additions and 32 deletions

View File

@@ -12,6 +12,7 @@ type ExecuteAllArgs<RS> = {
class ExecutionController<RS> {
private _engine: LanguageEngine<RS>;
private _breakpoints: number[] = [];
private _result: StepExecutionResult<RS> | null;
/**
@@ -42,12 +43,20 @@ class ExecutionController<RS> {
this._engine.prepare(code, input);
}
/**
* Update debugging breakpoints
* @param points Array of line numbers having breakpoints
*/
updateBreakpoints(points: number[]) {
this._breakpoints = points;
}
async executeAll({ interval, onResult }: ExecuteAllArgs<RS>) {
while (true) {
this._result = this._engine.executeStep();
onResult && onResult(this._result);
if (!this._result.nextStepLocation) break;
if (interval) await this.sleep(interval);
await this.sleep(interval || 0);
}
return this._result;
}