This commit is contained in:
Giulio Agostini
2025-11-12 20:45:35 +01:00
parent 07cedc27bf
commit ee279425f2
9 changed files with 240 additions and 45 deletions
+11 -7
View File
@@ -271,10 +271,17 @@ pub enum BaseValue {
Nil,
Function(LoxFunction),
NativeFunction(NativeFunction),
Return {
value: Box<BaseValue>,
labels: Vec<String>,
},
}
struct ReturnValue {
label: Vec<String>,
value: BaseValue,
}
impl ReturnValue {
pub fn new(label: Vec<String>, value: BaseValue) -> Self {
Self { label, value }
}
}
impl BaseValue {
@@ -296,9 +303,6 @@ impl Display for BaseValue {
BaseValue::Nil => write!(f, "nil"),
BaseValue::Function(..) => write!(f, "<fn lox function>"),
BaseValue::NativeFunction(..) => write!(f, "<native native function>"),
BaseValue::Return { labels, .. } => {
write!(f, "<return value [return:{}]>", labels.join(":"))
}
}
}
}
+6 -3
View File
@@ -1,5 +1,8 @@
use crate::frontend::source_registry::{SourceRegistry, SourceSlice};
use std::fmt;
use crate::{
common::base_value::BaseValue,
frontend::source_registry::{SourceRegistry, SourceSlice},
};
use std::{error::Error, fmt};
#[derive(Debug, Clone)]
pub enum LoxError {
@@ -397,7 +400,7 @@ impl fmt::Display for LoxError {
}
}
impl std::error::Error for LoxError {}
impl Error for LoxError {}
pub type LoxResult<T> = Result<T, LoxError>;