native flag
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// Hidden vars (os, actorsym, init, core_path, shop_path, json, args) come from env
|
||||
// Engine is self-sufficient: defines its own compilation pipeline
|
||||
var ACTORDATA = actorsym
|
||||
var native_mode = false
|
||||
var SYSYM = '__SYSTEM__'
|
||||
|
||||
var _cell = {}
|
||||
@@ -216,13 +217,24 @@ var _program = null
|
||||
var _user_args = []
|
||||
var _j = 1
|
||||
var _init = init
|
||||
if (args != null && _init == null) {
|
||||
|
||||
// Inherit native_mode from init (set by C for --native, or by parent actor)
|
||||
if (_init != null && _init.native_mode)
|
||||
native_mode = true
|
||||
|
||||
// CLI path: convert args to init record
|
||||
if (args != null && (_init == null || !_init.program)) {
|
||||
_program = args[0]
|
||||
while (_j < length(args)) {
|
||||
push(_user_args, args[_j])
|
||||
_j = _j + 1
|
||||
}
|
||||
_init = {program: _program, arg: _user_args}
|
||||
if (_init == null) {
|
||||
_init = {program: _program, arg: _user_args}
|
||||
} else {
|
||||
_init.program = _program
|
||||
_init.arg = _user_args
|
||||
}
|
||||
}
|
||||
|
||||
use_cache['core/os'] = os
|
||||
@@ -413,9 +425,11 @@ core_extras.content_hash = content_hash
|
||||
core_extras.cache_path = cache_path
|
||||
core_extras.ensure_build_dir = ensure_build_dir
|
||||
core_extras.compile_to_blob = compile_to_blob
|
||||
core_extras.native_mode = native_mode
|
||||
|
||||
// NOW load shop -- it receives all of the above via env
|
||||
var shop = use_core('internal/shop')
|
||||
if (native_mode) use_core('build')
|
||||
var time = use_core('time')
|
||||
|
||||
var pronto = use_core('pronto')
|
||||
@@ -690,6 +704,7 @@ $_.start = function start(cb, program) {
|
||||
overling_id: oid,
|
||||
root_id: root ? root[ACTORDATA].id : null,
|
||||
program,
|
||||
native_mode: native_mode,
|
||||
}
|
||||
greeters[id] = cb
|
||||
push(message_queue, { startup })
|
||||
@@ -1082,6 +1097,28 @@ $_.clock(_ => {
|
||||
env.log = log
|
||||
env = stone(env)
|
||||
|
||||
var native_build = null
|
||||
var native_dylib_path = null
|
||||
var native_handle = null
|
||||
var native_parts = null
|
||||
var native_basename = null
|
||||
var native_sym = null
|
||||
|
||||
// Native execution path: compile to dylib and run
|
||||
if (native_mode) {
|
||||
native_build = use_core('build')
|
||||
native_dylib_path = native_build.compile_native(prog_path, null, null, pkg)
|
||||
native_handle = os.dylib_open(native_dylib_path)
|
||||
native_parts = array(prog_path, '/')
|
||||
native_basename = native_parts[length(native_parts) - 1]
|
||||
native_sym = pkg ? shop.c_symbol_for_file(pkg, native_basename) : null
|
||||
if (native_sym)
|
||||
os.native_module_load_named(native_handle, native_sym, env)
|
||||
else
|
||||
os.native_module_load(native_handle, env)
|
||||
return
|
||||
}
|
||||
|
||||
var source_blob = fd.slurp(prog_path)
|
||||
var hash = content_hash(source_blob)
|
||||
var cached_path = cache_path(hash)
|
||||
|
||||
Reference in New Issue
Block a user