Add constructor reduced ast node; fix test
This commit is contained in:
parent
7809cda240
commit
3b9084810e
@ -325,7 +325,8 @@ mod eval_tests {
|
|||||||
let mut state = State::new(symbol_table);
|
let mut state = State::new(symbol_table);
|
||||||
let ast = parse(tokenize($string)).0.unwrap();
|
let ast = parse(tokenize($string)).0.unwrap();
|
||||||
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast);
|
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast);
|
||||||
let all_output = state.evaluate(ast.reduce(), true);
|
let reduced = ast.reduce(&state.symbol_table_handle.borrow());
|
||||||
|
let all_output = state.evaluate(reduced, true);
|
||||||
let ref output = all_output.last().unwrap();
|
let ref output = all_output.last().unwrap();
|
||||||
assert_eq!(**output, Ok($correct.to_string()));
|
assert_eq!(**output, Ok($correct.to_string()));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use ast::{AST, Statement, Expression, Declaration};
|
use ast::{AST, Statement, Expression, Declaration};
|
||||||
use symbol_table::SymbolTable;
|
use symbol_table::{Symbol, SymbolSpec, SymbolTable};
|
||||||
use builtin::{BinOp, PrefixOp};
|
use builtin::{BinOp, PrefixOp};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -29,6 +29,10 @@ pub enum Expr {
|
|||||||
Tuple(Vec<Expr>),
|
Tuple(Vec<Expr>),
|
||||||
Func(Func),
|
Func(Func),
|
||||||
Val(Rc<String>),
|
Val(Rc<String>),
|
||||||
|
Constructor {
|
||||||
|
name: Rc<String>,
|
||||||
|
args: Vec<Expr>,
|
||||||
|
},
|
||||||
Call {
|
Call {
|
||||||
f: Box<Expr>,
|
f: Box<Expr>,
|
||||||
args: Vec<Expr>,
|
args: Vec<Expr>,
|
||||||
@ -96,7 +100,15 @@ impl Expression {
|
|||||||
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
BoolLiteral(b) => Expr::Lit(Lit::Bool(*b)),
|
||||||
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
BinExp(binop, lhs, rhs) => binop.reduce(symbol_table, lhs, rhs),
|
||||||
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
PrefixExp(op, arg) => op.reduce(symbol_table, arg),
|
||||||
Value(name) => Expr::Val(name.clone()),
|
Value(name) => {
|
||||||
|
match symbol_table.values.get(name) {
|
||||||
|
Some(Symbol { name, spec: SymbolSpec::DataConstructor { type_name, type_args } }) => {
|
||||||
|
//TODO finish
|
||||||
|
Expr::Val(name.clone())
|
||||||
|
},
|
||||||
|
_ => Expr::Val(name.clone()),
|
||||||
|
}
|
||||||
|
},
|
||||||
Call { f, arguments } => Expr::Call {
|
Call { f, arguments } => Expr::Call {
|
||||||
f: Box::new(f.reduce(symbol_table)),
|
f: Box::new(f.reduce(symbol_table)),
|
||||||
args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(),
|
args: arguments.iter().map(|arg| arg.reduce(symbol_table)).collect(),
|
||||||
|
Loading…
Reference in New Issue
Block a user