Skip to content

Commit

Permalink
fix: Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
can-keklik committed Jun 27, 2024
1 parent 946893e commit 43bf988
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 32 deletions.
36 changes: 11 additions & 25 deletions lykiadb-server/src/engine/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ pub struct SourceProcessor {

impl SourceProcessor {
pub fn new() -> SourceProcessor {
SourceProcessor { scopes: vec![], locals: FxHashMap::default() }
SourceProcessor {
scopes: vec![],
locals: FxHashMap::default(),
}
}

pub fn process(&mut self, source: &str) -> Result<Program, ExecutionError> {
Expand Down Expand Up @@ -176,7 +179,7 @@ impl Interpreter {
root_env: env,
loop_stack: LoopStack::new(),
source_processor: SourceProcessor::new(),
current_program: None
current_program: None,
}
}

Expand All @@ -198,11 +201,7 @@ impl Interpreter {
}
}

fn eval_unary(
&mut self,
operation: &Operation,
expr: &Expr,
) -> Result<RV, HaltReason> {
fn eval_unary(&mut self, operation: &Operation, expr: &Expr) -> Result<RV, HaltReason> {
if *operation == Operation::Subtract {
if let Some(num) = self.visit_expr(expr)?.as_number() {
return Ok(RV::Num(-num));
Expand All @@ -225,11 +224,7 @@ impl Interpreter {
Ok(eval_binary(left_eval, right_eval, operation))
}

fn look_up_variable(
&self,
name: &str,
expr: &Expr,
) -> Result<RV, HaltReason> {
fn look_up_variable(&self, name: &str, expr: &Expr) -> Result<RV, HaltReason> {
let distance = self.current_program.clone().unwrap().get_distance(expr);
if let Some(unwrapped) = distance {
self.env_man
Expand Down Expand Up @@ -307,10 +302,7 @@ impl Interpreter {
RV::Object(alloc_shared(new_map))
}
Literal::Array(arr) => {
let collected = arr
.iter()
.map(|x| self.visit_expr(x).unwrap())
.collect();
let collected = arr.iter().map(|x| self.visit_expr(x).unwrap()).collect();
RV::Array(alloc_shared(collected))
}
}
Expand Down Expand Up @@ -341,9 +333,7 @@ impl VisitorMut<RV, HaltReason> for Interpreter {
right,
span: _,
} => self.eval_binary(left, right, *operation),
Expr::Variable { name, span: _, id } => {
self.look_up_variable(&name.name, e)
}
Expr::Variable { name, span: _, id } => self.look_up_variable(&name.name, e),
Expr::Assignment {
dst,
expr,
Expand Down Expand Up @@ -385,9 +375,7 @@ impl VisitorMut<RV, HaltReason> for Interpreter {
return Ok(RV::Bool(is_true));
}

Ok(RV::Bool(
self.visit_expr(right)?.as_bool(),
))
Ok(RV::Bool(self.visit_expr(right)?.as_bool()))
}
Expr::Call { callee, args, span } => {
let eval = self.visit_expr(callee)?;
Expand Down Expand Up @@ -552,9 +540,7 @@ impl VisitorMut<RV, HaltReason> for Interpreter {
self.loop_stack.push_loop(LoopState::Go);
while !self.loop_stack.is_loop_at(LoopState::Broken)
&& (condition.is_none()
|| self
.visit_expr(&condition.as_ref().unwrap())?
.as_bool())
|| self.visit_expr(&condition.as_ref().unwrap())?.as_bool())
{
self.visit_stmt(&body)?;
self.loop_stack
Expand Down
17 changes: 10 additions & 7 deletions lykiadb-server/src/lang/parser/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ impl<'a> Resolver<'a> {
pub fn resolve(
&mut self,
) -> Result<(Vec<FxHashMap<String, bool>>, FxHashMap<usize, usize>), ResolveError> {
self.visit_stmt((&self.program.get_root()))?;
self.visit_stmt(&self.program.get_root())?;
let scopes = self.scopes.clone();
let locals = self.locals.clone();
Ok((scopes, locals))
}

pub fn new(scopes: Vec<FxHashMap<String, bool>>, program: &'a Program, previous_locals: Option<FxHashMap<usize, usize>>) -> Resolver<'a> {
pub fn new(
scopes: Vec<FxHashMap<String, bool>>,
program: &'a Program,
previous_locals: Option<FxHashMap<usize, usize>>,
) -> Resolver<'a> {
Resolver {
scopes,
locals: if previous_locals.is_some() {
previous_locals.unwrap()
}
else {
} else {
FxHashMap::default()
},
program,
Expand All @@ -57,11 +60,11 @@ impl<'a> Resolver<'a> {
}

fn resolve_stmt(&mut self, statement: &Stmt) {
self.visit_stmt((&statement)).unwrap();
self.visit_stmt(&statement).unwrap();
}

fn resolve_expr(&mut self, expr: &Expr) {
self.visit_expr((expr)).unwrap();
self.visit_expr(expr).unwrap();
}

fn resolve_local(&mut self, expr_id: usize, name: &Identifier) {
Expand Down Expand Up @@ -105,7 +108,7 @@ impl<'a> VisitorMut<(), ResolveError> for Resolver<'a> {
}
Literal::Array(items) => {
for item in items {
self.visit_expr((item))?;
self.visit_expr(item)?;
}
}
_ => (),
Expand Down

0 comments on commit 43bf988

Please sign in to comment.