Enforce native type signatures and effects across delegated calls

This commit is contained in:
2026-10-22 13:51:42 +08:00
parent f9243c77c7
commit 680caf81e3
14 changed files with 676 additions and 24 deletions
+20
View File
@@ -10,12 +10,32 @@ pub(crate) enum StackEntry {
Value(Value),
}
#[derive(Debug)]
pub(crate) struct NativeReturn {
pub name: String,
pub expected: crate::AnnotationType,
}
impl NativeReturn {
pub fn check(&self, store: &objects::ObjectStore, value: &Value) -> Result<(), crate::VmError> {
if !store.matches_annotation(value, self.expected)? {
return Err(crate::VmError::TypeMismatch {
function: self.name.clone(),
position: "return".into(),
expected: store.annotation_type_name(self.expected)?,
actual: store.value_type_name(value)?,
});
}
Ok(())
}
}
/// Internal activation record, analogous to _PyInterpreterFrame. It has no
/// EndorObject header; introspection objects can be added independently later.
#[derive(Debug)]
pub struct EndorFrame {
pub(crate) function: ObjectRef,
pub(crate) return_type: Option<crate::AnnotationType>,
pub(crate) native_returns: Vec<NativeReturn>,
/// Index of the caller in the execution's frame vector, never a pointer.
pub(crate) previous: Option<usize>,
pub(crate) code: ObjectRef,