From 0875ec2ab532444a1253e288b6534502f5f35477 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Wed, 6 Nov 2024 18:28:29 -0500 Subject: [PATCH] get the vm basically working! --- src/main.rs | 2 +- src/vm.rs | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce1cf8c..23abaa5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,7 +43,7 @@ mod vm; use crate::vm::*; pub fn main() { - let src = "(1, :two, nil)"; + let src = "[1, 2, 3]"; let (tokens, lex_errs) = lexer().parse(src).into_output_errors(); if lex_errs.len() > 0 { println!("{:?}", lex_errs); diff --git a/src/vm.rs b/src/vm.rs index abea333..69d5cc4 100644 --- a/src/vm.rs +++ b/src/vm.rs @@ -43,8 +43,8 @@ pub fn eval<'src, 'a>( Ast::Nil => Ok(Value::Nil), Ast::Boolean(b) => Ok(Value::Boolean(*b)), Ast::Number(n) => Ok(Value::Number(*n)), - Ast::Keyword(k) => Ok(Value::Keyword(k.clone())), - Ast::String(s) => Ok(Value::String(s.clone())), + Ast::Keyword(k) => Ok(Value::Keyword(k)), + Ast::String(s) => Ok(Value::String(s)), Ast::Block(exprs) => { let mut result = Value::Nil; for (expr, _) in exprs { @@ -55,11 +55,9 @@ pub fn eval<'src, 'a>( Ast::If(cond, if_true, if_false) => { let truthy = eval(&cond.0, ctx)?.bool(); if truthy { - let (if_true, _) = *if_true; - eval(&if_true, ctx) + eval(&if_true.0, ctx) } else { - let (if_false, _) = **if_false; - eval(&if_false, ctx) + eval(&if_false.0, ctx) } } Ast::List(members) => {