feat: 添加内置函数支持(len, typeof, push, pop),更新相关错误处理和测试用例

This commit is contained in:
0264408
2026-06-16 19:03:47 +08:00
parent 18fa53cf4a
commit 75c1d230ad
7 changed files with 314 additions and 9 deletions
+7
View File
@@ -1,5 +1,6 @@
//! 内置函数模块:按功能分组注册,便于扩展和维护。
mod core;
mod io;
mod os;
@@ -27,4 +28,10 @@ pub fn register_all(env: &Rc<RefCell<Env>>) {
e.define("os".into(), Value::Object(Rc::new(RefCell::new(os))), true);
// clock can also be used as a global function for convenience
e.define("clock".into(), Value::NativeFunction(os::clock), true);
// core — len, typeof, push, pop
e.define("len".into(), Value::NativeFunction(core::len), true);
e.define("typeof".into(), Value::NativeFunction(core::typeof_fn), true);
e.define("push".into(), Value::NativeFunction(core::push), true);
e.define("pop".into(), Value::NativeFunction(core::pop), true);
}