diff --git a/compiler/lowerer.ts b/compiler/lowerer.ts index 53a4077..dde41e2 100644 --- a/compiler/lowerer.ts +++ b/compiler/lowerer.ts @@ -432,10 +432,6 @@ export class Lowerer { this.locals = new LocalLeaf(this.locals); this.scoutFnHeaders(expr.kind.stmts); for (const stmt of expr.kind.stmts) { - console.log(`sm for stmt ${stmt.kind.type} ${stmt.pos.line}`); - if (stmt.kind.type === "assign") { - console.log(` - ${stmtToString(stmt)}`); - } this.addSourceMap(stmt.pos); this.lowerStmt(stmt); } diff --git a/runtime/Makefile b/runtime/Makefile index c4e80d3..99a1669 100644 --- a/runtime/Makefile +++ b/runtime/Makefile @@ -20,6 +20,7 @@ all: build_dir $(OUT) $(OUT): $(CXX_OBJECTS) $(CXX) -o $@ $(CXX_FLAGS) $^ + git rev-parse HEAD > build/rev build_dir: mkdir -p build/ diff --git a/web/main.ts b/web/main.ts index 9a07548..e2eb0f6 100644 --- a/web/main.ts +++ b/web/main.ts @@ -17,6 +17,7 @@ const filepath = flags._[0] as string; const text = await Deno.readTextFile(filepath); const runtime = new Runtime(13370); +await runtime.start(); async function compileProgram(filepath: string) { const result = await compiler.compileWithDebug(filepath); diff --git a/web/runtime.ts b/web/runtime.ts index 2970d7d..b80e931 100644 --- a/web/runtime.ts +++ b/web/runtime.ts @@ -1,12 +1,49 @@ export class Runtime { + private runtimeProcess?: Deno.ChildProcess; + constructor(private port: number) {} + async checkRuntimeRev() { + const currentRev = new TextDecoder().decode( + await new Deno.Command("git", { args: ["rev-parse", "HEAD"] }) + .output() + .then((output) => output.stdout), + ).trim(); + const runtimeRev = (await Deno.readTextFile("../runtime/build/rev")) + .trim(); + if (runtimeRev !== currentRev) { + console.error( + "runtime out-of-date; run 'make' inside runtime/ folder", + ); + Deno.exit(1); + } + } + + async start() { + await this.checkRuntimeRev(); + this.runtimeProcess = new Deno.Command("../runtime/build/sliger", { + args: [], + stdout: "piped", + }).spawn(); + } + + stop() { + this.runtimeProcess?.kill(); + this.runtimeProcess = undefined; + } + async connect(): Promise { - return new RuntimeConnection( - await Deno.connect({ - port: this.port, - }), - ); + return await new Promise((resolve) => { + setTimeout(async () => { + resolve( + new RuntimeConnection( + await Deno.connect({ + port: this.port, + }), + ), + ); + }, 1000); + }); } }