diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-17 09:47:09 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-17 21:19:49 -0400 |
commit | 05672b7e240f8568c1f58eb074623aede20f13d1 (patch) | |
tree | d639abc21b20ac1ac59ecb65b681a2cdbe5a8784 /os.ts | |
parent | 6f9c919f410c7d97f99515ea99c8dcc434d5d26d (diff) |
runtime.ts - first pass at caching compiler
Diffstat (limited to 'os.ts')
-rw-r--r-- | os.ts | 37 |
1 files changed, 29 insertions, 8 deletions
@@ -11,11 +11,27 @@ export function exit(code = 0): void { }); } -export function compileOutput(source: string, filename: string): void { - sendMsgFromObject({ - kind: pb.Msg.MsgKind.COMPILE_OUTPUT, - compileOutput: { source, filename } +export function sourceCodeFetch( + filename: string +): { sourceCode: string; outputCode: string } { + const res = sendMsgFromObject({ + kind: pb.Msg.MsgKind.SOURCE_CODE_FETCH, + sourceCodeFetch: { filename } + }); + const { sourceCode, outputCode } = res.sourceCodeFetchRes; + return { sourceCode, outputCode }; +} + +export function sourceCodeCache( + filename: string, + sourceCode: string, + outputCode: string +): void { + const res = sendMsgFromObject({ + kind: pb.Msg.MsgKind.SOURCE_CODE_CACHE, + sourceCodeCache: { filename, sourceCode, outputCode } }); + throwOnError(res); } export function readFileSync(filename: string): string { @@ -23,9 +39,6 @@ export function readFileSync(filename: string): string { kind: pb.Msg.MsgKind.READ_FILE_SYNC, path: filename }); - if (res.error != null && res.error.length > 0) { - throw Error(res.error); - } const decoder = new TextDecoder("utf8"); return decoder.decode(res.data); } @@ -41,8 +54,16 @@ function sendMsgFromObject(obj: pb.IMsg): null | pb.Msg { const ab = typedArrayToArrayBuffer(ui8); const resBuf = V8Worker2.send(ab); if (resBuf != null && resBuf.byteLength > 0) { - return pb.Msg.decode(new Uint8Array(resBuf)); + const res = pb.Msg.decode(new Uint8Array(resBuf)); + throwOnError(res); + return res; } else { return null; } } + +function throwOnError(res: pb.Msg) { + if (res != null && res.error != null && res.error.length > 0) { + throw Error(res.error); + } +} |