From 7819dd2d0a707ebdec758669d4228d5b18e77318 Mon Sep 17 00:00:00 2001 From: Nilton Constantino Date: Mon, 2 Feb 2026 20:22:48 +0000 Subject: [PATCH] pr 62 --- .../src/virtual_machine/virtual_machine.rs | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/crates/prometeu-core/src/virtual_machine/virtual_machine.rs b/crates/prometeu-core/src/virtual_machine/virtual_machine.rs index 49205785..e3b1e525 100644 --- a/crates/prometeu-core/src/virtual_machine/virtual_machine.rs +++ b/crates/prometeu-core/src/virtual_machine/virtual_machine.rs @@ -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::() { @@ -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;