16 Commits
Author SHA1 Message Date
gmagostini 2498b3b345 Merge pull request 'Ai/refactor' (#1) from ai/refactor into dev
Reviewed-on: https://gitea.lambstudios.eu/ProjectValkay/rlox/pulls/1
2026-07-06 17:14:35 +00:00
Giulio Agostini b93a1394cd Update parser.rs 2026-07-06 19:10:01 +02:00
Giulio Agostini 842216729b wip:
Add type system and refator for having only epression
2026-07-06 10:43:17 +02:00
Giulio Agostini 9f15a00b98 Add static variable resolution with scope tracking
- Add distance-based get_at on EnvironmentStack
- Add distance-based assign_at on EnvironmentStack
- Introduce ErrorSink to accumulate diagnostics across passes
- Implement Resolver with a ScopeStack and per-node distance map
- Extend interpreter to store locals distances for runtime lookup
- Add tests for resolution behavior and error accumulation
  Add static variable resolution with scope tracking
2026-06-30 15:05:34 +02:00
Giulio Agostini d40fe2a550 Introduce NodeId for AST and synthetic slices 2026-06-30 14:05:46 +02:00
Giulio Agostini ef8abda048 Move variable resolution to middleend
- Introduce AST-based visitor and resolver in middleend
- Update guard field and parser to use AstNode<Expr>
- Remove backend variable_resolution and adjust exports
- Expose middleend in the library
2026-06-30 09:47:22 +02:00
Giulio Agostini 29c86d278d Make environment generic and adapt closures
Added unit test
2026-06-29 20:50:29 +02:00
fizban 4e2645e12d closure 2026-02-11 16:35:05 +01:00
Giulio Agostini ee279425f2 wip 2025-11-12 20:45:35 +01:00
Giulio Agostini 07cedc27bf 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.
2025-10-10 10:18:02 +02:00
Giulio Agostini c1ecd7d1f7 Switch interpreter to use new base value types
The commit changes the interpreter and related code to use the new
`BaeValue` and `Number` types, moving away from direct floats. The main
changes include:

- Replace LiteralValue with BaeValue across the codebase - Add Number
enum for type-safe numeric values - Move AST definitions to common
module - Update operators to handle new numeric types - Add 'is' token
type and parser support Switch to common base_value library for value
types

This commit represents a significant refactoring to switch the
interpreter to use a new shared base value type system. The main changes
include:

1. Move value types to a new common/base_value.rs module 2. Add richer
numeric type support with promotion rules 3. Update interpreter to use
new BaseValue enum 4. Move AST types to common module for sharing 5.
Consolidate value operations like Add, Sub etc 6. Add proper test
coverage for numeric operations

The commit improves type safety and adds more robust numeric handling
while keeping the interpreter's core logic clean.
2025-10-07 14:28:24 +02:00
Giulio Agostini fa2e9178fb Move example code to examples directory
The commit moves example and test files to a dedicated examples
directory and updates the code for function and variable handling. The
subject line captures the primary purpose of the move operation.

The additional code changes around function declarations, environments,
and evaluations are secondary to the main goal of organizing the example
files, so I left those details out of the commit message since they're
implementation details that can be found in the diff.
2025-10-06 18:52:32 +02:00
Giulio Agostini 827349cbad Refactor environment to use stack-based scoping
The commit rewrites the environment to use a stack of hash maps for
managing variable scopes. This replaces the old parent-reference
approach with a simpler and more efficient stack-based model.

Key changes: - Rename Environment to EnvironmentStack - Store scopes in
a Vec of HashMaps - Add push/pop scope operations for block handling -
Update interpreter to properly manage scope lifetimes - Clean up error
handling with helper functions
2025-10-04 21:05:00 +02:00
Giulio Agostini 41253e932a Add source location tracking to AST nodes
The commit expands the source location tracking through the AST by:

1. Switching from raw Expr/Stmt nodes to AstNode wrappers containing
source slices 2. Updating interpreter and parser to preserve location
info through node traversal 3. Enhancing error reporting with richer
source context information
2025-10-04 19:02:33 +02:00
Giulio Agostini 113a683beb Add while loop support and token pretty printing
The commit adds while loop statements and improves token display
formatting:

- Implements while loop syntax and evaluation - Adds a new token pretty
printing module with configurable formatting - Improves token display
with colors and different output modes
2025-10-03 19:40:25 +02:00
Giulio Agostini a7df45dc72 Initialize Rust implementation of Lox interpreter
This initial commit sets up the basic structure for a Rust
implementation of the Lox interpreter, including:

- Lexer for tokenizing source code - Parser for building AST - Basic
interpreter functionality - Environment for variable storage

The core components include source tracking, error handling, and basic
expression evaluation.
2025-10-03 19:07:12 +02:00