Validate unified source and native positional call contracts
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
| 文件 | 职责 |
|
||||
| --- | --- |
|
||||
| [lib.rs](lib.rs) | VM 类型导出、objects 类型兼容重导出、宿主调用与字节码 rustdoc 示例 |
|
||||
| [vm.rs](vm.rs) | Vm 拥有 ObjectStore 与错误位置记录;对象操作和宿主 new_class 和显式Trait注册/关系查询显式委托给 objects;函数/字段检查统一开关与函数类型配置 |
|
||||
| [vm.rs](vm.rs) | Vm 拥有 ObjectStore 与错误位置记录;对象操作和宿主 new_class 和显式Trait注册/关系查询显式委托给 objects;函数/字段检查统一开关、统一参数区间查询与函数类型配置 |
|
||||
| [frame.rs](frame.rs) | EndorFrame、栈条目、返回类型执行根、执行位置元数据、ExecutionLimits |
|
||||
| [eval.rs](eval.rs) | execute/call、只读调用与依赖结果、参数绑定、可选注解检查、源码类字段环境绑定、帧切换、取指分派、MakeFunction、结果根转移与失败清理 |
|
||||
| [eval.rs](eval.rs) | execute/call、只读调用与依赖结果、参数绑定、原生实现前数量检查、可选注解检查、源码类字段环境绑定、帧切换、取指分派、MakeFunction、结果根转移与失败清理 |
|
||||
|
||||
## 常见修改入口
|
||||
|
||||
|
||||
@@ -260,6 +260,16 @@ impl Vm {
|
||||
for argument in arguments {
|
||||
self.validate_value(argument)?;
|
||||
}
|
||||
if let Some(arity) = self.objects.call_arity(function)?
|
||||
&& !arity.accepts(arguments.len())
|
||||
{
|
||||
return Err(VmError::ArgumentCount {
|
||||
name: self.object(function)?.payload().kind_name().into(),
|
||||
required: arity.required,
|
||||
maximum: arity.maximum,
|
||||
provided: arguments.len(),
|
||||
});
|
||||
}
|
||||
if let Some(callable) = self.object(function)?.payload().native_callable() {
|
||||
return NativeContext::execute(&mut self.objects, function, arguments, callable);
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ pub use objects::{
|
||||
TypeConstructor,
|
||||
};
|
||||
pub use objects::{
|
||||
ChangeBatch, ChangeKey, CodeLayout, CompareOp, ContextNativeFunction, DecodedInstruction,
|
||||
EndorBaseExceptionObject, EndorCellObject, EndorCode, EndorCodeObject, EndorDecimal,
|
||||
EndorDictObject, EndorFunctionObject, EndorInteger, EndorNativeCall, EndorNativeFunctionObject,
|
||||
EndorNumber, EndorNumberObject, EndorObject, EndorRational, EndorReal, EndorStringObject,
|
||||
EndorTracebackEntry, Instruction, NativeCall, NativeCallable, NativeContext, NativeFunction,
|
||||
NativeResult, ObjectChange, ObjectHeader, ObjectPayload, ObjectRef, Opcode, Record,
|
||||
SourceSignature, Value, VmError, WeakObjectRef,
|
||||
CallArity, ChangeBatch, ChangeKey, CodeLayout, CompareOp, ContextNativeFunction,
|
||||
DecodedInstruction, EndorBaseExceptionObject, EndorCellObject, EndorCode, EndorCodeObject,
|
||||
EndorDecimal, EndorDictObject, EndorFunctionObject, EndorInteger, EndorNativeCall,
|
||||
EndorNativeFunctionObject, EndorNumber, EndorNumberObject, EndorObject, EndorRational,
|
||||
EndorReal, EndorStringObject, EndorTracebackEntry, Instruction, NativeCall, NativeCallable,
|
||||
NativeContext, NativeFunction, NativeResult, ObjectChange, ObjectHeader, ObjectPayload,
|
||||
ObjectRef, Opcode, Record, SourceSignature, Value, VmError, WeakObjectRef,
|
||||
};
|
||||
pub use vm::Vm;
|
||||
|
||||
@@ -25,6 +25,10 @@ impl Vm {
|
||||
self.source_type_checks = enabled;
|
||||
Ok(())
|
||||
}
|
||||
pub fn call_arity(&self, function: ObjectRef) -> Result<Option<objects::CallArity>, VmError> {
|
||||
self.objects.call_arity(function)
|
||||
}
|
||||
|
||||
pub fn set_function_type(&mut self, definition: ObjectRef) -> Result<(), VmError> {
|
||||
self.objects.set_function_type(definition)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user