Fix type-of and comparison for new Value variants
This commit is contained in:
+44
-18
@@ -381,6 +381,11 @@ fn register_comparison(env: &Environment) {
|
||||
(Value::Record(la, va), Value::Record(lb, vb)) => {
|
||||
Value::Bool(std::sync::Arc::ptr_eq(la, lb) && va == vb)
|
||||
}
|
||||
(Value::Tuple(a), Value::Tuple(b)) => {
|
||||
Value::Bool(a.len() == b.len()
|
||||
&& a.iter().zip(b.iter()).all(|(x, y)| values_equal(x, y)))
|
||||
}
|
||||
(Value::FieldAccessor(a), Value::FieldAccessor(b)) => Value::Bool(a == b),
|
||||
(Value::Void, Value::Void) => Value::Bool(true),
|
||||
_ => Value::Bool(false),
|
||||
}
|
||||
@@ -401,6 +406,11 @@ fn register_comparison(env: &Environment) {
|
||||
(Value::Bool(a), Value::Bool(b)) => Value::Bool(a != b),
|
||||
(Value::Keyword(a), Value::Keyword(b)) => Value::Bool(a != b),
|
||||
(Value::DateTime(a), Value::DateTime(b)) => Value::Bool(a != b),
|
||||
(Value::Tuple(a), Value::Tuple(b)) => {
|
||||
Value::Bool(!(a.len() == b.len()
|
||||
&& a.iter().zip(b.iter()).all(|(x, y)| values_equal(x, y))))
|
||||
}
|
||||
(Value::FieldAccessor(a), Value::FieldAccessor(b)) => Value::Bool(a != b),
|
||||
(Value::Void, Value::Void) => Value::Bool(false),
|
||||
_ => Value::Bool(true),
|
||||
}
|
||||
@@ -605,24 +615,40 @@ fn register_testing(env: &Environment) {
|
||||
}));
|
||||
env.register_native_fn("type-of", type_of_ty, Purity::Pure, |args| {
|
||||
let name = match args.first() {
|
||||
Some(v) => match v.static_type() {
|
||||
StaticType::Void => "void",
|
||||
StaticType::Bool => "bool",
|
||||
StaticType::Int => "int",
|
||||
StaticType::Float => "float",
|
||||
StaticType::DateTime => "datetime",
|
||||
StaticType::Text => "text",
|
||||
StaticType::Keyword => "keyword",
|
||||
StaticType::Tuple(_)
|
||||
| StaticType::Vector(_, _)
|
||||
| StaticType::Matrix(_, _) => "tuple",
|
||||
StaticType::Record(_) => "record",
|
||||
StaticType::Series(_) => "series",
|
||||
StaticType::Stream(_) => "stream",
|
||||
StaticType::Function(_) | StaticType::FunctionOverloads(_) => "function",
|
||||
StaticType::FieldAccessor(_) => "field-accessor",
|
||||
StaticType::Object(name) => name,
|
||||
_ => "unknown",
|
||||
// Match on Value directly to avoid lossy static_type() conversion
|
||||
// (e.g. Value::Function → StaticType::Any loses the "function" info).
|
||||
Some(v) => match v {
|
||||
Value::Void => "void",
|
||||
Value::Bool(_) => "bool",
|
||||
Value::Int(_) => "int",
|
||||
Value::Float(_) => "float",
|
||||
Value::DateTime(_) => "datetime",
|
||||
Value::Text(_) => "text",
|
||||
Value::Keyword(_) => "keyword",
|
||||
Value::Tuple(_) => "tuple",
|
||||
Value::Record(_, _) => "record",
|
||||
Value::FieldAccessor(_) => "field-accessor",
|
||||
Value::Function(_) | Value::Closure(_) => "function",
|
||||
Value::Quote(_) => "quote",
|
||||
Value::Series(_) => "series",
|
||||
Value::Stream(_) => "stream",
|
||||
Value::Cell(c) => {
|
||||
// Recurse through Cell to get the inner type.
|
||||
// We can't recurse here directly, so use static_type fallback.
|
||||
match c.borrow().static_type() {
|
||||
StaticType::Void => "void",
|
||||
StaticType::Bool => "bool",
|
||||
StaticType::Int => "int",
|
||||
StaticType::Float => "float",
|
||||
StaticType::DateTime => "datetime",
|
||||
StaticType::Text => "text",
|
||||
StaticType::Keyword => "keyword",
|
||||
StaticType::Record(_) => "record",
|
||||
StaticType::Series(_) => "series",
|
||||
StaticType::Stream(_) => "stream",
|
||||
_ => "unknown",
|
||||
}
|
||||
}
|
||||
},
|
||||
None => panic!("type-of requires 1 argument"),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user