From fb66d9fce3365f888c08e67623b73f02e8721def Mon Sep 17 00:00:00 2001 From: Vedat Can Keklik Date: Sun, 29 Sep 2024 14:17:00 +0300 Subject: [PATCH] fix: Value reorg --- lykiadb-server/src/comm/mod.rs | 2 +- lykiadb-server/src/engine/interpreter.rs | 6 +++--- lykiadb-server/src/engine/mod.rs | 2 +- lykiadb-server/src/engine/stdlib/fib.rs | 2 +- lykiadb-server/src/engine/stdlib/json.rs | 2 +- lykiadb-server/src/engine/stdlib/mod.rs | 2 +- lykiadb-server/src/engine/stdlib/out.rs | 2 +- lykiadb-server/src/engine/stdlib/time.rs | 2 +- lykiadb-server/src/value/callable.rs | 2 +- lykiadb-server/src/value/environment.rs | 4 ++-- lykiadb-server/src/value/mod.rs | 21 ++++++++++++++++++++- lykiadb-server/src/value/types.rs | 20 ++------------------ lykiadb-server/tests/runtime/blocks.rs | 2 +- lykiadb-server/tests/runtime/functions.rs | 2 +- lykiadb-server/tests/runtime/ifs.rs | 2 +- lykiadb-server/tests/runtime/loops.rs | 2 +- 16 files changed, 39 insertions(+), 36 deletions(-) diff --git a/lykiadb-server/src/comm/mod.rs b/lykiadb-server/src/comm/mod.rs index 6002ce91..513ec498 100644 --- a/lykiadb-server/src/comm/mod.rs +++ b/lykiadb-server/src/comm/mod.rs @@ -1,5 +1,5 @@ use crate::engine::{Runtime, RuntimeMode}; -use crate::value::types::RV; +use crate::value::RV; use ::std::time::Instant; use tcp::TcpConnection; use tokio::net::TcpStream; diff --git a/lykiadb-server/src/engine/interpreter.rs b/lykiadb-server/src/engine/interpreter.rs index 0d7b6964..7869d8fe 100644 --- a/lykiadb-server/src/engine/interpreter.rs +++ b/lykiadb-server/src/engine/interpreter.rs @@ -17,7 +17,7 @@ use crate::plan::planner::Planner; use crate::util::{alloc_shared, Shared}; use crate::value::callable::{Callable, CallableKind, Function, Stateful}; use crate::value::environment::{EnvId, Environment}; -use crate::value::types::{eval_binary, RV}; +use crate::value::{RV, types::eval_binary}; use std::sync::Arc; use std::vec; @@ -706,7 +706,7 @@ impl Stateful for Output { pub mod test_helpers { use crate::engine::{Runtime, RuntimeMode}; use crate::util::{alloc_shared, Shared}; - use crate::value::types::RV; + use crate::value::RV; use super::Output; @@ -725,7 +725,7 @@ pub mod test_helpers { #[cfg(test)] mod test { - use crate::value::types::RV; + use crate::value::RV; use super::test_helpers::get_runtime; diff --git a/lykiadb-server/src/engine/mod.rs b/lykiadb-server/src/engine/mod.rs index 03f0d165..e8021478 100644 --- a/lykiadb-server/src/engine/mod.rs +++ b/lykiadb-server/src/engine/mod.rs @@ -4,7 +4,7 @@ use self::stdlib::stdlib; use crate::engine::interpreter::Interpreter; use crate::util::{alloc_shared, Shared}; use crate::value::environment::Environment; -use crate::value::types::RV; +use crate::value::RV; use lykiadb_lang::parser::Parser; use lykiadb_lang::tokenizer::scanner::Scanner; use serde_json::Value; diff --git a/lykiadb-server/src/engine/stdlib/fib.rs b/lykiadb-server/src/engine/stdlib/fib.rs index 9c73b078..5eb6658e 100644 --- a/lykiadb-server/src/engine/stdlib/fib.rs +++ b/lykiadb-server/src/engine/stdlib/fib.rs @@ -1,6 +1,6 @@ use crate::{ engine::interpreter::{HaltReason, InterpretError, Interpreter}, - value::types::RV, + value::RV, }; fn _calculate(n: f64) -> f64 { diff --git a/lykiadb-server/src/engine/stdlib/json.rs b/lykiadb-server/src/engine/stdlib/json.rs index 63df62d5..222d2a32 100644 --- a/lykiadb-server/src/engine/stdlib/json.rs +++ b/lykiadb-server/src/engine/stdlib/json.rs @@ -1,6 +1,6 @@ use crate::{ engine::interpreter::{HaltReason, InterpretError, Interpreter}, - value::types::RV, + value::RV, }; use serde_json::json; use std::sync::Arc; diff --git a/lykiadb-server/src/engine/stdlib/mod.rs b/lykiadb-server/src/engine/stdlib/mod.rs index 908b7323..8722b807 100644 --- a/lykiadb-server/src/engine/stdlib/mod.rs +++ b/lykiadb-server/src/engine/stdlib/mod.rs @@ -2,7 +2,7 @@ use rustc_hash::FxHashMap; use crate::{ util::{alloc_shared, Shared}, - value::{callable::{Callable, CallableKind, Function}, types::RV}, + value::{callable::{Callable, CallableKind, Function}, RV}, }; use self::{ diff --git a/lykiadb-server/src/engine/stdlib/out.rs b/lykiadb-server/src/engine/stdlib/out.rs index e9ff7157..73994d0c 100644 --- a/lykiadb-server/src/engine/stdlib/out.rs +++ b/lykiadb-server/src/engine/stdlib/out.rs @@ -1,6 +1,6 @@ use crate::{ engine::interpreter::{HaltReason, Interpreter}, - value::types::RV, + value::RV, }; pub fn nt_print(_interpreter: &mut Interpreter, args: &[RV]) -> Result { diff --git a/lykiadb-server/src/engine/stdlib/time.rs b/lykiadb-server/src/engine/stdlib/time.rs index cf38773f..c8dbec0f 100644 --- a/lykiadb-server/src/engine/stdlib/time.rs +++ b/lykiadb-server/src/engine/stdlib/time.rs @@ -1,5 +1,5 @@ use crate::engine::interpreter::{HaltReason, Interpreter}; -use crate::value::types::RV; +use crate::value::RV; use std::time; pub fn nt_clock(_interpreter: &mut Interpreter, _args: &[RV]) -> Result { diff --git a/lykiadb-server/src/value/callable.rs b/lykiadb-server/src/value/callable.rs index 65137f31..88a7a8a0 100644 --- a/lykiadb-server/src/value/callable.rs +++ b/lykiadb-server/src/value/callable.rs @@ -3,7 +3,7 @@ use std::fmt::{Debug, Display, Formatter}; use lykiadb_lang::ast::stmt::Stmt; use crate::{engine::interpreter::{HaltReason, Interpreter}, util::Shared}; use super::environment::EnvId; -use super::types::RV; +use super::RV; #[derive(Debug, Clone)] pub enum CallableKind { diff --git a/lykiadb-server/src/value/environment.rs b/lykiadb-server/src/value/environment.rs index 2d510c6c..4fdd2a05 100644 --- a/lykiadb-server/src/value/environment.rs +++ b/lykiadb-server/src/value/environment.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap; use serde::{Deserialize, Serialize}; use std::borrow::{Borrow, BorrowMut}; -use super::types::RV; +use super::RV; #[repr(transparent)] #[derive(Debug, Eq, PartialEq, Clone, Copy)] @@ -169,7 +169,7 @@ impl Environment { #[cfg(test)] mod test { - use crate::value::types::RV; + use crate::value::RV; #[test] fn test_read_basic() { diff --git a/lykiadb-server/src/value/mod.rs b/lykiadb-server/src/value/mod.rs index bf7d3a44..eb7d8a89 100644 --- a/lykiadb-server/src/value/mod.rs +++ b/lykiadb-server/src/value/mod.rs @@ -1,3 +1,22 @@ +use std::sync::Arc; + +use callable::Callable; +use rustc_hash::FxHashMap; + +use crate::util::Shared; + pub mod environment; pub mod types; -pub mod callable; \ No newline at end of file +pub mod callable; +#[derive(Debug, Clone)] +pub enum RV { + Str(Arc), + Num(f64), + Bool(bool), + Object(Shared>), + Array(Shared>), + Callable(Callable), + Undefined, + NaN, + Null, +} \ No newline at end of file diff --git a/lykiadb-server/src/value/types.rs b/lykiadb-server/src/value/types.rs index ffe5ce38..524bc4c1 100644 --- a/lykiadb-server/src/value/types.rs +++ b/lykiadb-server/src/value/types.rs @@ -2,26 +2,10 @@ use lykiadb_lang::ast::expr::Operation; use rustc_hash::FxHashMap; use serde::ser::{SerializeMap, SerializeSeq}; use serde::{Deserialize, Serialize}; -use std::fmt::Debug; use std::ops; use std::sync::{Arc, RwLock}; - -use crate::util::{alloc_shared, Shared}; - -use super::callable::Callable; - -#[derive(Debug, Clone)] -pub enum RV { - Str(Arc), - Num(f64), - Bool(bool), - Object(Shared>), - Array(Shared>), - Callable(Callable), - Undefined, - NaN, - Null, -} +use crate::util::alloc_shared; +use super::RV; impl Serialize for RV { fn serialize(&self, serializer: S) -> Result diff --git a/lykiadb-server/tests/runtime/blocks.rs b/lykiadb-server/tests/runtime/blocks.rs index faae0d4d..bd546ac0 100644 --- a/lykiadb-server/tests/runtime/blocks.rs +++ b/lykiadb-server/tests/runtime/blocks.rs @@ -6,7 +6,7 @@ use lykiadb_server::{ InterpretError, }, }, - value::types::RV, + value::RV, }; use std::sync::Arc; diff --git a/lykiadb-server/tests/runtime/functions.rs b/lykiadb-server/tests/runtime/functions.rs index 773299d7..7fb59d28 100644 --- a/lykiadb-server/tests/runtime/functions.rs +++ b/lykiadb-server/tests/runtime/functions.rs @@ -1,6 +1,6 @@ use lykiadb_server::{ engine::interpreter::test_helpers::{exec_assert, get_runtime}, - value::types::RV, + value::RV, }; use std::sync::Arc; diff --git a/lykiadb-server/tests/runtime/ifs.rs b/lykiadb-server/tests/runtime/ifs.rs index 76e0c510..f3fbe6f3 100644 --- a/lykiadb-server/tests/runtime/ifs.rs +++ b/lykiadb-server/tests/runtime/ifs.rs @@ -1,4 +1,4 @@ -use lykiadb_server::{engine::interpreter::test_helpers::exec_assert, value::types::RV}; +use lykiadb_server::{engine::interpreter::test_helpers::exec_assert, value::RV}; use std::sync::Arc; #[test] diff --git a/lykiadb-server/tests/runtime/loops.rs b/lykiadb-server/tests/runtime/loops.rs index 961c927e..a06cc646 100644 --- a/lykiadb-server/tests/runtime/loops.rs +++ b/lykiadb-server/tests/runtime/loops.rs @@ -1,4 +1,4 @@ -use lykiadb_server::{engine::interpreter::test_helpers::exec_assert, value::types::RV}; +use lykiadb_server::{engine::interpreter::test_helpers::exec_assert, value::RV}; use std::sync::Arc;