Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 206 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ edition = "2021"
nom = "7.0"
approx = "0.5.1"
once_cell = "1.10"
predicates = "3.1.3"
assert_cmd = "2.0.17"
12 changes: 12 additions & 0 deletions src/interpreter/statement_execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::expression_eval::{eval, ExpressionResult};
use crate::environment::environment::Environment;
use crate::ir::ast::{Expression, Statement};
use crate::stdlib::standard_library::get_metabuiltins_table;

pub enum Computation {
Continue(Environment<Expression>),
Expand All @@ -24,6 +25,7 @@ pub fn run(
stmt: Statement,
env: &Environment<Expression>,
) -> Result<Environment<Expression>, String> {
get_metabuiltins_table();
match execute(stmt, env) {
Ok(Computation::Continue(new_env)) => Ok(new_env),
Ok(Computation::Return(_, new_env)) => Ok(new_env),
Expand Down Expand Up @@ -192,6 +194,16 @@ pub fn execute(stmt: Statement, env: &Environment<Expression>) -> Result<Computa
Ok(Computation::Continue(new_env))
}

Statement::MetaStmt(ref name) => {
let table = get_metabuiltins_table();
if let Some(f) = table.get(name) {
let next_stmt = f(&mut new_env);
execute(next_stmt, &new_env)
} else {
Err(format!("Meta built-in '{}' not found", name))
}
}

_ => Err(String::from("not implemented yet")),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ir/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,5 @@ pub enum Statement {
FuncDef(Function),
Return(Box<Expression>),
TypeDeclaration(Name, Vec<ValueConstructor>),
MetaStmt(String),
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
pub mod environment;
pub mod interpreter;
pub mod ir;
pub mod parser;
pub mod stdlib;
Loading