Repository navigation
feat(compiler): implement stack-frame based local variable allocation to support recursion (#44) - #58
Merged
Merged
Conversation
… to support recursion (#44)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #44.
This PR implements a frame-pointer based stack-frame model (using the AVR Y register pair
R29:R28) for local variables and function parameters, enabling robust recursive function calls and preserving caller state.Key Changes
cpu.py,assembler.py):LDD Rd, Y+q / Z+qandSTD Y+q / Z+q, Rrinstructions for indirect addressing with displacement.0x3D(SPL) and0x3E(SPH) inINandOUT.Y+q,Z+qin the assembler.compiler.py):_collect_localsto discover all function parameters and local variable declarations across blocks and statements.IN R28, 0x3D; IN R29, 0x3E), allocates local stack space viaSBIW R28, <locals_size>, and updates SP.ADIW R28, <locals_size>, updates SP, restores caller Y, and returns (RET).LDD/STD.LDDimmediately followingSTD.fib(7)), recursive Factorial with local variables, nested multi-frame calls, and global variable interactions inside functions.cpu.py,compiler.py, andassembler.py(342 tests passing).Verification
uv run pytest --cov=tiny8.compiler --cov=tiny8.cpu --cov=tiny8.assembler(100% coverage, 342 passed)uv run ruff check src/ tests/(all passed)uv run ruff format --check src/ tests/(clean)