summaryrefslogtreecommitdiff
path: root/os.ts
blob: 32988e224551c1a1d6c4fcb75eb0c4c168e27729 (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
import { ModuleInfo } from "./types";
import { sendMsg } from "./dispatch";
import { main as pb } from "./msg.pb";
import { assert } from "./util";

export function exit(exitCode = 0): void {
  sendMsg("os", {
    command: pb.Msg.Command.EXIT,
    exitCode
  });
}

export function codeFetch(
  moduleSpecifier: string,
  containingFile: string
): ModuleInfo {
  const res = sendMsg("os", {
    command: pb.Msg.Command.CODE_FETCH,
    codeFetchModuleSpecifier: moduleSpecifier,
    codeFetchContainingFile: containingFile
  });
  assert(res.command === pb.Msg.Command.CODE_FETCH_RES);
  return {
    moduleName: res.codeFetchResModuleName,
    filename: res.codeFetchResFilename,
    sourceCode: res.codeFetchResSourceCode,
    outputCode: res.codeFetchResOutputCode
  };
}

export function codeCache(
  filename: string,
  sourceCode: string,
  outputCode: string
): void {
  sendMsg("os", {
    command: pb.Msg.Command.CODE_CACHE,
    codeCacheFilename: filename,
    codeCacheSourceCode: sourceCode,
    codeCacheOutputCode: outputCode
  });
}