diff --git a/forge-script-lang/src/runtime/executor/simple.rs b/forge-script-lang/src/runtime/executor/simple.rs index 6dbd2c312f3327b475a6a416cff27ffde134aa55..13cad9ad145b8ff766ff762eccb555d4e5933857 100644 --- a/forge-script-lang/src/runtime/executor/simple.rs +++ b/forge-script-lang/src/runtime/executor/simple.rs @@ -1,5 +1,6 @@ use crate::parse::ast::{ - BinaryOp, DeclareFunction, ExpressionList, Program, UnaryOp, ValueExpression, VoidExpression, + BinaryOp, DeclareFunction, ExpressionList, Print, Program, UnaryOp, ValueExpression, + VoidExpression, }; use crate::runtime::executor::Visitor; use crate::runtime::value::{ForgeValue, UnsupportedOperation}; @@ -110,7 +111,19 @@ impl Visitor for SimpleExecutor { &mut self, expression: &VoidExpression, ) -> Result<Self::Output, Self::Error> { - Err(RuntimeError::Unsupported("Void Expression")) + match expression { + VoidExpression::ConditionLoop(_) => { + return Err(RuntimeError::Unsupported("ConditionLoop")) + } + VoidExpression::Import(_) => return Err(RuntimeError::Unsupported("Import")), + VoidExpression::Export(_) => return Err(RuntimeError::Unsupported("Export")), + VoidExpression::Print(Print { expr }) => { + let value = self.evaluate_value_expression(expr.as_ref())?; + println!("{}", value); + } + } + + Ok(ForgeValue::Null) } fn evaluate_program(&mut self, program: &Program) -> Result<Self::Output, Self::Error> { @@ -154,4 +167,11 @@ mod interpreter_test { let mut vm = SimpleExecutor::default(); assert_eq!(vm.evaluate_program(&add_numbers), Ok(ForgeValue::from(0))); } + + #[test] + fn print() { + let print_4 = parse_program("print 2 + 2").expect("Failed to parse"); + let mut vm = SimpleExecutor::default(); + assert_eq!(vm.evaluate_program(&print_4), Ok(ForgeValue::Null)); + } }