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:
+36
-10
@@ -263,7 +263,10 @@ impl PrettyPrint for Stmt {
|
||||
let indent = ctx.indent();
|
||||
|
||||
match self {
|
||||
Stmt::Expression { expression } => {
|
||||
Stmt::Expression {
|
||||
expression,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
pretty_print_with_config(expression.as_ref(), &PrettyConfig::compact());
|
||||
@@ -276,7 +279,10 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Print { expression } => {
|
||||
Stmt::Print {
|
||||
expression,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
pretty_print_with_config(expression.as_ref(), &PrettyConfig::compact());
|
||||
@@ -289,7 +295,11 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::VarDeclaration { name, initializer } => {
|
||||
Stmt::VarDeclaration {
|
||||
name,
|
||||
initializer,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
match initializer {
|
||||
Some(init) => {
|
||||
@@ -315,7 +325,11 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::VarAssigment { name, value } => {
|
||||
Stmt::VarAssigment {
|
||||
name,
|
||||
value,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
let value_str =
|
||||
pretty_print_with_config(value.as_ref(), &PrettyConfig::compact());
|
||||
@@ -329,7 +343,10 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Return { expression } => {
|
||||
Stmt::Return {
|
||||
expression,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
let expr_str =
|
||||
pretty_print_with_config(expression.as_ref(), &PrettyConfig::compact());
|
||||
@@ -342,11 +359,15 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Block { statements } => {
|
||||
Stmt::Block {
|
||||
statements,
|
||||
label,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
write!(f, "{{ ... ({} statements) }}", statements.len())
|
||||
write!(f, "{{ ... [{}] ({} statements) }}", label, statements.len())
|
||||
} else {
|
||||
writeln!(f, "{}Block {{", indent)?;
|
||||
writeln!(f, "{}Block [{}] {{", label, indent)?;
|
||||
writeln!(f, "{}statements: [", ctx.child_context(false).indent())?;
|
||||
for (i, stmt) in statements.iter().enumerate() {
|
||||
let is_last = i == statements.len() - 1;
|
||||
@@ -366,6 +387,7 @@ impl PrettyPrint for Stmt {
|
||||
then_branch,
|
||||
elif_branch,
|
||||
else_branch,
|
||||
return_value,
|
||||
} => {
|
||||
if ctx.config.compact {
|
||||
let cond_str =
|
||||
@@ -415,8 +437,11 @@ impl PrettyPrint for Stmt {
|
||||
write!(f, "{}}}", indent)
|
||||
}
|
||||
}
|
||||
Stmt::Stmt { expression } => expression.pretty_print(ctx, f),
|
||||
Stmt::While { condition, body } => {
|
||||
Stmt::While {
|
||||
condition,
|
||||
body,
|
||||
return_value,
|
||||
} => {
|
||||
write!(f, "{}while (", ctx.child_context(true).indent())?;
|
||||
condition.pretty_print(&ctx.child_context(true), f)?;
|
||||
writeln!(f, ") {{")?;
|
||||
@@ -428,6 +453,7 @@ impl PrettyPrint for Stmt {
|
||||
condition,
|
||||
increment,
|
||||
body,
|
||||
return_value,
|
||||
} => {
|
||||
write!(f, "{}for (", ctx.child_context(true).indent())?;
|
||||
variable.pretty_print(&ctx.child_context(true), f)?;
|
||||
|
||||
Reference in New Issue
Block a user