Add GOTO and BREAK control statements to TP2 - #378
Draft
4Luke4 wants to merge 1 commit into
Draft
Conversation
4Luke4
marked this pull request as draft
August 1, 2026 22:52
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
This adds first-class
GOTO, labels, andBREAKstatements to both TP2 action and patch code.The scope model takes inspiration from Lua's control statements, while being adapted to WeiDU's action/patch execution model.
Syntax and semantics
::label::declares a label.GOTO labelresumes execution immediately after a visible label.BREAKexits the innermost supported loop.ACTION_TRYandPATCH_TRYdo not intercept control transfers.GOTOorBREAKleaves a nested block.BREAKexits the innermost:OUTER_WHILE,OUTER_FOR,ACTION_FOR_EACH,ACTION_PHP_EACH, orACTION_BASH_FOR;WHILE,FOR,PATCH_FOR_EACH,PATCH_PHP_EACH, orPATCH_BASH_FOR.OUTER_FORandFORdo not execute their increment lists afterBREAK.WeiDU validates the complete control-flow structure during parsing. It rejects:
BREAKoutside a supported loop.Diagnostics include the source filename, line, and column.
Implementation
GOTO, andBREAK.Tests
A new
make test-control-statementstarget covers:ACTION_TRY,PATCH_TRY,WITH_SCOPE, andPATCH_WITH_SCOPE;BREAKselection;A temporary branch-only workflow built the Linux executable using the repository's archived OCaml 4.08.1 unsafe-string toolchain, ran the complete regression suite, and generated the documentation successfully:
The repository's ordinary matrix on the same source tree also passed both macOS jobs. Its Windows job compiled the changed OCaml modules before reaching an unchanged
src/reg.cWin32 API type error, while its ordinary Linux job stopped during provisioning because the configured non-archived OCaml switch was unavailable:The disposable workflow was removed after validation and is not part of this pull request.