From bd4d5ecd5803d989bad0a407a6105eefc4a1cacf Mon Sep 17 00:00:00 2001 From: Vedat Can Keklik Date: Thu, 26 Dec 2024 21:53:25 +0300 Subject: [PATCH] fix: Removed NaN and Null --- lykiadb-lang/src/ast/expr.rs | 6 +- lykiadb-lang/src/ast/mod.rs | 6 +- lykiadb-lang/src/parser/mod.rs | 6 - lykiadb-lang/src/tokenizer/scanner.rs | 3 +- lykiadb-lang/src/tokenizer/token.rs | 4 - .../tests/lang/generic/other_literals.rs | 15 --- lykiadb-server/benches/scripts/while.ly | 10 -- lykiadb-server/benches/scripts/while.short.ly | 5 - lykiadb-server/src/engine/interpreter.rs | 4 +- lykiadb-server/src/engine/stdlib/json.rs | 4 +- lykiadb-server/src/value/datatype.rs | 11 ++ lykiadb-server/src/value/eval.rs | 103 +++++++----------- lykiadb-server/src/value/mod.rs | 21 +--- lykiadb-server/tests/interpreter/expr | 18 +-- 14 files changed, 72 insertions(+), 144 deletions(-) create mode 100644 lykiadb-server/src/value/datatype.rs diff --git a/lykiadb-lang/src/ast/expr.rs b/lykiadb-lang/src/ast/expr.rs index 4f14611c..155c00ec 100644 --- a/lykiadb-lang/src/ast/expr.rs +++ b/lykiadb-lang/src/ast/expr.rs @@ -329,8 +329,7 @@ impl Display for Expr { Literal::Str(s) => write!(f, "Str(\"{}\")", s), Literal::Num(n) => write!(f, "Num({:?})", n), Literal::Bool(b) => write!(f, "{}", b), - Literal::Undefined => write!(f, "undefined"), - Literal::Object(o) => write!(f, "{:?}", o), + Literal::Object(o) => write!(f, "Object({:?})", o), Literal::Array(a) => write!( f, "Array({})", @@ -339,8 +338,7 @@ impl Display for Expr { .collect::>() .join(", ") ), - Literal::NaN => write!(f, "NaN"), - Literal::Null => write!(f, "null"), + Literal::Undefined => write!(f, "Undefined"), }, Expr::Function { name, parameters, .. diff --git a/lykiadb-lang/src/ast/mod.rs b/lykiadb-lang/src/ast/mod.rs index eccc5d78..faf99c1c 100644 --- a/lykiadb-lang/src/ast/mod.rs +++ b/lykiadb-lang/src/ast/mod.rs @@ -52,11 +52,9 @@ pub enum Literal { Str(Arc), Num(f64), Bool(bool), - Undefined, Object(FxHashMap>), Array(Vec), - NaN, - Null, + Undefined, } impl Literal { @@ -78,8 +76,6 @@ impl Hash for Literal { Literal::Array(a) => a.hash(state), // Literal::Undefined => "undefined".hash(state), - Literal::NaN => "NaN".hash(state), - Literal::Null => "null".hash(state), } } } diff --git a/lykiadb-lang/src/parser/mod.rs b/lykiadb-lang/src/parser/mod.rs index 81db5766..631d8fb9 100644 --- a/lykiadb-lang/src/parser/mod.rs +++ b/lykiadb-lang/src/parser/mod.rs @@ -750,12 +750,6 @@ impl<'a> Parser<'a> { span: tok.span, id: self.get_expr_id(), })), - TokenType::Null => Ok(Box::new(Expr::Literal { - value: Literal::Null, - raw: "null".to_string(), - span: tok.span, - id: self.get_expr_id(), - })), TokenType::Undefined => Ok(Box::new(Expr::Literal { value: Literal::Undefined, raw: "undefined".to_string(), diff --git a/lykiadb-lang/src/tokenizer/scanner.rs b/lykiadb-lang/src/tokenizer/scanner.rs index 72ec97d6..aabd21db 100644 --- a/lykiadb-lang/src/tokenizer/scanner.rs +++ b/lykiadb-lang/src/tokenizer/scanner.rs @@ -1210,7 +1210,7 @@ mod test { #[test] fn test_sql_keywords() { assert_tokens( - "Begin Transaction Rollback Commit Where Having Asc Desc Order By Explain Is Not Null Offset Like Limit And Or Join Inner Right Left On Create Insert Update Delete Drop Into Values Index Collection Select From As Cross Default Group Key Of Only Primary References Set System Unique Read Write", vec![ + "Begin Transaction Rollback Commit Where Having Asc Desc Order By Explain Is Not Offset Like Limit And Or Join Inner Right Left On Create Insert Update Delete Drop Into Values Index Collection Select From As Cross Default Group Key Of Only Primary References Set System Unique Read Write", vec![ Token {tok_type: skw!(SqlKeyword::Begin), literal: None, lexeme: lexm!("Begin"), span: Span { line: 0, start: 0, line_end: 0, end: 5 }}, Token {tok_type: skw!(SqlKeyword::Transaction), literal: None, lexeme: lexm!("Transaction") , span: Span { line: 0, start: 6, line_end: 0, end: 17 }}, Token {tok_type: skw!(SqlKeyword::Rollback), literal: None, lexeme: lexm!("Rollback"), span: Span { line: 0, start: 18, line_end: 0, end: 26 }}, @@ -1224,7 +1224,6 @@ mod test { Token {tok_type: skw!(SqlKeyword::Explain), literal: None, lexeme: lexm!("Explain"), span: Span { line: 0, start: 65, line_end: 0, end: 72 }}, Token {tok_type: skw!(SqlKeyword::Is), literal: None, lexeme: lexm!("Is"), span: Span { line: 0, start: 73, line_end: 0, end: 75 }}, Token {tok_type: skw!(SqlKeyword::Not), literal: None, lexeme: lexm!("Not"), span: Span { line: 0, start: 76, line_end: 0, end: 79 }}, - Token {tok_type: skw!(SqlKeyword::Null), literal: None, lexeme: lexm!("Null"), span: Span { line: 0, start: 80, line_end: 0, end: 84 }}, Token {tok_type: skw!(SqlKeyword::Offset), literal: None, lexeme: lexm!("Offset"), span: Span { line: 0, start: 85, line_end: 0, end: 91 }}, Token {tok_type: skw!(SqlKeyword::Like), literal: None, lexeme: lexm!("Like"), span: Span { line: 0, start: 92, line_end: 0, end: 96 }}, Token {tok_type: skw!(SqlKeyword::Limit), literal: None, lexeme: lexm!("Limit"), span: Span { line: 0, start: 97, line_end: 0, end: 102 }}, diff --git a/lykiadb-lang/src/tokenizer/token.rs b/lykiadb-lang/src/tokenizer/token.rs index 317aec14..bac5208d 100644 --- a/lykiadb-lang/src/tokenizer/token.rs +++ b/lykiadb-lang/src/tokenizer/token.rs @@ -36,7 +36,6 @@ pub enum Symbol { pub enum TokenType { Str, Num, - Null, Undefined, False, True, @@ -102,7 +101,6 @@ pub enum SqlKeyword { // Is, Not, - Null, Like, In, Between, @@ -200,7 +198,6 @@ pub static GENERIC_KEYWORDS: phf::Map<&'static str, TokenType> = phf_map! { "while" => kw!(Keyword::While), "loop" => kw!(Keyword::Loop), // - "null" => TokenType::Null, "undefined" => TokenType::Undefined, "false" => TokenType::False, "true" => TokenType::True, @@ -228,7 +225,6 @@ pub static SQL_KEYWORDS: phf::Map<&'static str, TokenType> = phf_map! { "EXPLAIN" => skw!(SqlKeyword::Explain), "IS" => skw!(SqlKeyword::Is), "NOT" => skw!(SqlKeyword::Not), - "NULL" => skw!(SqlKeyword::Null), "LIKE" => skw!(SqlKeyword::Like), "IN" => skw!(SqlKeyword::In), "BETWEEN" => skw!(SqlKeyword::Between), diff --git a/lykiadb-lang/tests/lang/generic/other_literals.rs b/lykiadb-lang/tests/lang/generic/other_literals.rs index f415b23e..6ae3183c 100644 --- a/lykiadb-lang/tests/lang/generic/other_literals.rs +++ b/lykiadb-lang/tests/lang/generic/other_literals.rs @@ -51,20 +51,5 @@ assert_parsing! { } ] } - }, - null: { - "null;" => { - "@type": "Stmt::Program", - "body": [ - { - "@type": "Stmt::Expression", - "expr": { - "@type": "Expr::Literal", - "value": "Null", - "raw": "null" - } - } - ] - } } } diff --git a/lykiadb-server/benches/scripts/while.ly b/lykiadb-server/benches/scripts/while.ly index 389a92e0..add0c894 100644 --- a/lykiadb-server/benches/scripts/while.ly +++ b/lykiadb-server/benches/scripts/while.ly @@ -2,19 +2,9 @@ var $i = 0; while ($i < 10000000) { $i = $i + 1; - - 1; 1; 1; 2; 1; null; 1; "str"; 1; true; - null; null; null; 1; null; "str"; null; true; - true; true; true; 1; true; false; true; "str"; true; null; - "str"; "str"; "str"; "stru"; "str"; 1; "str"; null; "str"; true; } $i = 0; while ($i < 10000000) { $i = $i + 1; - - 1 == 1; 1 == 2; 1 == null; 1 == "str"; 1 == true; - null == null; null == 1; null == "str"; null == true; - true == true; true == 1; true == false; true == "str"; true == null; - "str" == "str"; "str" == "stru"; "str" == 1; "str" == null; "str" == true; } diff --git a/lykiadb-server/benches/scripts/while.short.ly b/lykiadb-server/benches/scripts/while.short.ly index 61c9af68..1b557a60 100644 --- a/lykiadb-server/benches/scripts/while.short.ly +++ b/lykiadb-server/benches/scripts/while.short.ly @@ -2,9 +2,4 @@ var $i = 0; while ($i < 10000000) { $i = $i + 1; - - 1; 1; 1; 2; 1; null; 1; "str"; 1; true; - null; null; null; 1; null; "str"; null; true; - true; true; true; 1; true; false; true; "str"; true; null; - "str"; "str"; "str"; "stru"; "str"; 1; "str"; null; "str"; true; } \ No newline at end of file diff --git a/lykiadb-server/src/engine/interpreter.rs b/lykiadb-server/src/engine/interpreter.rs index e0a72afe..56b66b94 100644 --- a/lykiadb-server/src/engine/interpreter.rs +++ b/lykiadb-server/src/engine/interpreter.rs @@ -200,7 +200,7 @@ impl Interpreter { if let Some(num) = self.visit_expr(expr)?.as_number() { return Ok(RV::Num(-num)); } - Ok(RV::NaN) + Ok(RV::Undefined) } else { Ok(RV::Bool(!self.visit_expr(expr)?.as_bool())) } @@ -276,8 +276,6 @@ impl Interpreter { Literal::Num(n) => RV::Num(*n), Literal::Bool(b) => RV::Bool(*b), Literal::Undefined => RV::Undefined, - Literal::NaN => RV::NaN, - Literal::Null => RV::Null, Literal::Object(map) => { let mut new_map = FxHashMap::default(); for (k, v) in map.iter() { diff --git a/lykiadb-server/src/engine/stdlib/json.rs b/lykiadb-server/src/engine/stdlib/json.rs index 4d8491fc..b247bb5d 100644 --- a/lykiadb-server/src/engine/stdlib/json.rs +++ b/lykiadb-server/src/engine/stdlib/json.rs @@ -70,7 +70,7 @@ mod tests { ); assert_eq!( - nt_json_encode(&mut interpreter, &[RV::Null]).unwrap(), + nt_json_encode(&mut interpreter, &[RV::Undefined]).unwrap(), RV::Str(Arc::new("null".to_string())) ); @@ -121,7 +121,7 @@ mod tests { assert_eq!( nt_json_decode(&mut interpreter, &[RV::Str(Arc::new("null".to_string()))]).unwrap(), - RV::Null + RV::Undefined ); // Test array diff --git a/lykiadb-server/src/value/datatype.rs b/lykiadb-server/src/value/datatype.rs new file mode 100644 index 00000000..e4815b5d --- /dev/null +++ b/lykiadb-server/src/value/datatype.rs @@ -0,0 +1,11 @@ +use rustc_hash::FxHashMap; + +pub enum Datatype { + Str, + Num, + Bool, + Composite(FxHashMap), + Array(Box), + Callable, + Undefined +} diff --git a/lykiadb-server/src/value/eval.rs b/lykiadb-server/src/value/eval.rs index 5b734ec2..4a62df30 100644 --- a/lykiadb-server/src/value/eval.rs +++ b/lykiadb-server/src/value/eval.rs @@ -7,14 +7,8 @@ impl PartialEq for RV { fn eq(&self, other: &Self) -> bool { match (self, other) { (RV::Array(_), RV::Array(_)) | (RV::Object(_), RV::Object(_)) => false, - (RV::Null, RV::Null) => true, (RV::Undefined, RV::Undefined) => true, - (RV::NaN, RV::NaN) => true, - (RV::Null, RV::Undefined) => true, - (RV::Undefined, RV::Null) => true, // - (RV::NaN, _) | (_, RV::NaN) => false, - (RV::Null, _) | (_, RV::Null) => false, (RV::Undefined, _) | (_, RV::Undefined) => false, // (RV::Str(a), RV::Str(b)) => a == b, @@ -39,14 +33,8 @@ impl PartialOrd for RV { fn partial_cmp(&self, other: &Self) -> Option { match (self, other) { (RV::Array(_), RV::Array(_)) | (RV::Object(_), RV::Object(_)) => None, - (RV::Null, RV::Null) => Some(std::cmp::Ordering::Equal), (RV::Undefined, RV::Undefined) => Some(std::cmp::Ordering::Equal), - (RV::NaN, RV::NaN) => Some(std::cmp::Ordering::Equal), - (RV::Null, RV::Undefined) => Some(std::cmp::Ordering::Equal), - (RV::Undefined, RV::Null) => Some(std::cmp::Ordering::Equal), // - (RV::NaN, _) | (_, RV::NaN) => None, - (RV::Null, _) | (_, RV::Null) => None, (RV::Undefined, _) | (_, RV::Undefined) => None, // (RV::Str(a), RV::Str(b)) => Some(a.cmp(b)), @@ -82,7 +70,6 @@ impl ops::Add for RV { fn add(self, rhs: Self) -> Self::Output { match (&self, &rhs) { - (RV::NaN, _) | (_, RV::NaN) => RV::NaN, // (RV::Bool(_), RV::Bool(_)) | (RV::Num(_), RV::Bool(_)) | (RV::Bool(_), RV::Num(_)) => { RV::Num(self.as_number().unwrap() + rhs.as_number().unwrap()) @@ -98,7 +85,7 @@ impl ops::Add for RV { (RV::Str(s), RV::Bool(bool)) => RV::Str(Arc::new(s.to_string() + &bool.to_string())), (RV::Bool(bool), RV::Str(s)) => RV::Str(Arc::new(bool.to_string() + &s.to_string())), // - (_, _) => RV::NaN, + (_, _) => RV::Undefined, } } } @@ -108,14 +95,12 @@ impl ops::Sub for RV { fn sub(self, rhs: Self) -> Self::Output { match (self, rhs) { - (RV::Undefined, _) | (_, RV::Undefined) => RV::NaN, - (RV::NaN, _) | (_, RV::NaN) => RV::NaN, - (RV::Null, _) | (_, RV::Null) => RV::Num(0.0), + (RV::Undefined, _) | (_, RV::Undefined) => RV::Undefined, (l, r) => l .as_number() .and_then(|a| r.as_number().map(|b| (a, b))) .map(|(a, b)| RV::Num(a - b)) - .unwrap_or(RV::NaN), + .unwrap_or(RV::Undefined), } } } @@ -125,14 +110,12 @@ impl ops::Mul for RV { fn mul(self, rhs: Self) -> Self::Output { match (self, rhs) { - (RV::Undefined, _) | (_, RV::Undefined) => RV::NaN, - (RV::NaN, _) | (_, RV::NaN) => RV::NaN, - (RV::Null, _) | (_, RV::Null) => RV::Num(0.0), + (RV::Undefined, _) | (_, RV::Undefined) => RV::Undefined, (l, r) => l .as_number() .and_then(|a| r.as_number().map(|b| (a, b))) .map(|(a, b)| RV::Num(a * b)) - .unwrap_or(RV::NaN), + .unwrap_or(RV::Undefined), } } } @@ -142,20 +125,18 @@ impl ops::Div for RV { fn div(self, rhs: Self) -> Self::Output { match (self, rhs) { - (RV::Undefined, _) | (_, RV::Undefined) => RV::NaN, - (RV::NaN, _) | (_, RV::NaN) => RV::NaN, - (RV::Null, _) | (_, RV::Null) => RV::Num(0.0), + (RV::Undefined, _) | (_, RV::Undefined) => RV::Undefined, (l, r) => l .as_number() .and_then(|a| r.as_number().map(|b| (a, b))) .map(|(a, b)| { if a == 0.0 && b == 0.0 { - RV::NaN + RV::Undefined } else { RV::Num(a / b) } }) - .unwrap_or(RV::NaN), + .unwrap_or(RV::Undefined), } } } @@ -204,9 +185,7 @@ mod test { #[test] fn test_is_value_truthy() { - assert!(!(RV::Null).as_bool()); assert!(!(RV::Undefined).as_bool()); - assert!(!(RV::NaN).as_bool()); assert!(!(RV::Bool(false)).as_bool()); assert!((RV::Bool(true)).as_bool()); assert!(!(RV::Num(0.0)).as_bool()); @@ -361,7 +340,7 @@ mod test { RV::Str(Arc::new("b".to_string())), Operation::Subtract ), - RV::NaN + RV::Undefined ); assert_eq!( eval_binary( @@ -369,7 +348,7 @@ mod test { RV::Str(Arc::new("a".to_string())), Operation::Subtract ), - RV::NaN + RV::Undefined ); } @@ -432,7 +411,7 @@ mod test { RV::Str(Arc::new("b".to_string())), Operation::Multiply ), - RV::NaN + RV::Undefined ); assert_eq!( eval_binary( @@ -440,7 +419,7 @@ mod test { RV::Str(Arc::new("a".to_string())), Operation::Multiply ), - RV::NaN + RV::Undefined ); } @@ -471,7 +450,7 @@ mod test { // assert_eq!( eval_binary(RV::Bool(false), RV::Bool(false), Operation::Divide), - RV::NaN + RV::Undefined ); // assert_eq!( @@ -503,7 +482,7 @@ mod test { RV::Str(Arc::new("b".to_string())), Operation::Divide ), - RV::NaN + RV::Undefined ); assert_eq!( eval_binary( @@ -511,7 +490,7 @@ mod test { RV::Str(Arc::new("a".to_string())), Operation::Divide ), - RV::NaN + RV::Undefined ); } @@ -1029,78 +1008,78 @@ mod test { #[test] fn test_eval_binary_nan() { - assert_eq!(eval_binary(RV::NaN, RV::Num(1.0), Operation::Add), RV::NaN); - assert_eq!(eval_binary(RV::Num(1.0), RV::NaN, Operation::Add), RV::NaN); + assert_eq!(eval_binary(RV::Undefined, RV::Num(1.0), Operation::Add), RV::Undefined); + assert_eq!(eval_binary(RV::Num(1.0), RV::Undefined, Operation::Add), RV::Undefined); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::Subtract), - RV::NaN + eval_binary(RV::Undefined, RV::Num(1.0), Operation::Subtract), + RV::Undefined ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::Subtract), - RV::NaN + eval_binary(RV::Num(1.0), RV::Undefined, Operation::Subtract), + RV::Undefined ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::Multiply), - RV::NaN + eval_binary(RV::Undefined, RV::Num(1.0), Operation::Multiply), + RV::Undefined ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::Multiply), - RV::NaN + eval_binary(RV::Num(1.0), RV::Undefined, Operation::Multiply), + RV::Undefined ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::Divide), - RV::NaN + eval_binary(RV::Undefined, RV::Num(1.0), Operation::Divide), + RV::Undefined ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::Divide), - RV::NaN + eval_binary(RV::Num(1.0), RV::Undefined, Operation::Divide), + RV::Undefined ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::IsEqual), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::IsEqual), RV::Bool(false) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::IsEqual), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::IsEqual), RV::Bool(false) ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::IsNotEqual), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::IsNotEqual), RV::Bool(true) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::IsNotEqual), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::IsNotEqual), RV::Bool(true) ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::Less), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::Less), RV::Bool(false) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::Less), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::Less), RV::Bool(false) ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::LessEqual), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::LessEqual), RV::Bool(false) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::LessEqual), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::LessEqual), RV::Bool(false) ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::Greater), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::Greater), RV::Bool(false) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::Greater), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::Greater), RV::Bool(false) ); assert_eq!( - eval_binary(RV::NaN, RV::Num(1.0), Operation::GreaterEqual), + eval_binary(RV::Undefined, RV::Num(1.0), Operation::GreaterEqual), RV::Bool(false) ); assert_eq!( - eval_binary(RV::Num(1.0), RV::NaN, Operation::GreaterEqual), + eval_binary(RV::Num(1.0), RV::Undefined, Operation::GreaterEqual), RV::Bool(false) ); } diff --git a/lykiadb-server/src/value/mod.rs b/lykiadb-server/src/value/mod.rs index 5d0b29a9..69634150 100644 --- a/lykiadb-server/src/value/mod.rs +++ b/lykiadb-server/src/value/mod.rs @@ -11,6 +11,7 @@ use callable::Callable; pub mod callable; pub mod environment; pub mod eval; +pub mod datatype; #[derive(Debug, Clone)] pub enum RV { @@ -20,9 +21,7 @@ pub enum RV { Object(Shared>), Array(Shared>), Callable(Callable), - Undefined, - NaN, - Null, + Undefined } impl RV { @@ -31,7 +30,7 @@ impl RV { RV::Num(value) => !value.is_nan() && value.abs() > 0.0, RV::Str(value) => !value.is_empty(), RV::Bool(value) => *value, - RV::Null | RV::Undefined | RV::NaN => false, + RV::Undefined => false, _ => true, } } @@ -95,8 +94,6 @@ impl Display for RV { RV::Num(n) => write!(f, "{}", n), RV::Bool(b) => write!(f, "{}", b), RV::Undefined => write!(f, "undefined"), - RV::NaN => write!(f, "NaN"), - RV::Null => write!(f, "null"), RV::Array(arr) => { let arr = (arr as &RwLock>).read().unwrap(); write!(f, "[")?; @@ -134,8 +131,6 @@ impl Serialize for RV { RV::Num(n) => serializer.serialize_f64(*n), RV::Bool(b) => serializer.serialize_bool(*b), RV::Undefined => serializer.serialize_none(), - RV::NaN => serializer.serialize_none(), - RV::Null => serializer.serialize_none(), RV::Array(arr) => { let mut seq = serializer.serialize_seq(None).unwrap(); let arr = (arr as &RwLock>).read().unwrap(); @@ -181,7 +176,7 @@ impl<'de> Deserialize<'de> for RV { } Ok(RV::Object(alloc_shared(map))) } - serde_json::Value::Null => Ok(RV::Null), + serde_json::Value::Null => Ok(RV::Undefined), } } } @@ -208,9 +203,7 @@ mod tests { assert!(!RV::Bool(false).as_bool()); // Test special values - assert!(!RV::Null.as_bool()); assert!(!RV::Undefined.as_bool()); - assert!(!RV::NaN.as_bool()); // Test collections let empty_array = RV::Array(alloc_shared(Vec::new())); @@ -240,9 +233,7 @@ mod tests { assert_eq!(RV::Str(Arc::new("".to_string())).as_number(), None); // Test other types - assert_eq!(RV::Null.as_number(), None); assert_eq!(RV::Undefined.as_number(), None); - assert_eq!(RV::NaN.as_number(), None); assert_eq!(RV::Array(alloc_shared(Vec::new())).as_number(), None); assert_eq!( RV::Object(alloc_shared(FxHashMap::default())).as_number(), @@ -297,9 +288,7 @@ mod tests { RV::Str(Arc::new("hello".to_string())).not(), RV::Bool(false) ); - assert_eq!(RV::Null.not(), RV::Bool(true)); assert_eq!(RV::Undefined.not(), RV::Bool(true)); - assert_eq!(RV::NaN.not(), RV::Bool(true)); } #[test] @@ -309,8 +298,6 @@ mod tests { assert_eq!(RV::Bool(true).to_string(), "true"); assert_eq!(RV::Bool(false).to_string(), "false"); assert_eq!(RV::Undefined.to_string(), "undefined"); - assert_eq!(RV::NaN.to_string(), "NaN"); - assert_eq!(RV::Null.to_string(), "null"); let arr = vec![RV::Num(1.0), RV::Str(Arc::new("test".to_string()))]; assert_eq!(RV::Array(alloc_shared(arr)).to_string(), "[1, test]"); diff --git a/lykiadb-server/tests/interpreter/expr b/lykiadb-server/tests/interpreter/expr index ee664f8c..bede4e73 100644 --- a/lykiadb-server/tests/interpreter/expr +++ b/lykiadb-server/tests/interpreter/expr @@ -98,13 +98,13 @@ Interpret(PropertyNotFound { span: Span { start: 16, end: 28, line: 0, line_end: ---> -test_utils::out(null.prop); +test_utils::out(undefined.prop); ---err Interpret(PropertyNotFound { span: Span { start: 50, end: 58, line: 4, line_end: 4 }, property: "age" }) Interpret(PropertyNotFound { span: Span { start: 16, end: 28, line: 0, line_end: 0 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) ---> @@ -114,7 +114,7 @@ test_utils::out(5.prop); Interpret(PropertyNotFound { span: Span { start: 50, end: 58, line: 4, line_end: 4 }, property: "age" }) Interpret(PropertyNotFound { span: Span { start: 16, end: 28, line: 0, line_end: 0 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) Interpret(Other { message: "Only objects have properties. Num(5.0) is not an object" }) ---> @@ -125,7 +125,7 @@ test_utils::out("string".length); Interpret(PropertyNotFound { span: Span { start: 50, end: 58, line: 4, line_end: 4 }, property: "age" }) Interpret(PropertyNotFound { span: Span { start: 16, end: 28, line: 0, line_end: 0 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) Interpret(Other { message: "Only objects have properties. Num(5.0) is not an object" }) Interpret(Other { message: "Only objects have properties. Str(\"string\") is not an object" }) @@ -174,12 +174,12 @@ Interpret(PropertyNotFound { span: Span { start: 34, end: 46, line: 4, line_end: ---> -null.prop = "test"; +undefined.prop = "test"; ---err Interpret(PropertyNotFound { span: Span { start: 34, end: 46, line: 4, line_end: 4 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) ---> @@ -188,7 +188,7 @@ Interpret(Other { message: "Only objects have properties. Null is not an object" ---err Interpret(PropertyNotFound { span: Span { start: 34, end: 46, line: 4, line_end: 4 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) Interpret(Other { message: "Only objects have properties. Num(5.0) is not an object" }) ---> @@ -198,7 +198,7 @@ Interpret(Other { message: "Only objects have properties. Num(5.0) is not an obj ---err Interpret(PropertyNotFound { span: Span { start: 34, end: 46, line: 4, line_end: 4 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) Interpret(Other { message: "Only objects have properties. Num(5.0) is not an object" }) Interpret(Other { message: "Only objects have properties. Str(\"string\") is not an object" }) @@ -209,7 +209,7 @@ undefined.prop = "test"; ---err Interpret(PropertyNotFound { span: Span { start: 34, end: 46, line: 4, line_end: 4 }, property: "address" }) -Interpret(Other { message: "Only objects have properties. Null is not an object" }) +Interpret(Other { message: "Only objects have properties. Undefined is not an object" }) Interpret(Other { message: "Only objects have properties. Num(5.0) is not an object" }) Interpret(Other { message: "Only objects have properties. Str(\"string\") is not an object" }) Interpret(Other { message: "Only objects have properties. Undefined is not an object" })