feat: 添加对const关键字的支持,允许定义不可变变量并增强相关错误处理

This commit is contained in:
0264408
2026-06-16 17:24:17 +08:00
parent 284a29a4be
commit c2d6c518fc
8 changed files with 254 additions and 102 deletions
+5 -5
View File
@@ -16,15 +16,15 @@ pub fn register_all(env: &Rc<RefCell<Env>>) {
let mut io = HashMap::new();
io.insert("print".into(), Value::NativeFunction(io::print));
io.insert("input".into(), Value::NativeFunction(io::input));
e.define("io".into(), Value::Object(Rc::new(RefCell::new(io))));
e.define("io".into(), Value::Object(Rc::new(RefCell::new(io))), true);
// input and print can be used as global functions for convenience
e.define("print".into(), Value::NativeFunction(io::print));
e.define("input".into(), Value::NativeFunction(io::input));
e.define("print".into(), Value::NativeFunction(io::print), true);
e.define("input".into(), Value::NativeFunction(io::input), true);
// os
let mut os = HashMap::new();
os.insert("clock".into(), Value::NativeFunction(os::clock));
e.define("os".into(), Value::Object(Rc::new(RefCell::new(os))));
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));
e.define("clock".into(), Value::NativeFunction(os::clock), true);
}