@@ -3699,7 +3699,9 @@ private void emitPatternNotImplemented(String kind) {
36993699 }
37003700
37013701 /**
3702- * Saves subject of the pattern context into BytecodeLocal variable, to be restored eventually.
3702+ * Saves subject of the pattern context into BytecodeLocal variable, to be restored
3703+ * eventually.
3704+ *
37033705 * @param pc Pattern context, which subject needs to be saved.
37043706 * @return Subject saved in local variable.
37053707 */
@@ -3713,6 +3715,7 @@ private BytecodeLocal patternContextSubjectSave(PatternContext pc) {
37133715
37143716 /**
37153717 * Loads pattern context subject back into pattern context.
3718+ *
37163719 * @param pcSave Variable to restore pattern context subject from.
37173720 * @param pc Pattern context into which the subject should be restored.
37183721 */
@@ -3723,8 +3726,9 @@ private void patternContextSubjectLoad(BytecodeLocal pcSave, PatternContext pc)
37233726 }
37243727
37253728 /**
3726- * Check if attribute and keyword attribute lengths match, or if there isn't too much patterns or attributes.
3727- * Throws error on fail.
3729+ * Check if attribute and keyword attribute lengths match, or if there isn't too much
3730+ * patterns or attributes. Throws error on fail.
3731+ *
37283732 * @param patLen Patterns count
37293733 * @param attrsLen Attributes count
37303734 * @param kwdPatLen Keyword attributes count
@@ -3742,9 +3746,11 @@ private void classMatchLengthChecks(int patLen, int attrsLen, int kwdPatLen, Pat
37423746 }
37433747
37443748 /**
3745- * Visits sub-patterns for class pattern matching. Regular, positional patterns are handled first, then the
3746- * keyword patterns (e.g. the "class.attribute = [keyword] pattern"). Generates boolean value based on
3747- * results of the subpatterns; values are evaluated using the AND operator.
3749+ * Visits sub-patterns for class pattern matching. Regular, positional patterns are handled
3750+ * first, then the keyword patterns (e.g. the "class.attribute = [keyword] pattern").
3751+ * Generates boolean value based on results of the subpatterns; values are evaluated using
3752+ * the AND operator.
3753+ *
37483754 * @param patterns Patterns to check as subpatterns.
37493755 * @param kwdPatterns Keyword patterns to check as subpatterns.
37503756 * @param attrsValueUnpacked Values to use as `pc.subject` in sub-pattern check.
@@ -3760,31 +3766,31 @@ private void classMatchVisitSubpatterns(PatternTy[] patterns, PatternTy[] kwdPat
37603766 } else {
37613767 BytecodeLocal temp = b .createLocal ();
37623768 b .beginStoreLocal (temp );
3763- b .beginPrimitiveBoolAnd ();
3764- for (int i = 0 ; i < patLen ; i ++) {
3765- b .beginBlock ();
3766- b .beginStoreLocal (pc .subject );
3767- b .beginArrayIndex (i );
3768- b .emitLoadLocal (attrsValueUnpacked );
3769- b .endArrayIndex ();
3770- b .endStoreLocal ();
3769+ b .beginPrimitiveBoolAnd ();
3770+ for (int i = 0 ; i < patLen ; i ++) {
3771+ b .beginBlock ();
3772+ b .beginStoreLocal (pc .subject );
3773+ b .beginArrayIndex (i );
3774+ b .emitLoadLocal (attrsValueUnpacked );
3775+ b .endArrayIndex ();
3776+ b .endStoreLocal ();
37713777
3772- visitSubpattern (patterns [i ], pc );
3773- b .endBlock ();
3774- }
3778+ visitSubpattern (patterns [i ], pc );
3779+ b .endBlock ();
3780+ }
37753781
3776- for (int i = 0 , j = patLen ; i < attrsLen ; i ++, j ++) {
3777- b .beginBlock ();
3778- b .beginStoreLocal (pc .subject );
3779- b .beginArrayIndex (j );
3780- b .emitLoadLocal (attrsValueUnpacked );
3781- b .endArrayIndex ();
3782- b .endStoreLocal ();
3782+ for (int i = 0 , j = patLen ; i < attrsLen ; i ++, j ++) {
3783+ b .beginBlock ();
3784+ b .beginStoreLocal (pc .subject );
3785+ b .beginArrayIndex (j );
3786+ b .emitLoadLocal (attrsValueUnpacked );
3787+ b .endArrayIndex ();
3788+ b .endStoreLocal ();
37833789
3784- visitSubpattern (kwdPatterns [i ], pc );
3785- b .endBlock ();
3786- }
3787- b .endPrimitiveBoolAnd ();
3790+ visitSubpattern (kwdPatterns [i ], pc );
3791+ b .endBlock ();
3792+ }
3793+ b .endPrimitiveBoolAnd ();
37883794 b .endStoreLocal ();
37893795
37903796 patternContextSubjectLoad (pcSave , pc );
@@ -3866,7 +3872,9 @@ private void doVisitPattern(PatternTy.MatchClass node, PatternContext pc) {
38663872 }
38673873
38683874 /**
3869- * Checks if keyword argument names aren't the same or if their name isn't forbidden. Raises error at fail.
3875+ * Checks if keyword argument names aren't the same or if their name isn't forbidden. Raises
3876+ * error at fail.
3877+ *
38703878 * @param attrs Attributes to check.
38713879 * @param patterns Patterns for error source range.
38723880 */
@@ -3891,8 +3899,8 @@ private static int lengthOrZero(Object[] p) {
38913899 }
38923900
38933901 /**
3894- * Checks if keys in pattern are, if present, longer than keys in subject. If yes, pattern should fail,
3895- * otherwise, we should continue with evaluation.
3902+ * Checks if keys in pattern are, if present, longer than keys in subject. If yes, pattern
3903+ * should fail, otherwise, we should continue with evaluation.
38963904 *
38973905 * Generates result of the comparison (boolean).
38983906 *
@@ -3909,8 +3917,8 @@ private void checkPatternKeysLength(int keyLen, PatternContext pc) {
39093917 }
39103918
39113919 /**
3912- * Will process pattern keys: Attributes evaluation and constant folding. Checks for duplicate keys and
3913- * that only literals and attributes lookups are being matched.
3920+ * Will process pattern keys: Attributes evaluation and constant folding. Checks for
3921+ * duplicate keys and that only literals and attributes lookups are being matched.
39143922 *
39153923 * Generates array.
39163924 *
@@ -3962,56 +3970,56 @@ private void mappingVisitSubpatterns(PatternTy[] patterns, BytecodeLocal values,
39623970 int patLen = patterns .length ;
39633971
39643972 b .beginBlock ();
3965- // unpack values from pc.subject
3966- BytecodeLocal valuesUnpacked = b .createLocal ();
3967- b .beginStoreLocal (valuesUnpacked );
3968- b .beginUnpackSequence (patLen );
3969- b .emitLoadLocal (values );
3970- b .endUnpackSequence ();
3971- b .endStoreLocal ();
3972-
3973- // backup pc.subject, it will get replaced for sub-patterns
3974- BytecodeLocal pcSave = patternContextSubjectSave (pc );
3973+ // unpack values from pc.subject
3974+ BytecodeLocal valuesUnpacked = b .createLocal ();
3975+ b .beginStoreLocal (valuesUnpacked );
3976+ b .beginUnpackSequence (patLen );
3977+ b .emitLoadLocal (values );
3978+ b .endUnpackSequence ();
3979+ b .endStoreLocal ();
39753980
3976- BytecodeLocal temp = b .createLocal ();
3977- b .beginStoreLocal (temp );
3978- b .beginPrimitiveBoolAnd ();
3979- boolean hadNonWildcardPattern = false ;
3980- for (int i = 0 ; i < patLen ; i ++) {
3981- if (wildcardCheck (patterns [i ])) {
3982- continue ;
3983- }
3984- hadNonWildcardPattern = true ;
3985- b .beginBlock ();
3986- b .beginStoreLocal (pc .subject );
3987- b .beginArrayIndex (i );
3988- b .emitLoadLocal (valuesUnpacked );
3989- b .endArrayIndex ();
3990- b .endStoreLocal ();
3981+ // backup pc.subject, it will get replaced for sub-patterns
3982+ BytecodeLocal pcSave = patternContextSubjectSave (pc );
39913983
3992- visitSubpattern (patterns [i ], pc );
3993- b .endBlock ();
3994- }
3995- if (!hadNonWildcardPattern ) {
3996- b .emitLoadConstant (true );
3997- }
3998- b .endPrimitiveBoolAnd ();
3984+ BytecodeLocal temp = b .createLocal ();
3985+ b .beginStoreLocal (temp );
3986+ b .beginPrimitiveBoolAnd ();
3987+ boolean hadNonWildcardPattern = false ;
3988+ for (int i = 0 ; i < patLen ; i ++) {
3989+ if (wildcardCheck (patterns [i ])) {
3990+ continue ;
3991+ }
3992+ hadNonWildcardPattern = true ;
3993+ b .beginBlock ();
3994+ b .beginStoreLocal (pc .subject );
3995+ b .beginArrayIndex (i );
3996+ b .emitLoadLocal (valuesUnpacked );
3997+ b .endArrayIndex ();
39993998 b .endStoreLocal ();
40003999
4001- patternContextSubjectLoad (pcSave , pc );
4000+ visitSubpattern (patterns [i ], pc );
4001+ b .endBlock ();
4002+ }
4003+ if (!hadNonWildcardPattern ) {
4004+ b .emitLoadConstant (true );
4005+ }
4006+ b .endPrimitiveBoolAnd ();
4007+ b .endStoreLocal ();
40024008
4003- b .emitLoadLocal (temp );
4009+ patternContextSubjectLoad (pcSave , pc );
4010+
4011+ b .emitLoadLocal (temp );
40044012 b .endBlock ();
40054013 }
40064014
40074015 private void doVisitPattern (PatternTy .MatchMapping node , PatternContext pc ) {
40084016 /**
4009- * Mapping pattern match will take the keys and check, whether the keys in the pattern are
4010- * present in the subject. This is good enough, since the pattern needs only to be a subset of the subject.
4011- * Keys aren't evaluated as subpatterns.
4017+ * Mapping pattern match will take the keys and check, whether the keys in the pattern
4018+ * are present in the subject. This is good enough, since the pattern needs only to be a
4019+ * subset of the subject. Keys aren't evaluated as subpatterns.
40124020 *
4013- * After the key check, the values of the pattern are patterns as well and are evaluated as sub-patterns
4014- * with values in the subject used as separate respective subjects.
4021+ * After the key check, the values of the pattern are patterns as well and are evaluated
4022+ * as sub-patterns with values in the subject used as separate respective subjects.
40154023 */
40164024 ExprTy [] keys = node .keys ;
40174025 PatternTy [] patterns = node .patterns ;
0 commit comments