get the vm basically working!
This commit is contained in:
parent
740b14f9da
commit
0875ec2ab5
|
@ -43,7 +43,7 @@ mod vm;
|
||||||
use crate::vm::*;
|
use crate::vm::*;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let src = "(1, :two, nil)";
|
let src = "[1, 2, 3]";
|
||||||
let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
|
let (tokens, lex_errs) = lexer().parse(src).into_output_errors();
|
||||||
if lex_errs.len() > 0 {
|
if lex_errs.len() > 0 {
|
||||||
println!("{:?}", lex_errs);
|
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::Nil => Ok(Value::Nil),
|
||||||
Ast::Boolean(b) => Ok(Value::Boolean(*b)),
|
Ast::Boolean(b) => Ok(Value::Boolean(*b)),
|
||||||
Ast::Number(n) => Ok(Value::Number(*n)),
|
Ast::Number(n) => Ok(Value::Number(*n)),
|
||||||
Ast::Keyword(k) => Ok(Value::Keyword(k.clone())),
|
Ast::Keyword(k) => Ok(Value::Keyword(k)),
|
||||||
Ast::String(s) => Ok(Value::String(s.clone())),
|
Ast::String(s) => Ok(Value::String(s)),
|
||||||
Ast::Block(exprs) => {
|
Ast::Block(exprs) => {
|
||||||
let mut result = Value::Nil;
|
let mut result = Value::Nil;
|
||||||
for (expr, _) in exprs {
|
for (expr, _) in exprs {
|
||||||
|
@ -55,11 +55,9 @@ pub fn eval<'src, 'a>(
|
||||||
Ast::If(cond, if_true, if_false) => {
|
Ast::If(cond, if_true, if_false) => {
|
||||||
let truthy = eval(&cond.0, ctx)?.bool();
|
let truthy = eval(&cond.0, ctx)?.bool();
|
||||||
if truthy {
|
if truthy {
|
||||||
let (if_true, _) = *if_true;
|
eval(&if_true.0, ctx)
|
||||||
eval(&if_true, ctx)
|
|
||||||
} else {
|
} else {
|
||||||
let (if_false, _) = **if_false;
|
eval(&if_false.0, ctx)
|
||||||
eval(&if_false, ctx)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ast::List(members) => {
|
Ast::List(members) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user