Check source function annotations and unify managed function identity
This commit is contained in:
@@ -17,6 +17,14 @@ pub struct CodeLayout {
|
||||
pub names: Vec<String>,
|
||||
}
|
||||
|
||||
/// Source declaration metadata, separate from executable slot layout.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SourceSignature {
|
||||
pub parameters: Vec<String>,
|
||||
pub return_type: String,
|
||||
pub method_owner: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EndorCode {
|
||||
bytecode: Vec<u8>,
|
||||
@@ -27,6 +35,7 @@ pub struct EndorCode {
|
||||
name: String,
|
||||
filename: String,
|
||||
first_line: usize,
|
||||
signature: Option<SourceSignature>,
|
||||
}
|
||||
|
||||
impl EndorCode {
|
||||
@@ -73,9 +82,30 @@ impl EndorCode {
|
||||
name: "<code>".into(),
|
||||
filename: "<endor>".into(),
|
||||
first_line: 1,
|
||||
signature: None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_source_signature(mut self, signature: SourceSignature) -> Result<Self, VmError> {
|
||||
if signature.parameters.len() != self.parameters().len()
|
||||
|| signature.return_type.is_empty()
|
||||
|| signature.parameters.iter().any(String::is_empty)
|
||||
|| signature
|
||||
.method_owner
|
||||
.as_ref()
|
||||
.is_some_and(String::is_empty)
|
||||
{
|
||||
return Err(VmError::InvalidArgument(
|
||||
"source signature does not match code parameters",
|
||||
));
|
||||
}
|
||||
self.signature = Some(signature);
|
||||
Ok(self)
|
||||
}
|
||||
pub fn source_signature(&self) -> Option<&SourceSignature> {
|
||||
self.signature.as_ref()
|
||||
}
|
||||
|
||||
pub fn with_location(
|
||||
mut self,
|
||||
name: impl Into<String>,
|
||||
|
||||
Reference in New Issue
Block a user