Add .idea to gitignore and prep return value types Add middleend module
for AST return value tracking The changes introduce support for tracking return values and labels across AST nodes. The key changes include: - Adding ReturnValue type to BaseValue - Adding return_type field to LoxFunction - Adding label field to Block statements - Creating middleend crawler module for AST traversal Add return value types to AST This accurately captures both changes: adding `.idea/` to gitignore and adding return value types to the AST structure. The changes include adding return value fields to statement nodes and adjusting the interpreter logic accordingly.
This commit is contained in:
@@ -271,6 +271,10 @@ pub enum BaseValue {
|
||||
Nil,
|
||||
Function(LoxFunction),
|
||||
NativeFunction(NativeFunction),
|
||||
Return {
|
||||
value: Box<BaseValue>,
|
||||
labels: Vec<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl BaseValue {
|
||||
@@ -292,6 +296,9 @@ 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(":"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,6 +306,7 @@ impl Display for BaseValue {
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct LoxFunction {
|
||||
pub parameters: Vec<(String, String)>,
|
||||
pub return_type: Option<String>,
|
||||
pub body: AstNode<Stmt>,
|
||||
pub closure: Option<EnvironmentStack>,
|
||||
pub guard: Option<Box<Expr>>,
|
||||
@@ -313,6 +321,7 @@ impl LoxFunction {
|
||||
) -> Self {
|
||||
LoxFunction {
|
||||
parameters,
|
||||
return_type: None,
|
||||
body,
|
||||
closure,
|
||||
guard,
|
||||
@@ -322,6 +331,7 @@ impl LoxFunction {
|
||||
pub fn anonymous_function(parameters: Vec<(String, String)>, body: AstNode<Stmt>) -> Self {
|
||||
LoxFunction {
|
||||
parameters,
|
||||
return_type: None,
|
||||
body,
|
||||
closure: None,
|
||||
guard: None,
|
||||
|
||||
Reference in New Issue
Block a user