get the vm basically working!
This commit is contained in:
parent
740b14f9da
commit
0875ec2ab5
|
@ -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);
|
||||
|
|
10
src/vm.rs
10
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) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user