correct syntax errors in core scripts
This commit is contained in:
@@ -70,6 +70,7 @@ function use_core(path) {
|
||||
var ast = null
|
||||
var mcode_path = null
|
||||
var mcode_blob = null
|
||||
var _load_mod = null
|
||||
|
||||
// Build env: merge core_extras
|
||||
env = {use: use_core}
|
||||
@@ -79,45 +80,58 @@ function use_core(path) {
|
||||
var cached_path = null
|
||||
var mach_blob = null
|
||||
var source_blob = null
|
||||
var file_path = null
|
||||
|
||||
// Check for pre-compiled .cm.mcode JSON IR (generated by regen)
|
||||
mcode_path = core_path + '/boot/' + replace(path, '/', '_') + '.cm.mcode'
|
||||
if (fd.is_file(mcode_path)) {
|
||||
mcode_blob = fd.slurp(mcode_path)
|
||||
hash = content_hash(mcode_blob)
|
||||
cached_path = cache_path(hash)
|
||||
if (cached_path && fd.is_file(cached_path)) {
|
||||
result = mach_load(fd.slurp(cached_path), env)
|
||||
} else {
|
||||
mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob))
|
||||
if (cached_path) {
|
||||
ensure_build_dir()
|
||||
fd.slurpwrite(cached_path, mach_blob)
|
||||
_load_mod = function() {
|
||||
mcode_blob = fd.slurp(mcode_path)
|
||||
hash = content_hash(mcode_blob)
|
||||
cached_path = cache_path(hash)
|
||||
if (cached_path && fd.is_file(cached_path)) {
|
||||
result = mach_load(fd.slurp(cached_path), env)
|
||||
} else {
|
||||
mach_blob = mach_compile_mcode_bin('core:' + path, text(mcode_blob))
|
||||
if (cached_path) {
|
||||
ensure_build_dir()
|
||||
fd.slurpwrite(cached_path, mach_blob)
|
||||
}
|
||||
result = mach_load(mach_blob, env)
|
||||
}
|
||||
result = mach_load(mach_blob, env)
|
||||
} disruption {
|
||||
print("use('" + path + "'): failed to load from " + mcode_path + "\n")
|
||||
disrupt
|
||||
}
|
||||
_load_mod()
|
||||
use_cache[cache_key] = result
|
||||
return result
|
||||
}
|
||||
|
||||
// Compile from source .cm file
|
||||
var file_path = core_path + '/' + path + MOD_EXT
|
||||
file_path = core_path + '/' + path + MOD_EXT
|
||||
if (fd.is_file(file_path)) {
|
||||
source_blob = fd.slurp(file_path)
|
||||
hash = content_hash(source_blob)
|
||||
cached_path = cache_path(hash)
|
||||
if (cached_path && fd.is_file(cached_path)) {
|
||||
result = mach_load(fd.slurp(cached_path), env)
|
||||
} else {
|
||||
script = text(source_blob)
|
||||
ast = analyze(script, file_path)
|
||||
mach_blob = compile_to_blob_fn('core:' + path, ast)
|
||||
if (cached_path) {
|
||||
ensure_build_dir()
|
||||
fd.slurpwrite(cached_path, mach_blob)
|
||||
_load_mod = function() {
|
||||
source_blob = fd.slurp(file_path)
|
||||
hash = content_hash(source_blob)
|
||||
cached_path = cache_path(hash)
|
||||
if (cached_path && fd.is_file(cached_path)) {
|
||||
result = mach_load(fd.slurp(cached_path), env)
|
||||
} else {
|
||||
script = text(source_blob)
|
||||
ast = analyze(script, file_path)
|
||||
mach_blob = compile_to_blob_fn('core:' + path, ast)
|
||||
if (cached_path) {
|
||||
ensure_build_dir()
|
||||
fd.slurpwrite(cached_path, mach_blob)
|
||||
}
|
||||
result = mach_load(mach_blob, env)
|
||||
}
|
||||
result = mach_load(mach_blob, env)
|
||||
} disruption {
|
||||
print("use('" + path + "'): failed to compile or load " + file_path + "\n")
|
||||
disrupt
|
||||
}
|
||||
_load_mod()
|
||||
use_cache[cache_key] = result
|
||||
return result
|
||||
}
|
||||
@@ -238,6 +252,7 @@ var runtime_env = {}
|
||||
|
||||
// Populate core_extras with everything shop (and other core modules) need
|
||||
core_extras.use_cache = use_cache
|
||||
core_extras.core_path = core_path
|
||||
core_extras.shop_path = shop_path
|
||||
core_extras.analyze = analyze
|
||||
core_extras.run_ast_fn = run_ast_fn
|
||||
|
||||
Reference in New Issue
Block a user