summaryrefslogtreecommitdiff
path: root/main.ts
blob: 28c1ecdff20baf5522be09cb7f6d236ac85a2d49 (plain)
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
39
40
41
42
43
44
45
46
47
import { main as pb } from "./msg.pb";
import "./util";
import * as runtime from "./runtime";
import * as timers from "./timers";
import * as util from "./util";

// To control internal logging output
// Set with the -debug command-line flag.
export let debug = false;

function start(
  cwd: string,
  argv: string[],
  debugFlag: boolean,
  mainJs: string,
  mainMap: string
): void {
  debug = debugFlag;
  util.log("start", { cwd, argv, debugFlag });

  runtime.setup(mainJs, mainMap);

  const inputFn = argv[0];
  const mod = runtime.resolveModule(inputFn, cwd + "/");
  mod.compileAndRun();
}

V8Worker2.recv((ab: ArrayBuffer) => {
  const msg = pb.Msg.decode(new Uint8Array(ab));
  switch (msg.payload) {
    case "start":
      start(
        msg.start.cwd,
        msg.start.argv,
        msg.start.debugFlag,
        msg.start.mainJs,
        msg.start.mainMap
      );
      break;
    case "timerReady":
      timers.timerReady(msg.timerReady.id, msg.timerReady.done);
      break;
    default:
      console.log("Unknown message", msg);
      break;
  }
});