feat: create scoped language functions from native calls
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
| [lib.rs](lib.rs) | 包边界、对象类型/ObjectStore 公开导出与独立存储 rustdoc 示例 |
|
||||
| [object.rs](object.rs) | Value、CompareOp、ObjectPayload、ObjectHeader、EndorObject、Record、NativeFunction |
|
||||
| [types.rs](types.rs) | 托管名义类型、显式 Object/Type 引导、继承查询、受管方法表/接收者绑定、类字段与原生构造委托 |
|
||||
| [native.rs](native.rs) | NativeContext、上下文原生函数、作用域根与非递归委托调用 |
|
||||
| [native.rs](native.rs) | NativeContext、上下文原生函数、作用域语言函数工厂、根与非递归委托调用 |
|
||||
| [changes.rs](changes.rs) | 合并变更批次、变更键与有界通知额度 |
|
||||
| [number.rs](number.rs) | Integer/Decimal/Rational/BinaryFloat/Complex 的无损表示和装箱载荷 |
|
||||
| [builtins.rs](builtins.rs) | String、Dict、Cell、Function、BaseException 载荷与 trace 边 |
|
||||
|
||||
@@ -58,6 +58,20 @@ impl<'a> NativeContext<'a> {
|
||||
self.allocate(crate::Record)
|
||||
}
|
||||
|
||||
/// Build a language function under this native scope using validated code.
|
||||
pub fn new_function(
|
||||
&mut self,
|
||||
name: impl Into<String>,
|
||||
code: ObjectRef,
|
||||
globals: ObjectRef,
|
||||
) -> Result<ObjectRef, VmError> {
|
||||
let function = self
|
||||
.store
|
||||
.new_function(name, code, globals, vec![], vec![])?;
|
||||
self.roots.push(function);
|
||||
Ok(function)
|
||||
}
|
||||
|
||||
pub fn new_dict(&mut self) -> Result<ObjectRef, VmError> {
|
||||
let object = self.store.new_dict()?;
|
||||
self.roots.push(object);
|
||||
|
||||
Reference in New Issue
Block a user