Make environment generic and adapt closures
Added unit test
This commit is contained in:
Regular → Executable
Regular → Executable
+3
-2
@@ -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 {
|
||||
|
||||
Regular → Executable
+1
-5
@@ -106,11 +106,7 @@ impl LoxError {
|
||||
LoxError::ParseError { source_slice, .. } => Some(source_slice.clone()),
|
||||
LoxError::IoError { .. } => None,
|
||||
LoxError::TypeMismatch { source_slice, .. } => Some(source_slice.clone()),
|
||||
LoxError::Return {
|
||||
value,
|
||||
return_label,
|
||||
..
|
||||
} => None,
|
||||
LoxError::Return { .. } => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
Reference in New Issue
Block a user