Added Label, Continue, Break support#1
Conversation
Derppening
left a comment
There was a problem hiding this comment.
Please don't include HkScratch.mls in the PR. Either attach the code snippet as part of the PR description, or add a file under hkmc2/shared/src/test/mlscript/wasm with your test cases.
| case Define(_, rst) => containsContinue(rst) | ||
| case Return(_, _) | End(_) | Break(_) | Throw(_) | _: HandleBlock => false | ||
|
|
||
| if containsContinue(body) then |
There was a problem hiding this comment.
Why do we need special logic when a continue is present? Looking at the equivalent implementation in JSBuilder it appears that we can just treat a label as a label + loop + break?
| val loopLabel = s"${label.nme}_loop" | ||
| val breakLabel = label.nme |
There was a problem hiding this comment.
I don't think you should manually create label names like this. You can probably follow how JSBuilder does it:
scope.allocateNameon the label- Generate a
block + loop - When you encounter a
breakyoubrto the allocated name of the label - When you encounter a
continueyoubr 0to theloopto continue executing the loop
Unlike with other index spaces, indexing of labels is relative by nesting depth, that is, label 0 refers to the innermost structured control instruction enclosing the referring branch instruction, while increasing indices refer to those farther out. [...] The exact effect depends on that control construct. In case of
𝖻𝗅𝗈𝖼𝗄or 𝗂𝖿 it is a forward jump, resuming execution after the end of the block. In case of𝗅𝗈𝗈𝗉it is a backward jump to the beginning of the loop.
https://webassembly.github.io/spec/core/syntax/instructions.html#syntax-instr-control
- Once you finish processing the
bodyblock,breakout to continue executingrest
|
Thanks @Derppening; I'll review when they address your comments. |
This PR is not dependent on #2 and the branch was creating from an existing hkmc2 branch.