0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

Simplify naming of CodeFetch, CodeCache

This commit is contained in:
Ryan Dahl 2018-05-25 17:21:06 -04:00
parent a1c0862047
commit cbfb7d8720
4 changed files with 49 additions and 49 deletions

View file

@ -12,9 +12,9 @@ message Msg {
enum Command { enum Command {
ERROR = 0; ERROR = 0;
START = 1; START = 1;
SOURCE_CODE_FETCH = 2; CODE_FETCH = 2;
SOURCE_CODE_FETCH_RES = 3; CODE_FETCH_RES = 3;
SOURCE_CODE_CACHE = 4; CODE_CACHE = 4;
EXIT = 5; EXIT = 5;
TIMER_START = 6; TIMER_START = 6;
TIMER_READY = 7; TIMER_READY = 7;
@ -35,23 +35,23 @@ message Msg {
string start_main_js = 13; // The contents of dist/main.js string start_main_js = 13; // The contents of dist/main.js
string start_main_map = 14; // The contents of dist/main.map string start_main_map = 14; // The contents of dist/main.map
// SOURCE_CODE_FETCH // CODE_FETCH
string source_code_fetch_module_specifier = 20; string code_fetch_module_specifier = 20;
string source_code_fetch_containing_file = 21; string code_fetch_containing_file = 21;
// SOURCE_CODE_FETCH_RES // CODE_FETCH_RES
// If it's a non-http module, moduleName and filename will be the same. // If it's a non-http module, moduleName and filename will be the same.
// For http modules, moduleName is its resolved http URL, and filename // For http modules, moduleName is its resolved http URL, and filename
// is the location of the locally downloaded source code. // is the location of the locally downloaded source code.
string source_code_fetch_res_module_name = 30; string code_fetch_res_module_name = 30;
string source_code_fetch_res_filename = 31; string code_fetch_res_filename = 31;
string source_code_fetch_res_source_code = 32; string code_fetch_res_source_code = 32;
string source_code_fetch_res_output_code = 33; // Non-empty only if cached. string code_fetch_res_output_code = 33; // Non-empty only if cached.
// SOURCE_CODE_CACHE // CODE_CACHE
string source_code_cache_filename = 41; string code_cache_filename = 41;
string source_code_cache_source_code = 42; string code_cache_source_code = 42;
string source_code_cache_output_code = 43; string code_cache_output_code = 43;
// EXIT // EXIT
int32 exit_code = 50; int32 exit_code = 50;

36
os.go
View file

@ -16,15 +16,15 @@ func InitOS() {
msg := &Msg{} msg := &Msg{}
check(proto.Unmarshal(buf, msg)) check(proto.Unmarshal(buf, msg))
switch msg.Command { switch msg.Command {
case Msg_SOURCE_CODE_FETCH: case Msg_CODE_FETCH:
return HandleSourceCodeFetch( return HandleCodeFetch(
msg.SourceCodeFetchModuleSpecifier, msg.CodeFetchModuleSpecifier,
msg.SourceCodeFetchContainingFile) msg.CodeFetchContainingFile)
case Msg_SOURCE_CODE_CACHE: case Msg_CODE_CACHE:
return HandleSourceCodeCache( return HandleCodeCache(
msg.SourceCodeCacheFilename, msg.CodeCacheFilename,
msg.SourceCodeCacheSourceCode, msg.CodeCacheSourceCode,
msg.SourceCodeCacheOutputCode) msg.CodeCacheOutputCode)
case Msg_EXIT: case Msg_EXIT:
os.Exit(int(msg.ExitCode)) os.Exit(int(msg.ExitCode))
default: default:
@ -57,7 +57,7 @@ func ResolveModule(moduleSpecifier string, containingFile string) (
return return
} }
func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out []byte) { func HandleCodeFetch(moduleSpecifier string, containingFile string) (out []byte) {
assert(moduleSpecifier != "", "moduleSpecifier shouldn't be empty") assert(moduleSpecifier != "", "moduleSpecifier shouldn't be empty")
res := &Msg{} res := &Msg{}
var sourceCodeBuf []byte var sourceCodeBuf []byte
@ -76,7 +76,7 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
return return
} }
//println("HandleSourceCodeFetch", "moduleSpecifier", moduleSpecifier, //println("HandleCodeFetch", "moduleSpecifier", moduleSpecifier,
// "containingFile", containingFile, "filename", filename) // "containingFile", containingFile, "filename", filename)
if isRemote(moduleName) { if isRemote(moduleName) {
@ -99,18 +99,18 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
} }
var sourceCode = string(sourceCodeBuf) var sourceCode = string(sourceCodeBuf)
var command = Msg_SOURCE_CODE_FETCH_RES var command = Msg_CODE_FETCH_RES
res = &Msg{ res = &Msg{
Command: command, Command: command,
SourceCodeFetchResModuleName: moduleName, CodeFetchResModuleName: moduleName,
SourceCodeFetchResFilename: filename, CodeFetchResFilename: filename,
SourceCodeFetchResSourceCode: sourceCode, CodeFetchResSourceCode: sourceCode,
SourceCodeFetchResOutputCode: outputCode, CodeFetchResOutputCode: outputCode,
} }
return return
} }
func HandleSourceCodeCache(filename string, sourceCode string, func HandleCodeCache(filename string, sourceCode string,
outputCode string) []byte { outputCode string) []byte {
fn := CacheFileName(filename, []byte(sourceCode)) fn := CacheFileName(filename, []byte(sourceCode))

28
os.ts
View file

@ -10,33 +10,33 @@ export function exit(exitCode = 0): void {
}); });
} }
export function sourceCodeFetch( export function codeFetch(
moduleSpecifier: string, moduleSpecifier: string,
containingFile: string containingFile: string
): ModuleInfo { ): ModuleInfo {
const res = sendMsg("os", { const res = sendMsg("os", {
command: pb.Msg.Command.SOURCE_CODE_FETCH, command: pb.Msg.Command.CODE_FETCH,
sourceCodeFetchModuleSpecifier: moduleSpecifier, codeFetchModuleSpecifier: moduleSpecifier,
sourceCodeFetchContainingFile: containingFile codeFetchContainingFile: containingFile
}); });
assert(res.command === pb.Msg.Command.SOURCE_CODE_FETCH_RES); assert(res.command === pb.Msg.Command.CODE_FETCH_RES);
return { return {
moduleName: res.sourceCodeFetchResModuleName, moduleName: res.codeFetchResModuleName,
filename: res.sourceCodeFetchResFilename, filename: res.codeFetchResFilename,
sourceCode: res.sourceCodeFetchResSourceCode, sourceCode: res.codeFetchResSourceCode,
outputCode: res.sourceCodeFetchResOutputCode outputCode: res.codeFetchResOutputCode
}; };
} }
export function sourceCodeCache( export function codeCache(
filename: string, filename: string,
sourceCode: string, sourceCode: string,
outputCode: string outputCode: string
): void { ): void {
sendMsg("os", { sendMsg("os", {
command: pb.Msg.Command.SOURCE_CODE_CACHE, command: pb.Msg.Command.CODE_CACHE,
sourceCodeCacheFilename: filename, codeCacheFilename: filename,
sourceCodeCacheSourceCode: sourceCode, codeCacheSourceCode: sourceCode,
sourceCodeCacheOutputCode: outputCode codeCacheOutputCode: outputCode
}); });
} }

View file

@ -72,7 +72,7 @@ export class FileModule {
); );
const compiler = Compiler.instance(); const compiler = Compiler.instance();
this.outputCode = compiler.compile(this.fileName); this.outputCode = compiler.compile(this.fileName);
os.sourceCodeCache(this.fileName, this.sourceCode, this.outputCode); os.codeCache(this.fileName, this.sourceCode, this.outputCode);
} }
util.log("compileAndRun", this.sourceCode); util.log("compileAndRun", this.sourceCode);
execute(this.fileName, this.outputCode); execute(this.fileName, this.outputCode);
@ -129,7 +129,7 @@ export function resolveModule(
util.assert(moduleSpecifier != null && moduleSpecifier.length > 0); util.assert(moduleSpecifier != null && moduleSpecifier.length > 0);
// We ask golang to sourceCodeFetch. It will load the sourceCode and if // We ask golang to sourceCodeFetch. It will load the sourceCode and if
// there is any outputCode cached, it will return that as well. // there is any outputCode cached, it will return that as well.
const { filename, sourceCode, outputCode } = os.sourceCodeFetch( const { filename, sourceCode, outputCode } = os.codeFetch(
moduleSpecifier, moduleSpecifier,
containingFile containingFile
); );