Make environment generic and adapt closures

Added unit test
This commit is contained in:
Giulio Agostini
2026-06-29 20:50:29 +02:00
parent 4e2645e12d
commit 29c86d278d
30 changed files with 820 additions and 30 deletions
Regular → Executable
+3 -2
View File
@@ -2,6 +2,7 @@ use core::fmt;
use std::fmt::Display;
use std::ops::{Add, Div, Mul, Not, Rem, Sub};
use crate::backend::environment::Environment;
use crate::common::lox_result::{runtime_error, LoxResult};
use crate::{
backend::environment::EnvironmentStack,
@@ -312,7 +313,7 @@ pub struct LoxFunction {
pub parameters: Vec<(String, String)>,
pub return_type: Option<String>,
pub body: AstNode<Stmt>,
pub closure: Option<EnvironmentStack>,
pub closure: Option<EnvironmentStack<BaseValue>>,
pub guard: Option<Box<Expr>>,
}
@@ -320,7 +321,7 @@ impl LoxFunction {
pub fn new(
parameters: Vec<(String, String)>,
body: AstNode<Stmt>,
closure: Option<EnvironmentStack>,
closure: Option<EnvironmentStack<BaseValue>>,
guard: Option<Box<Expr>>,
) -> Self {
LoxFunction {