This commit is contained in:
Nilton Constantino 2026-02-02 20:22:48 +00:00
parent ada072805e
commit 7819dd2d0a
No known key found for this signature in database

View File

@ -148,7 +148,7 @@ impl VirtualMachine {
return Err(VmInitError::InvalidFormat);
};
// Resolve the entrypoint: only empty (defaults to 0) or numeric PC are allowed.
// Resolve the entrypoint: empty (defaults to 0), numeric PC, or symbol name.
let pc = if entrypoint.is_empty() {
0
} else if let Ok(addr) = entrypoint.parse::<usize>() {
@ -157,8 +157,25 @@ impl VirtualMachine {
}
addr
} else {
// No symbol lookup by name in runtime. Linking is compiler-owned.
return Err(VmInitError::EntrypointNotFound);
// Try to resolve as a symbol name from the exports map
if let Some(&func_idx) = program.exports.get(entrypoint) {
program.functions.get(func_idx as usize)
.map(|f| f.code_offset as usize)
.ok_or(VmInitError::EntrypointNotFound)?
} else {
// Suffix match fallback (e.g. "frame" matches "src/main/modules/main:frame")
let suffix = format!(":{}", entrypoint);
let found = program.exports.iter()
.find(|(name, _)| name == &entrypoint || name.ends_with(&suffix));
if let Some((_, &func_idx)) = found {
program.functions.get(func_idx as usize)
.map(|f| f.code_offset as usize)
.ok_or(VmInitError::EntrypointNotFound)?
} else {
return Err(VmInitError::EntrypointNotFound);
}
}
};
// Finalize initialization by applying the new program and PC.
@ -178,8 +195,25 @@ impl VirtualMachine {
}).unwrap_or(0);
(addr, idx)
} else {
// No symbol lookup by name in runtime. Default to 0 for non-numeric entrypoints.
(0, 0)
// Try to resolve as a symbol name
let found = self.program.exports.get(entrypoint)
.map(|&idx| (idx, entrypoint.to_string()))
.or_else(|| {
let suffix = format!(":{}", entrypoint);
self.program.exports.iter()
.find(|(name, _)| name == &entrypoint || name.ends_with(&suffix))
.map(|(name, &idx)| (idx, name.clone()))
});
if let Some((func_idx, _)) = found {
let addr = self.program.functions.get(func_idx as usize)
.map(|f| f.code_offset as usize)
.unwrap_or(0);
(addr, func_idx as usize)
} else {
// Default to 0 for non-numeric entrypoints that aren't found.
(0, 0)
}
};
self.pc = addr;