1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -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 {
ERROR = 0;
START = 1;
SOURCE_CODE_FETCH = 2;
SOURCE_CODE_FETCH_RES = 3;
SOURCE_CODE_CACHE = 4;
CODE_FETCH = 2;
CODE_FETCH_RES = 3;
CODE_CACHE = 4;
EXIT = 5;
TIMER_START = 6;
TIMER_READY = 7;
@ -35,23 +35,23 @@ message Msg {
string start_main_js = 13; // The contents of dist/main.js
string start_main_map = 14; // The contents of dist/main.map
// SOURCE_CODE_FETCH
string source_code_fetch_module_specifier = 20;
string source_code_fetch_containing_file = 21;
// CODE_FETCH
string code_fetch_module_specifier = 20;
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.
// For http modules, moduleName is its resolved http URL, and filename
// is the location of the locally downloaded source code.
string source_code_fetch_res_module_name = 30;
string source_code_fetch_res_filename = 31;
string source_code_fetch_res_source_code = 32;
string source_code_fetch_res_output_code = 33; // Non-empty only if cached.
string code_fetch_res_module_name = 30;
string code_fetch_res_filename = 31;
string code_fetch_res_source_code = 32;
string code_fetch_res_output_code = 33; // Non-empty only if cached.
// SOURCE_CODE_CACHE
string source_code_cache_filename = 41;
string source_code_cache_source_code = 42;
string source_code_cache_output_code = 43;
// CODE_CACHE
string code_cache_filename = 41;
string code_cache_source_code = 42;
string code_cache_output_code = 43;
// EXIT
int32 exit_code = 50;

36
os.go
View file

@ -16,15 +16,15 @@ func InitOS() {
msg := &Msg{}
check(proto.Unmarshal(buf, msg))
switch msg.Command {
case Msg_SOURCE_CODE_FETCH:
return HandleSourceCodeFetch(
msg.SourceCodeFetchModuleSpecifier,
msg.SourceCodeFetchContainingFile)
case Msg_SOURCE_CODE_CACHE:
return HandleSourceCodeCache(
msg.SourceCodeCacheFilename,
msg.SourceCodeCacheSourceCode,
msg.SourceCodeCacheOutputCode)
case Msg_CODE_FETCH:
return HandleCodeFetch(
msg.CodeFetchModuleSpecifier,
msg.CodeFetchContainingFile)
case Msg_CODE_CACHE:
return HandleCodeCache(
msg.CodeCacheFilename,
msg.CodeCacheSourceCode,
msg.CodeCacheOutputCode)
case Msg_EXIT:
os.Exit(int(msg.ExitCode))
default:
@ -57,7 +57,7 @@ func ResolveModule(moduleSpecifier string, containingFile string) (
return
}
func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out []byte) {
func HandleCodeFetch(moduleSpecifier string, containingFile string) (out []byte) {
assert(moduleSpecifier != "", "moduleSpecifier shouldn't be empty")
res := &Msg{}
var sourceCodeBuf []byte
@ -76,7 +76,7 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
return
}
//println("HandleSourceCodeFetch", "moduleSpecifier", moduleSpecifier,
//println("HandleCodeFetch", "moduleSpecifier", moduleSpecifier,
// "containingFile", containingFile, "filename", filename)
if isRemote(moduleName) {
@ -99,18 +99,18 @@ func HandleSourceCodeFetch(moduleSpecifier string, containingFile string) (out [
}
var sourceCode = string(sourceCodeBuf)
var command = Msg_SOURCE_CODE_FETCH_RES
var command = Msg_CODE_FETCH_RES
res = &Msg{
Command: command,
SourceCodeFetchResModuleName: moduleName,
SourceCodeFetchResFilename: filename,
SourceCodeFetchResSourceCode: sourceCode,
SourceCodeFetchResOutputCode: outputCode,
Command: command,
CodeFetchResModuleName: moduleName,
CodeFetchResFilename: filename,
CodeFetchResSourceCode: sourceCode,
CodeFetchResOutputCode: outputCode,
}
return
}
func HandleSourceCodeCache(filename string, sourceCode string,
func HandleCodeCache(filename string, sourceCode string,
outputCode string) []byte {
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,
containingFile: string
): ModuleInfo {
const res = sendMsg("os", {
command: pb.Msg.Command.SOURCE_CODE_FETCH,
sourceCodeFetchModuleSpecifier: moduleSpecifier,
sourceCodeFetchContainingFile: containingFile
command: pb.Msg.Command.CODE_FETCH,
codeFetchModuleSpecifier: moduleSpecifier,
codeFetchContainingFile: containingFile
});
assert(res.command === pb.Msg.Command.SOURCE_CODE_FETCH_RES);
assert(res.command === pb.Msg.Command.CODE_FETCH_RES);
return {
moduleName: res.sourceCodeFetchResModuleName,
filename: res.sourceCodeFetchResFilename,
sourceCode: res.sourceCodeFetchResSourceCode,
outputCode: res.sourceCodeFetchResOutputCode
moduleName: res.codeFetchResModuleName,
filename: res.codeFetchResFilename,
sourceCode: res.codeFetchResSourceCode,
outputCode: res.codeFetchResOutputCode
};
}
export function sourceCodeCache(
export function codeCache(
filename: string,
sourceCode: string,
outputCode: string
): void {
sendMsg("os", {
command: pb.Msg.Command.SOURCE_CODE_CACHE,
sourceCodeCacheFilename: filename,
sourceCodeCacheSourceCode: sourceCode,
sourceCodeCacheOutputCode: outputCode
command: pb.Msg.Command.CODE_CACHE,
codeCacheFilename: filename,
codeCacheSourceCode: sourceCode,
codeCacheOutputCode: outputCode
});
}

View file

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