mumu 0.11.0

Lava Mumu is a language for those in the now and that know
Documentation
use crate::parser::ast::Stmt;
use crate::parser::types::Value;
use crate::parser::interpreter::Interpreter;
use super::helpers::err_with_pos;

impl Interpreter {
    pub fn exec_statement(&mut self, stmt: &Stmt) -> Result<Value, String> {
        match stmt {
            Stmt::ImportSo { path, line, col } => {
                if self.is_verbose() {
                    eprintln!("(Interpreter) extend => {}", path);
                }
                if !self.can_extend() {
                    return Err(err_with_pos("extend is disallowed", *line, *col));
                }
                let expr_for_legacy = format!("extend(\"{}\")", path);
                crate::modules::extend::handle_extend_call(self, &expr_for_legacy)
                    .map_err(|e| err_with_pos(format!("extend error: {}", e), *line, *col))
            }
            Stmt::Assignment { left, right, line: _line, col: _col } => {
                let right_val = self.eval_expression(right)?;
                crate::parser::interpreter::utils::assign_to_expr(self, left, right_val.clone())?;
                Ok(right_val)
            }
            Stmt::AssignmentDestructure { pattern, right, line: _line, col: _col } => {
                let right_val = self.eval_expression(right)?;
                crate::parser::interpreter::utils::assign_keyed_destructure(self, pattern, right_val.clone())?;
                Ok(right_val)
            }
            Stmt::AssignmentScoped { left, right, line: _line, col: _col } => {
                let val = self.eval_expression(right)?;
                match left {
                    crate::parser::ast::Expr::Ident { name, .. } => {
                        self.set_variable(name, val.clone());
                        Ok(val)
                    }
                    _ => Err(err_with_pos("Left side of ^=-assignment must be a variable", *_line, *_col)),
                }
            }
            Stmt::ExprStmt { expr, line: _line, col: _col } => self.eval_expression(expr),
        }
    }
}