Conversation
There was a problem hiding this comment.
Pull request overview
Implements Ruby 2.7+ case/in pattern matching in the PicoRuby mruby-compiler2 code generator, along with required presymbol additions and a new compiler-level test suite to validate pattern compilation behavior.
Changes:
- Add pattern-matching code generation (
case/in, guards, alternation, array/hash/find patterns) insrc/codegen_prism.inc. - Extend presymbol table with
deconstruct,deconstruct_keys, andsizefor pattern-matching runtime calls. - Add
compiler_test/pattern_match_test.rbcovering core pattern matching behaviors (with some cases marked pending for mruby/c).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| src/codegen_prism.inc | Adds the main pattern matching compilation implementation and PM_CASE_MATCH_NODE handling. |
| include/mrc_presym.inc | Adds presymbols used by the new codegen (deconstruct, deconstruct_keys, size). |
| compiler_test/pattern_match_test.rb | Adds a new test suite for pattern matching across literals, variables, arrays, alternation, pin, and guards (with pending section). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@hasumikin I've opened a new pull request, #4, to work on those changes. Once the pull request is ready, I'll request review from you. |
3417cfd to
bfa030a
Compare
By checking `has_key?` for original target insted of the result of `target.deconstruct_keys`. With it, disabling peephole optimization is needed. This comes from the incompatibility of Hash#deconstruct_keys between CRuby and mruby.
bfa030a to
2f873a0
Compare
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.
This PR implements pattern matching (case/in syntax) for the mruby-compiler2, bringing Ruby 2.7+ pattern matching capabilities to PicoRuby.
Changes
Code generation (src/codegen_prism.inc): 683 lines implementing:
New test suite (compiler_test/pattern_match_test.rb): comprehensive tests covering:
Some tests are pending until mruby/c supports pattern matching mrubyc/mrubyc#257