Skip to content

Commit 8d7efdd

Browse files
committed
Add runner
1 parent 98aa96b commit 8d7efdd

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Editor } from "./editor/index.js";
22
import { Interpreter } from "./interpreter/index.js";
3+
import { Runner } from "./runner/index.js";
34
import { UI } from "./ui/index.js";
45

56
const C4C = {
67
Editor: Editor,
78
Interpreter: Interpreter,
9+
Runner: Runner,
810
UI: UI,
911
};
1012

src/interpreter/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ const Interpreter = {
6565
stepRunInNamespace: stepRunInNamespace,
6666
};
6767

68-
export { Interpreter };
68+
export { Interpreter, stepRun };

src/runner/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ProgramRunner } from "./runner.js";
2+
3+
function createRunner() {
4+
return new ProgramRunner();
5+
}
6+
7+
const Runner = {
8+
createRunner: createRunner,
9+
};
10+
11+
export { Runner };

src/runner/runner.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// import Phaser from "phaser";
2+
import { stepRun } from "../interpreter/index.js";
3+
4+
class ProgramRunner {
5+
constructor(config) {
6+
this.programText = "";
7+
this.location = [];
8+
this.result = null;
9+
}
10+
11+
setProgram(t) {
12+
this.programText = t;
13+
}
14+
15+
reset() {
16+
this.location = [];
17+
}
18+
19+
step() {
20+
let [result, loc] = stepRun(this.programText, this.location);
21+
this.result = result;
22+
this.location = loc;
23+
}
24+
}
25+
26+
export { ProgramRunner };

0 commit comments

Comments
 (0)