remove random str for imported
This commit is contained in:
@@ -21,52 +21,10 @@ var my$_ = actor_api
|
||||
|
||||
var core = "core"
|
||||
|
||||
// Generate a random 5-letter uppercase identifier for package symbol naming.
|
||||
// Avoids collisions with existing IDs and "CORE".
|
||||
function generate_package_id() {
|
||||
var lock = Shop.load_lock()
|
||||
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
|
||||
// Make a package name safe for use in C identifiers.
|
||||
// Replaces /, ., -, @ with _ so the result is a valid C identifier fragment.
|
||||
function safe_c_name(name) {
|
||||
return replace(replace(replace(replace(name, '/', '_'), '.', '_'), '-', '_'), '@', '_')
|
||||
}
|
||||
|
||||
function pull_from_cache(content)
|
||||
@@ -706,21 +664,21 @@ function resolve_locator(path, ctx)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
var pkg_id = get_package_id(pkg)
|
||||
var file_safe = replace(replace(replace(file, '/', '_'), '.', '_'), '-', '_')
|
||||
return 'js_' + pkg_id + '_' + file_safe + '_use'
|
||||
var pkg_safe = safe_c_name(pkg)
|
||||
var file_safe = safe_c_name(file)
|
||||
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) {
|
||||
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) {
|
||||
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
|
||||
@@ -1492,32 +1450,26 @@ Shop.get_package_dir = function(pkg) {
|
||||
}
|
||||
|
||||
// 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')
|
||||
// -> 'js_WAWOF_sprite_use'
|
||||
// -> 'js_gitea_pockle_world_john_prosperon_sprite_use'
|
||||
Shop.c_symbol_for_file = function(pkg, file) {
|
||||
var pkg_id = get_package_id(pkg)
|
||||
var file_safe = replace(replace(fd.stem(file), '/', '_'), '.', '_')
|
||||
var pkg_safe = safe_c_name(pkg)
|
||||
var file_safe = safe_c_name(fd.stem(file))
|
||||
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
|
||||
// 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) {
|
||||
var pkg_id = get_package_id(pkg)
|
||||
return 'js_' + pkg_id + '_'
|
||||
return 'js_' + safe_c_name(pkg) + '_'
|
||||
}
|
||||
|
||||
// Get the library name for a package
|
||||
// e.g., 'gitea.pockle.world/john/prosperon' -> 'WAWOF'
|
||||
// Get the library directory name for a package
|
||||
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}] }
|
||||
// Get the deterministic dylib path for a module (public API)
|
||||
Shop.get_dylib_path = function(pkg, stem) {
|
||||
|
||||
Reference in New Issue
Block a user