From f7b5252044a2bc5c49c3beb4d98249011ba890b4 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Tue, 10 Feb 2026 09:21:21 -0600 Subject: [PATCH] core flag --- internal/bootstrap.cm | 3 +- internal/engine.cm | 8 ++--- source/cell.c | 80 +++++++++++++++++++++++++++---------------- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/internal/bootstrap.cm b/internal/bootstrap.cm index 75c61076..a5ee6f96 100644 --- a/internal/bootstrap.cm +++ b/internal/bootstrap.cm @@ -1,5 +1,4 @@ -// Hidden vars (os, args, shop_path, use_mcode) come from env -var core_path = shop_path + '/packages/core' +// Hidden vars (os, args, core_path, shop_path, use_mcode) come from env // args[0] = script name, args[1..] = user args var load_internal = os.load_internal function use_embed(name) { diff --git a/internal/engine.cm b/internal/engine.cm index bd4dbf76..4bb2b989 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -1,4 +1,4 @@ -// Hidden vars (os, actorsym, init, shop_path) come from env +// Hidden vars (os, actorsym, init, core_path, shop_path) come from env var ACTORDATA = actorsym var SYSYM = '__SYSTEM__' @@ -52,9 +52,9 @@ function ends_with(str, suffix) { var js = use_embed('js') var fd = use_embed('fd') -// shop_path comes from hidden env (set by cell.c) -var packages_path = shop_path + '/packages' -var core_path = packages_path + '/core' +// core_path and shop_path come from hidden env (set by cell.c) +// 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 diff --git a/source/cell.c b/source/cell.c index 881b2d9a..d57037b8 100644 --- a/source/cell.c +++ b/source/cell.c @@ -39,52 +39,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 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; } @@ -205,9 +210,10 @@ void script_startup(cell_rt *prt) JS_SetPropertyStr(js, hidden_env, "init", JS_NULL); } - 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); @@ -277,10 +283,14 @@ static void print_usage(const char *prog) printf("Usage: %s [options]