Repository navigation
feat(compiler): support do-while loop statement (#40) - #49
Merged
Merged
Conversation
- Add do to keywords in Lexer.TOKEN_SPEC - Add DoWhileStmt(body: Block, condition: ASTNode) AST node - Update Parser.parse_stmt to parse do <block> while (<condition>); - Implement code generation for do-while loops with start, cond, and end labels - Add unit tests verifying multiple iterations, false condition executing once, break/continue, single statement syntax, AST and lexer Closes #40
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 #40
What changed
dokeyword toLexer.TOKEN_SPEC.DoWhileStmt(body: Block, condition: ASTNode)node.do <block | stmt> while (<condition>);inParser.parse_stmt.DoWhileStmtwith loop start (dowhile_start_*), condition (dowhile_cond_*), and end (dowhile_end_*) labels.loop_continue_stacksocontinuecorrectly routes to condition evaluation.loop_end_stacksobreakcleanly exits the loop.CPI R16, 0and looped back withBRNE <start>.How tested
tests/test_compiler.py:test_compiler_do_while_basic: verify repeated execution while condition holds true.test_compiler_do_while_false_condition_executes_once: verify body executes exactly once when initial condition is false.test_compiler_do_while_break_and_continue: verifybreakexits the loop andcontinuejumps to condition evaluation.test_compiler_do_while_single_statement: verify brace-less single statementdo ... while (...);.test_compiler_do_while_ast_and_lexer: verify tokenization and AST parsing intoDoWhileStmt.uv run pytest: 307 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.