Repository navigation
feat(compiler): support continue statement in while and for loops (#39) - #48
Merged
Merged
Conversation
- Add continue keyword to Lexer.TOKEN_SPEC and Parser.parse_stmt - Add ContinueStmt AST node - Maintain loop_continue_stack in CodeGenerator - In while loops, route continue to loop condition evaluation label - In for loops, route continue to dedicated post-step label before jumping to condition - Support nested loops cleanly using continue stack - Add unit tests for while, for, and nested loops continue statements Closes #39
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.
Closes #39
What changed
continuekeyword toLexer.TOKEN_SPEC.ContinueStmt(ASTNode)node.continue;inParser.parse_stmt.loop_continue_stack: list[str]to track continuation targets.whileloops: target the condition evaluation label (while_start_*).forloops: create and target a dedicated post-step label (for_post_*) before jumping back to condition evaluation.How tested
tests/test_compiler.py:test_compiler_while_loop_continue: verifycontinueskips the rest of the loop body and re-evaluates the condition.test_compiler_for_loop_continue: verifycontinuejumps to the post-step expression (e.g.i++) before re-evaluating the condition.test_compiler_nested_loops_continue_and_break: verify continue and break in nested loops resolve to the correct inner/outer targets.test_compiler_continue_ast_and_lexer: verify tokenization and AST construction ofContinueStmt.uv run pytest: 302 passed (all tests passed).uv run ruff check src/tiny8/compiler.py tests/test_compiler.py: passed.uv run ruff format --check src/tiny8/compiler.py tests/test_compiler.py: passed.