feat: 新增对象字面量和属性访问表达式

This commit is contained in:
0264408
2026-02-10 17:13:40 +08:00
parent 5c5ca8600a
commit 521c7006d9
11 changed files with 188 additions and 66 deletions
+5
View File
@@ -1,9 +1,11 @@
pub mod builtins;
pub mod env;
pub mod interpreter;
pub use env::Env;
pub use interpreter::Interpreter;
use std::collections::HashMap;
use std::rc::Rc;
use std::cell::RefCell;
use std::fmt;
@@ -16,6 +18,7 @@ pub enum Value {
String(String),
Bool(bool),
Nil,
Object(Rc<RefCell<HashMap<String, Value>>>),
Function(Rc<Function>),
NativeFunction(NativeFn),
}
@@ -27,6 +30,7 @@ impl std::fmt::Debug for Value {
Value::String(s) => write!(f, "String({:?})", s),
Value::Bool(b) => write!(f, "Bool({:?})", b),
Value::Nil => write!(f, "Nil"),
Value::Object(_) => write!(f, "Object(...)"),
Value::Function(_) => write!(f, "Function(...)"),
Value::NativeFunction(_) => write!(f, "NativeFunction(...)"),
}
@@ -40,6 +44,7 @@ impl fmt::Display for Value {
Value::String(s) => write!(f, "{}", s),
Value::Bool(b) => write!(f, "{}", b),
Value::Nil => write!(f, "nil"),
Value::Object(_) => write!(f, "<object>"),
Value::Function(_) => write!(f, "<function>"),
Value::NativeFunction(_) => write!(f, "<native function>"),
}