Enforce native type signatures and effects across delegated calls
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user