forked from Nivanchenko/OneScriptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneScript.ts
More file actions
38 lines (32 loc) · 1018 Bytes
/
Copy pathOneScript.ts
File metadata and controls
38 lines (32 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { OSCompiler } from "./OneScriptCompiler.js";
import { OSMachine } from "./OneScriptVirtualMachine.js";
import { OSparser } from "./OneScriptParser.js";
export class OneScript {
private parser: OSparser;
private compiler: OSCompiler;
private vm: OSMachine;
constructor(PathToWASMParser = 'tree-sitter-onescript.wasm') {
this.parser = new OSparser(PathToWASMParser);
this.compiler = new OSCompiler();
this.vm = new OSMachine();
}
dumpVariables() {
return this.vm.dumpVariables();
}
async GetTree(source: string) {
return await this.parser.Parse(source);
}
async addSource(source: string) {
const tree = await this.parser.Parse(source);
if (!tree) {
throw Error("Не удалось получить дерево разбора");
}
this.compiler.loadAst(tree.rootNode);
}
async Run(source: string | null = null) {
if (source !== null) {
await this.addSource(source);
}
this.vm.run(this.compiler.GetInstructions());
}
}