remove random str for imported

This commit is contained in:
2026-02-16 19:13:37 -06:00
parent ce387d18d5
commit dce0b5cc89

View File

@@ -21,52 +21,10 @@ var my$_ = actor_api
var core = "core" var core = "core"
// Generate a random 5-letter uppercase identifier for package symbol naming. // Make a package name safe for use in C identifiers.
// Avoids collisions with existing IDs and "CORE". // Replaces /, ., -, @ with _ so the result is a valid C identifier fragment.
function generate_package_id() { function safe_c_name(name) {
var lock = Shop.load_lock() return replace(replace(replace(replace(name, '/', '_'), '.', '_'), '-', '_'), '@', '_')
var existing = {}
var keys = array(lock)
var _i = 0
while (_i < length(keys)) {
if (lock[keys[_i]] && lock[keys[_i]].id)
existing[lock[keys[_i]].id] = true
_i = _i + 1
}
existing["CORE"] = true
var id = null
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var _j = 0
while (true) {
id = ""
_j = 0
while (_j < 5) {
id = id + chars[abs(os.random()) % 26]
_j = _j + 1
}
if (!existing[id]) return id
}
}
// Get the assigned ID for a package, generating one if needed.
// Core always returns "core". Other packages get a random 5-letter ID
// assigned lazily on first use and persisted in lock.toml.
function get_package_id(pkg) {
if (pkg == core) return core
var lock = Shop.load_lock()
var entry = lock[pkg]
if (entry && entry.id) return entry.id
var id = generate_package_id()
if (!entry) {
entry = {}
lock[pkg] = entry
}
entry.id = id
Shop.save_lock(lock)
return id
} }
function pull_from_cache(content) function pull_from_cache(content)
@@ -706,21 +664,21 @@ function resolve_locator(path, ctx)
} }
// Generate symbol name for a C module file // Generate symbol name for a C module file
// Uses the package's assigned ID (5-letter random or "core") instead of the full name // e.g., make_c_symbol('core', 'math') -> 'js_core_math_use'
function make_c_symbol(pkg, file) { function make_c_symbol(pkg, file) {
var pkg_id = get_package_id(pkg) var pkg_safe = safe_c_name(pkg)
var file_safe = replace(replace(replace(file, '/', '_'), '.', '_'), '-', '_') var file_safe = safe_c_name(file)
return 'js_' + pkg_id + '_' + file_safe + '_use' return 'js_' + pkg_safe + '_' + file_safe + '_use'
} }
// Get the deterministic dylib path for a module in lib/<pkg_id>/<stem>.dylib // Get the deterministic dylib path for a module in lib/<pkg>/<stem>.dylib
function get_dylib_path(pkg, stem) { function get_dylib_path(pkg, stem) {
return global_shop_path + '/lib/' + get_package_id(pkg) + '/' + stem + dylib_ext return global_shop_path + '/lib/' + safe_package_path(pkg) + '/' + stem + dylib_ext
} }
// Get the deterministic mach path for a module in lib/<pkg_id>/<stem>.mach // Get the deterministic mach path for a module in lib/<pkg>/<stem>.mach
function get_mach_path(pkg, stem) { function get_mach_path(pkg, stem) {
return global_shop_path + '/lib/' + get_package_id(pkg) + '/' + stem + '.mach' return global_shop_path + '/lib/' + safe_package_path(pkg) + '/' + stem + '.mach'
} }
// Open a per-module dylib and return the dlopen handle // Open a per-module dylib and return the dlopen handle
@@ -1492,32 +1450,26 @@ Shop.get_package_dir = function(pkg) {
} }
// Generate C symbol name for a file within a package // Generate C symbol name for a file within a package
// Uses the package's assigned ID (e.g., "WAWOF") instead of the full name
// e.g., c_symbol_for_file('gitea.pockle.world/john/prosperon', 'sprite.c') // e.g., c_symbol_for_file('gitea.pockle.world/john/prosperon', 'sprite.c')
// -> 'js_WAWOF_sprite_use' // -> 'js_gitea_pockle_world_john_prosperon_sprite_use'
Shop.c_symbol_for_file = function(pkg, file) { Shop.c_symbol_for_file = function(pkg, file) {
var pkg_id = get_package_id(pkg) var pkg_safe = safe_c_name(pkg)
var file_safe = replace(replace(fd.stem(file), '/', '_'), '.', '_') var file_safe = safe_c_name(fd.stem(file))
var suffix = ends_with(file, '.ce') ? '_program' : '_use' var suffix = ends_with(file, '.ce') ? '_program' : '_use'
return 'js_' + pkg_id + '_' + file_safe + suffix return 'js_' + pkg_safe + '_' + file_safe + suffix
} }
// Generate C symbol prefix for a package // Generate C symbol prefix for a package
// e.g., c_symbol_prefix('gitea.pockle.world/john/prosperon') -> 'js_WAWOF_' // e.g., c_symbol_prefix('core') -> 'js_core_'
Shop.c_symbol_prefix = function(pkg) { Shop.c_symbol_prefix = function(pkg) {
var pkg_id = get_package_id(pkg) return 'js_' + safe_c_name(pkg) + '_'
return 'js_' + pkg_id + '_'
} }
// Get the library name for a package // Get the library directory name for a package
// e.g., 'gitea.pockle.world/john/prosperon' -> 'WAWOF'
Shop.lib_name_for_package = function(pkg) { Shop.lib_name_for_package = function(pkg) {
return get_package_id(pkg) return safe_package_path(pkg)
} }
// Get the assigned package ID (public API)
Shop.get_package_id = get_package_id
// Returns { ok: bool, results: [{pkg, ok, error}] } // Returns { ok: bool, results: [{pkg, ok, error}] }
// Get the deterministic dylib path for a module (public API) // Get the deterministic dylib path for a module (public API)
Shop.get_dylib_path = function(pkg, stem) { Shop.get_dylib_path = function(pkg, stem) {