Skip to content

Commit

Permalink
fix: Refactored CallableKind
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Sep 29, 2024
1 parent 66a06f5 commit 35da50b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lykiadb-server/src/engine/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::error::ExecutionError;

use crate::plan::planner::Planner;
use crate::util::{alloc_shared, Shared};
use crate::value::callable::{Callable, CallableType, Function, Stateful};
use crate::value::callable::{Callable, CallableKind, Function, Stateful};
use crate::value::environment::{EnvId, Environment};
use crate::value::types::{eval_binary, RV};

Expand Down Expand Up @@ -466,7 +466,7 @@ impl VisitorMut<RV, HaltReason> for Interpreter {
closure: self.env,
};

let callable = RV::Callable(Callable::new(Some(parameters.len()), CallableType::Any, fun.into()));
let callable = RV::Callable(Callable::new(Some(parameters.len()), CallableKind::Generic, fun.into()));

if name.is_some() {
// TODO(vck): Callable shouldn't be cloned here
Expand Down
16 changes: 7 additions & 9 deletions lykiadb-server/src/engine/stdlib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::sync::Arc;

use rustc_hash::FxHashMap;

use crate::{
util::{alloc_shared, Shared},
value::{callable::{Callable, CallableType, Function}, types::RV},
value::{callable::{Callable, CallableKind, Function}, types::RV},
};

use self::{
Expand All @@ -30,15 +28,15 @@ pub fn stdlib(out: Option<Shared<Output>>) -> FxHashMap<String, RV> {

benchmark_namespace.insert(
"fib".to_owned(),
RV::Callable(Callable::new(Some(1), CallableType::Any, Function::Lambda { function: nt_fib })),
RV::Callable(Callable::new(Some(1), CallableKind::Generic, Function::Lambda { function: nt_fib })),
);

json_namespace.insert(
"stringify".to_owned(),
RV::Callable(
Callable::new(
Some(1),
CallableType::Any,
CallableKind::Generic,
Function::Lambda {
function: nt_json_encode,
}
Expand All @@ -50,7 +48,7 @@ pub fn stdlib(out: Option<Shared<Output>>) -> FxHashMap<String, RV> {
"parse".to_owned(),
RV::Callable(Callable::new(
Some(1),
CallableType::Any,
CallableKind::Generic,
Function::Lambda {
function: nt_json_decode,
}),
Expand All @@ -61,7 +59,7 @@ pub fn stdlib(out: Option<Shared<Output>>) -> FxHashMap<String, RV> {
"clock".to_owned(),
RV::Callable(Callable::new(
Some(0),
CallableType::Any,
CallableKind::Generic,
Function::Lambda { function: nt_clock }
)),
);
Expand All @@ -71,7 +69,7 @@ pub fn stdlib(out: Option<Shared<Output>>) -> FxHashMap<String, RV> {

test_namespace.insert(
"out".to_owned(),
RV::Callable(Callable::new(None, CallableType::Any, Function::Stateful(out.unwrap().clone()))),
RV::Callable(Callable::new(None, CallableKind::Generic, Function::Stateful(out.unwrap().clone()))),
);

std.insert(
Expand All @@ -88,7 +86,7 @@ pub fn stdlib(out: Option<Shared<Output>>) -> FxHashMap<String, RV> {
std.insert("Time".to_owned(), RV::Object(alloc_shared(time_namespace)));
std.insert(
"print".to_owned(),
RV::Callable(Callable::new(None, CallableType::Any, Function::Lambda { function: nt_print })),
RV::Callable(Callable::new(None, CallableKind::Generic, Function::Lambda { function: nt_print })),
);

std
Expand Down
10 changes: 5 additions & 5 deletions lykiadb-server/src/value/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ use super::environment::EnvId;
use super::types::RV;

#[derive(Debug, Clone)]
pub enum CallableType {
Any,
pub enum CallableKind {
Generic,
Aggregator,
}

#[derive(Clone, Debug)]
pub struct Callable {
pub arity: Option<usize>,
pub call_type: CallableType,
pub kind: CallableKind,
pub function: Arc<Function>,
}

impl Callable {
pub fn new(arity: Option<usize>, call_type: CallableType, function: Function) -> Self {
pub fn new(arity: Option<usize>, call_type: CallableKind, function: Function) -> Self {
Callable {
arity,
call_type,
kind: call_type,
function: Arc::new(function),
}
}
Expand Down

0 comments on commit 35da50b

Please sign in to comment.