feat: implement goto/label support#216
Merged
Merged
Conversation
- Semantic analysis: replace rejection with proper scope validation - Goto targets must exist in visible scope - Goto cannot jump over local variable declarations - Recursive validation for nested blocks (if/while/repeat/for) - CGen: add CompileStmtGoto and CompileStmtLabel - Labels emit C labels with flua_L_ prefix - Gotos emit C goto statements - SyntaxTreeGoto: add GetLabel() method - Remove old exception tests for unsupported goto/label - Add 4 new test cases: forward skip, backward loop, label-only, invalid goto
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #216 +/- ##
==========================================
+ Coverage 96.69% 96.77% +0.07%
==========================================
Files 67 67
Lines 14008 14118 +110
==========================================
+ Hits 13545 13662 +117
+ Misses 463 456 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Valid goto tests (test/lua/jit/): - test_goto_forward_skip: forward goto skipping a reassignment - test_goto_backward_loop: backward goto forming a loop - test_goto_label_only: label with no goto - test_goto_continue: goto simulating continue in for loop - test_goto_break_out: goto breaking out of nested for loops - test_goto_in_if_else: goto within if/else branches Invalid goto tests (test/lua/exception/): - test_goto_skip_single_local: goto jumps over single local - test_goto_skip_local: goto jumps over multiple locals - test_goto_nonexistent_label: goto to nonexistent label - test_goto_cross_function: goto targeting label in another function Removed old combined test files.
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
实现 Lua goto/label 语法支持。
语义分析(
semantic_analysis.cpp)CheckGotoOrLabel()的拦截抛异常逻辑ValidateGotoInBlock():递归验证 goto 合法性C 代码生成(
c_gen.cpp)CompileStmtGoto():生成goto flua_L_<name>;CompileStmtLabel():生成flua_L_<name>: ;AST(
syntax_tree.h)SyntaxTreeGoto新增GetLabel()方法测试
全部 715 个测试通过