34 lines
974 B
Rust
34 lines
974 B
Rust
use super::Interpret;
|
|
use super::{types::Primitive, RuntimeError};
|
|
use crate::ast::statement;
|
|
use crate::interpreter::world::World;
|
|
|
|
impl Interpret for statement::Statement {
|
|
fn interpret(&self, w: &mut World) -> Result<Primitive, RuntimeError> {
|
|
statement::all_variants!(self, n => n.interpret(w))
|
|
}
|
|
}
|
|
|
|
impl Interpret for statement::PrintStatement {
|
|
fn interpret(&self, w: &mut World) -> Result<Primitive, RuntimeError> {
|
|
let res = self.0.interpret(w)?;
|
|
println!("{:?}", res);
|
|
Ok(res)
|
|
}
|
|
}
|
|
|
|
impl Interpret for statement::ExpressionStatement {
|
|
fn interpret(&self, w: &mut World) -> Result<Primitive, RuntimeError> {
|
|
self.0.interpret(w)
|
|
}
|
|
}
|
|
|
|
impl Interpret for statement::VariableAssignmentStatement {
|
|
fn interpret(&self, w: &mut World) -> Result<Primitive, RuntimeError> {
|
|
let expr_val = self.node.interpret(w)?;
|
|
// Clone for now, later this will use a GC and won't need to clone
|
|
w.set_var(self.var_name.clone(), expr_val.clone());
|
|
Ok(expr_val)
|
|
}
|
|
}
|