some documentation

This commit is contained in:
Sebastian Hugentobler 2025-05-28 21:08:14 +02:00
parent 61a056157b
commit 2d739d98cc
Signed by: shu
SSH key fingerprint: SHA256:ppcx6MlixdNZd5EUM1nkHOKoyQYoJwzuQKXM6J/t66M
2 changed files with 7 additions and 0 deletions

View file

@ -1,5 +1,6 @@
use crate::{expression::Expression, statement::Statement, token::Literal};
/// Generate a string representation of a list of AST statements.
pub fn print(statements: &[Statement]) -> String {
let mut result = String::new();
for statement in statements {
@ -8,6 +9,7 @@ pub fn print(statements: &[Statement]) -> String {
result
}
/// Recursively generate a string representation of a single AST statement.
fn print_statement(statement: &Statement, indent: usize) -> String {
let indent_str = " ".repeat(indent);
match statement {
@ -131,6 +133,7 @@ fn print_statement(statement: &Statement, indent: usize) -> String {
}
}
/// Recursively generate a string representation of a single AST expression.
fn print_expression(expr: &Expression) -> String {
match expr {
Expression::Assign { name, value } => {

View file

@ -40,9 +40,13 @@ enum ClassType {
/// Resolve variable references and perform static analysis before interpretation.
#[derive(Debug)]
pub struct Resolver<'a> {
/// Stack of scopes, each mapping variable names to their initialized state.
scopes: Vec<HashMap<String, bool>>,
/// Reference to the interpreter to resolve variable depths.
interpreter: &'a mut Interpreter,
/// Track the type of the current function being resolved (regular, method, initializer, ...).
current_fun: FunctionType,
/// Tracks the type of the current class being resolved (regular, subclass, ...).
current_class: ClassType,
}