Skip to content

Commit

Permalink
Implement value in pattern pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 28, 2024
1 parent 0720bbb commit 92a7319
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 11 additions & 1 deletion src/main/java/org/truffleruby/parser/YARPTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,17 @@ public RubyNode visitMatchLastLineNode(Nodes.MatchLastLineNode node) {

@Override
public RubyNode visitMatchPredicateNode(Nodes.MatchPredicateNode node) {
return defaultVisit(node);
var translator = new YARPPatternMatchingTranslator(language, environment, rubySource, this);

// Evaluate the expression and store it in a local
final int tempSlot = environment.declareLocalTemp("value_of_=>");
final ReadLocalNode readTemp = environment.readNode(tempSlot, node);
final RubyNode assignTemp = readTemp.makeWriteNode(node.value.accept(this));

RubyNode condition = translator.translatePatternNode(node.pattern, readTemp);

final RubyNode ret = sequence(Arrays.asList(assignTemp, condition));
return assignPositionAndFlags(node, ret);
}

@Override
Expand Down
7 changes: 2 additions & 5 deletions test/mri/excludes/TestPatternMatching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
exclude :test_alternative_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:204:in `test_alternative_pattern'."
exclude :test_invalid_syntax, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1269:in `test_invalid_syntax'."
exclude :test_deconstruct_keys, "Failed assertion, no message given."
exclude :test_pin_operator_expr_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:468:in `test_pin_operator_expr_pattern'."
exclude :test_single_pattern_error_as_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
exclude :test_single_pattern_error_value_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
exclude :test_single_pattern_error_hash_pattern, "Expected Exception(NoMatchingPatternError) was raised, but the message doesn't match."
exclude :test_literal_value_pattern, "/home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:347:in `test_literal_value_pattern'."
exclude :test_find_pattern, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:806: YARPDefNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:806"
exclude :test_one_line, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1571: YARPDefNodeTranslator does not know how to translate MatchPredicateNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1571"
exclude :test_hash_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x6f8 @obj={:a=>0}>"
exclude :test_array_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x778 @obj=[0]>"
exclude :test_bug18990, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1581: YARPDefNodeTranslator does not know how to translate MatchPredicateNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1581"
exclude :test_hash_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x708 @obj={:a=>0}>"
exclude :test_array_pattern, "NoMatchingPatternError: #<TestPatternMatching::C:0x758 @obj=[0]>"
exclude :test_single_pattern_error_find_pattern, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1623: YARPBlockNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1623"
exclude :test_deconstruct_cache, "SyntaxError: /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1451: YARPBlockNodeTranslator does not know how to translate FindPatternNode at /home/eregon/code/truffleruby-ws/truffleruby/test/mri/tests/ruby/test_pattern_matching.rb:1451"
Original file line number Diff line number Diff line change
@@ -1 +1 @@
exclude :test_refinements, "NoMatchingPatternError: #<TestPatternMatching::TestPatternMatchingRefinements::C1:0x9f8>"
exclude :test_refinements, "NoMatchingPatternError: #<TestPatternMatching::TestPatternMatchingRefinements::C1:0x9b8>"

0 comments on commit 92a7319

Please sign in to comment.