Checkpoint

This commit is contained in:
2023-10-14 16:39:16 -07:00
parent 87d027bf8d
commit 71228b9e09
18 changed files with 402 additions and 78 deletions

View File

@@ -1,8 +1,7 @@
use super::{Primitive, Type, ValueOrRef};
use crate::eval::{EvalEnvironment, EvalError, Value};
use crate::ir::{Expression, Program, Statement, TopLevel};
use super::{Primitive, Type, ValueOrRef};
impl Program {
/// Evaluate the program, returning either an error or a string containing everything
/// the program printed out.
@@ -14,7 +13,7 @@ impl Program {
for stmt in self.items.iter() {
match stmt {
TopLevel::Function(_, _, _) => unimplemented!(),
TopLevel::Function(_, _, _, _) => unimplemented!(),
TopLevel::Statement(Statement::Binding(_, name, _, value)) => {
let actual_value = value.eval(&env)?;
@@ -43,6 +42,7 @@ impl Expression {
match t {
Type::Primitive(pt) => Ok(pt.safe_cast(&value)?),
Type::Function(_, _) => Err(EvalError::CastToFunction(t.to_string())),
}
}