Merge branch 'mcode2' into pitweb
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// Hidden vars come from env:
|
||||
// CLI mode (cell_init): os, args, shop_path, use_mcode
|
||||
// Actor spawn (script_startup): os, json, nota, wota, actorsym, init, shop_path
|
||||
var core_path = shop_path + '/packages/core'
|
||||
// CLI mode (cell_init): os, args, core_path, shop_path, use_mcode
|
||||
// Actor spawn (script_startup): os, json, nota, wota, actorsym, init, core_path, shop_path
|
||||
// args[0] = script name, args[1..] = user args
|
||||
var load_internal = os.load_internal
|
||||
function use_embed(name) {
|
||||
@@ -160,7 +159,7 @@ if (args != null) {
|
||||
// Actor spawn mode — load engine.cm with full actor env
|
||||
load_engine({
|
||||
os: os, actorsym: actorsym, init: init,
|
||||
shop_path: shop_path, json: json, nota: nota, wota: wota,
|
||||
core_path: core_path, shop_path: shop_path, json: json, nota: nota, wota: wota,
|
||||
analyze: analyze, run_ast_fn: run_ast
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Hidden vars (os, actorsym, init, shop_path, analyze, run_ast_fn, json) come from env
|
||||
// Hidden vars (os, actorsym, init, core_path, shop_path, analyze, run_ast_fn, json) come from env
|
||||
// In actor spawn mode, also: nota, wota
|
||||
var ACTORDATA = actorsym
|
||||
var SYSYM = '__SYSTEM__'
|
||||
@@ -53,9 +53,9 @@ function ends_with(str, suffix) {
|
||||
var fd = use_embed('fd')
|
||||
var js = use_embed('js')
|
||||
|
||||
// shop_path comes from env (bootstrap.cm passes it through)
|
||||
var packages_path = shop_path + '/packages'
|
||||
var core_path = packages_path + '/core'
|
||||
// core_path and shop_path come from env (bootstrap.cm passes them through)
|
||||
// shop_path may be null if --core was used without --shop
|
||||
var packages_path = shop_path ? shop_path + '/packages' : null
|
||||
|
||||
var use_cache = {}
|
||||
use_cache['core/os'] = os
|
||||
|
||||
@@ -40,52 +40,57 @@ static const char* get_home_dir(void) {
|
||||
return home;
|
||||
}
|
||||
|
||||
// Find and verify the cell shop
|
||||
// Precedence: override (--shop flag) > CELL_SHOP env var > ~/.cell
|
||||
int find_cell_shop(const char *override_path)
|
||||
// Resolve shop_path and core_path
|
||||
// core: --core flag > CELL_CORE env > derived from shop
|
||||
// shop: --shop flag > CELL_SHOP env > ~/.cell
|
||||
int find_cell_shop(const char *shop_override, const char *core_override)
|
||||
{
|
||||
if (override_path) {
|
||||
shop_path = strdup(override_path);
|
||||
// Resolve shop_path
|
||||
if (shop_override) {
|
||||
shop_path = strdup(shop_override);
|
||||
} else {
|
||||
const char *env = getenv("CELL_SHOP");
|
||||
if (env) {
|
||||
shop_path = strdup(env);
|
||||
} else {
|
||||
const char *home = get_home_dir();
|
||||
if (!home) {
|
||||
if (!home && !core_override && !getenv("CELL_CORE")) {
|
||||
printf("ERROR: Could not determine home directory. Set HOME environment variable.\n");
|
||||
return 0;
|
||||
}
|
||||
size_t path_len = strlen(home) + strlen("/" CELL_SHOP_DIR) + 1;
|
||||
shop_path = malloc(path_len);
|
||||
if (!shop_path) {
|
||||
printf("ERROR: Could not allocate memory for shop path\n");
|
||||
return 0;
|
||||
if (home) {
|
||||
size_t path_len = strlen(home) + strlen("/" CELL_SHOP_DIR) + 1;
|
||||
shop_path = malloc(path_len);
|
||||
if (shop_path)
|
||||
snprintf(shop_path, path_len, "%s/" CELL_SHOP_DIR, home);
|
||||
}
|
||||
snprintf(shop_path, path_len, "%s/" CELL_SHOP_DIR, home);
|
||||
}
|
||||
}
|
||||
|
||||
// Derive core_path from shop_path
|
||||
size_t core_len = strlen(shop_path) + strlen("/" CELL_CORE_DIR) + 1;
|
||||
core_path = malloc(core_len);
|
||||
// Resolve core_path
|
||||
if (core_override) {
|
||||
core_path = strdup(core_override);
|
||||
} else {
|
||||
const char *env = getenv("CELL_CORE");
|
||||
if (env) {
|
||||
core_path = strdup(env);
|
||||
} else if (shop_path) {
|
||||
size_t core_len = strlen(shop_path) + strlen("/" CELL_CORE_DIR) + 1;
|
||||
core_path = malloc(core_len);
|
||||
if (core_path)
|
||||
snprintf(core_path, core_len, "%s/" CELL_CORE_DIR, shop_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!core_path) {
|
||||
printf("ERROR: Could not allocate memory for core path\n");
|
||||
free(shop_path);
|
||||
shop_path = NULL;
|
||||
printf("ERROR: No core path. Use --core <path> or set CELL_CORE.\n");
|
||||
return 0;
|
||||
}
|
||||
snprintf(core_path, core_len, "%s/" CELL_CORE_DIR, shop_path);
|
||||
|
||||
// Check if the core directory exists
|
||||
struct stat st;
|
||||
if (stat(core_path, &st) != 0 || !S_ISDIR(st.st_mode)) {
|
||||
printf("ERROR: Cell shop not found at %s\n", shop_path);
|
||||
printf("Run 'cell install' to set up the cell environment.\n");
|
||||
free(core_path);
|
||||
free(shop_path);
|
||||
core_path = NULL;
|
||||
shop_path = NULL;
|
||||
printf("ERROR: Core not found at %s\n", core_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -210,9 +215,10 @@ void script_startup(cell_rt *prt)
|
||||
JS_SetPropertyStr(js, hidden_env, "args", JS_NULL);
|
||||
JS_SetPropertyStr(js, hidden_env, "use_mcode", JS_NewBool(js, 0));
|
||||
|
||||
if (shop_path) {
|
||||
if (core_path)
|
||||
JS_SetPropertyStr(js, hidden_env, "core_path", JS_NewString(js, core_path));
|
||||
if (shop_path)
|
||||
JS_SetPropertyStr(js, hidden_env, "shop_path", JS_NewString(js, shop_path));
|
||||
}
|
||||
|
||||
// Stone the environment
|
||||
hidden_env = JS_Stone(js, hidden_env);
|
||||
@@ -282,10 +288,14 @@ static void print_usage(const char *prog)
|
||||
printf("Usage: %s [options] <script> [args...]\n\n", prog);
|
||||
printf("Run a cell script (.ce actor or .cm module).\n\n");
|
||||
printf("Options:\n");
|
||||
printf(" --shop <path> Set shop path (overrides CELL_SHOP env var)\n");
|
||||
printf(" --core <path> Set core path directly (overrides CELL_CORE)\n");
|
||||
printf(" --shop <path> Set shop path (overrides CELL_SHOP)\n");
|
||||
printf(" --mcode <script> [args] Run through mcode compilation pipeline\n");
|
||||
printf(" --test [heap_size] Run C test suite\n");
|
||||
printf(" -h, --help Show this help message\n");
|
||||
printf("\nEnvironment:\n");
|
||||
printf(" CELL_CORE Core path (default: <shop>/packages/core)\n");
|
||||
printf(" CELL_SHOP Shop path (default: ~/.cell)\n");
|
||||
printf("\nRecompile after changes: make\n");
|
||||
printf("Bootstrap from scratch: make bootstrap\n");
|
||||
}
|
||||
@@ -315,6 +325,7 @@ int cell_init(int argc, char **argv)
|
||||
int use_mcode = 0;
|
||||
int arg_start = 1;
|
||||
const char *shop_override = NULL;
|
||||
const char *core_override = NULL;
|
||||
|
||||
// Parse flags (order-independent)
|
||||
while (arg_start < argc && argv[arg_start][0] == '-') {
|
||||
@@ -328,12 +339,19 @@ int cell_init(int argc, char **argv)
|
||||
}
|
||||
shop_override = argv[arg_start + 1];
|
||||
arg_start += 2;
|
||||
} else if (strcmp(argv[arg_start], "--core") == 0) {
|
||||
if (arg_start + 1 >= argc) {
|
||||
printf("ERROR: --core requires a path argument\n");
|
||||
return 1;
|
||||
}
|
||||
core_override = argv[arg_start + 1];
|
||||
arg_start += 2;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!find_cell_shop(shop_override)) return 1;
|
||||
if (!find_cell_shop(shop_override, core_override)) return 1;
|
||||
|
||||
actor_initialize();
|
||||
|
||||
@@ -394,7 +412,9 @@ int cell_init(int argc, char **argv)
|
||||
|
||||
JSValue hidden_env = JS_NewObject(ctx);
|
||||
JS_SetPropertyStr(ctx, hidden_env, "os", js_os_use(ctx));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "shop_path", JS_NewString(ctx, shop_path));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "core_path", JS_NewString(ctx, core_path));
|
||||
if (shop_path)
|
||||
JS_SetPropertyStr(ctx, hidden_env, "shop_path", JS_NewString(ctx, shop_path));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "use_mcode", JS_NewBool(ctx, use_mcode));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "actorsym", JS_DupValue(ctx, cli_rt->actor_sym_ref.val));
|
||||
JS_SetPropertyStr(ctx, hidden_env, "json", js_json_use(ctx));
|
||||
|
||||
Reference in New Issue
Block a user