Wire functions through everything, with some unimplemented, and add a basic scoped map.

This commit is contained in:
2023-10-07 11:06:28 +02:00
parent eba5227ebc
commit 736d27953f
18 changed files with 392 additions and 97 deletions

View File

@@ -1,7 +1,7 @@
use internment::ArcIntern;
use crate::eval::{EvalEnvironment, EvalError, PrimitiveType, Value};
use crate::syntax::{ConstantType, Expression, Program, Statement};
use crate::syntax::{ConstantType, Expression, Program, Statement, TopLevel};
use std::str::FromStr;
impl Program {
@@ -19,16 +19,19 @@ impl Program {
let mut env = EvalEnvironment::empty();
let mut stdout = String::new();
for stmt in self.statements.iter() {
// at this point, evaluation is pretty simple. just walk through each
// statement, in order, and record printouts as we come to them.
for stmt in self.items.iter() {
match stmt {
Statement::Binding(_, name, value) => {
TopLevel::Function(_name, _arg_names, _body) => {
unimplemented!()
}
// at this point, evaluation is pretty simple. just walk through each
// statement, in order, and record printouts as we come to them.
TopLevel::Statement(Statement::Binding(_, name, value)) => {
let actual_value = value.eval(&env)?;
env = env.extend(name.clone().intern(), actual_value);
}
Statement::Print(_, name) => {
TopLevel::Statement(Statement::Print(_, name)) => {
let value = env.lookup(name.clone().intern())?;
let line = format!("{} = {}\n", name, value);
stdout.push_str(&line);