@@ -128,9 +128,9 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
128
128
public void initialize (Python3Core core ) {
129
129
addBuiltinConstant ("_with_tregex" , core .getContext ().getLanguage ().getEngineOption (PythonOptions .WithTRegex ));
130
130
addBuiltinConstant ("_with_sre" , core .getContext ().getLanguage ().getEngineOption (PythonOptions .TRegexUsesSREFallback ));
131
- addBuiltinConstant ("_METHOD_SEARCH" , PythonMethod .search . ordinal () );
132
- addBuiltinConstant ("_METHOD_MATCH" , PythonMethod .match . ordinal () );
133
- addBuiltinConstant ("_METHOD_FULLMATCH" , PythonMethod .fullmatch . ordinal () );
131
+ addBuiltinConstant ("_METHOD_SEARCH" , PythonMethod .search );
132
+ addBuiltinConstant ("_METHOD_MATCH" , PythonMethod .match );
133
+ addBuiltinConstant ("_METHOD_FULLMATCH" , PythonMethod .fullmatch );
134
134
super .initialize (core );
135
135
}
136
136
@@ -481,45 +481,43 @@ abstract static class TRegexCompile extends PythonTernaryBuiltinNode {
481
481
private static final TruffleString T__GETLOCALE = tsLiteral ("_getlocale" );
482
482
483
483
@ Specialization (guards = {"tRegexCache == cachedTRegexCache" , "method == cachedMethod" , "mustAdvance == cachedMustAdvance" , "!cachedTRegexCache.isLocaleSensitive()" }, limit = "2" )
484
- Object cached (TRegexCache tRegexCache , int method , boolean mustAdvance ,
484
+ Object cached (TRegexCache tRegexCache , PythonMethod method , boolean mustAdvance ,
485
485
@ Cached ("tRegexCache" ) TRegexCache cachedTRegexCache ,
486
- @ Cached ("method" ) int cachedMethod ,
486
+ @ Cached ("method" ) PythonMethod cachedMethod ,
487
487
@ Cached ("mustAdvance" ) boolean cachedMustAdvance ,
488
488
@ Cached ("getCompiledRegex(tRegexCache, method, mustAdvance)" ) Object compiledRegex ) {
489
489
return compiledRegex ;
490
490
}
491
491
492
- protected Object getCompiledRegex (TRegexCache tRegexCache , int method , boolean mustAdvance ) {
493
- return localeNonSensitive (tRegexCache , method , mustAdvance , method , mustAdvance , PythonMethod . fromOrdinal ( method ) );
492
+ protected Object getCompiledRegex (TRegexCache tRegexCache , PythonMethod method , boolean mustAdvance ) {
493
+ return localeNonSensitive (tRegexCache , method , mustAdvance , method , mustAdvance );
494
494
}
495
495
496
496
@ Specialization (guards = {"method == cachedMethod" , "mustAdvance == cachedMustAdvance" , "!tRegexCache.isLocaleSensitive()" }, limit = "6" )
497
- Object localeNonSensitive (TRegexCache tRegexCache , int method , boolean mustAdvance ,
498
- @ Cached ("method" ) int cachedMethod ,
499
- @ Cached ("mustAdvance" ) boolean cachedMustAdvance ,
500
- @ Cached ("fromOrdinal(method)" ) PythonMethod pythonMethod ) {
501
- final Object tRegex = tRegexCache .getRegexp (pythonMethod , mustAdvance );
497
+ Object localeNonSensitive (TRegexCache tRegexCache , PythonMethod method , boolean mustAdvance ,
498
+ @ Cached ("method" ) PythonMethod cachedMethod ,
499
+ @ Cached ("mustAdvance" ) boolean cachedMustAdvance ) {
500
+ final Object tRegex = tRegexCache .getRegexp (method , mustAdvance );
502
501
if (tRegex != null ) {
503
502
return tRegex ;
504
503
} else {
505
- return tRegexCache .compile (getContext (), pythonMethod , mustAdvance , null );
504
+ return tRegexCache .compile (getContext (), method , mustAdvance , null );
506
505
}
507
506
}
508
507
509
508
@ Specialization (guards = {"method == cachedMethod" , "mustAdvance == cachedMustAdvance" , "tRegexCache.isLocaleSensitive()" }, limit = "6" )
510
- Object localeSensitive (TRegexCache tRegexCache , int method , boolean mustAdvance ,
511
- @ Cached ("method" ) int cachedMethod ,
509
+ Object localeSensitive (TRegexCache tRegexCache , PythonMethod method , boolean mustAdvance ,
510
+ @ Cached ("method" ) PythonMethod cachedMethod ,
512
511
@ Cached ("mustAdvance" ) boolean cachedMustAdvance ,
513
- @ Cached ("fromOrdinal(method)" ) PythonMethod pythonMethod ,
514
512
@ Cached ("lookupGetLocaleFunction()" ) Object getLocale ,
515
513
@ Cached CallNode callGetLocale ,
516
514
@ Cached CastToTruffleStringNode castToTruffleStringNode ) {
517
515
TruffleString locale = castToTruffleStringNode .execute (callGetLocale .execute (getLocale ));
518
- final Object tRegex = tRegexCache .getLocaleSensitiveRegexp (pythonMethod , mustAdvance , locale );
516
+ final Object tRegex = tRegexCache .getLocaleSensitiveRegexp (method , mustAdvance , locale );
519
517
if (tRegex != null ) {
520
518
return tRegex ;
521
519
} else {
522
- return tRegexCache .compile (getContext (), pythonMethod , mustAdvance , locale );
520
+ return tRegexCache .compile (getContext (), method , mustAdvance , locale );
523
521
}
524
522
}
525
523
@@ -613,10 +611,10 @@ abstract static class TRegexSearch extends PythonSenaryBuiltinNode {
613
611
614
612
@ Specialization (guards = {"isSingleContext()" , "pattern == cachedPattern" , "method == cachedMethod" , "mustAdvance == cachedMustAdvance" , "!tRegexCache.isLocaleSensitive()" }, limit = "1" )
615
613
@ SuppressWarnings ("truffle-static-method" )
616
- protected Object doCached (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , int method , boolean mustAdvance ,
614
+ protected Object doCached (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , PythonMethod method , boolean mustAdvance ,
617
615
@ Bind ("this" ) Node inliningTarget ,
618
616
@ Cached ("pattern" ) Object cachedPattern ,
619
- @ Cached ("method" ) int cachedMethod ,
617
+ @ Cached ("method" ) PythonMethod cachedMethod ,
620
618
@ Cached ("mustAdvance" ) boolean cachedMustAdvance ,
621
619
@ Cached @ Shared ReadAttributeFromObjectNode readCacheNode ,
622
620
@ Cached @ Shared TRegexCompile tRegexCompileNode ,
@@ -629,7 +627,7 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
629
627
@ Cached @ Shared PyNumberAsSizeNode asSizeNode ,
630
628
@ Cached @ Shared PyObjectSizeNode lengthNode ,
631
629
@ CachedLibrary (limit = "1" ) @ Shared InteropLibrary libCompiledRegex ,
632
- @ Cached ("create(getMethodName(method ))" ) GetAttributeNode getFallbackMethodNode ,
630
+ @ Cached ("create(method. getMethodName())" ) GetAttributeNode getFallbackMethodNode ,
633
631
@ Cached @ Shared TRegexCallExec tRegexCallExec ,
634
632
@ Cached @ Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode ) {
635
633
reCheckInputTypeNode .execute (frame , input , tRegexCache .isBinary ());
@@ -665,9 +663,9 @@ protected Object doCached(VirtualFrame frame, Object pattern, Object input, Obje
665
663
@ Specialization (guards = {"tRegexCompileNode.execute(frame, getTRegexCache(readCacheNode, pattern), method, mustAdvance) == compiledRegex" , "method == cachedMethod" ,
666
664
"mustAdvance == cachedMustAdvance" , "!tRegexCache.isLocaleSensitive()" }, limit = "1" )
667
665
@ SuppressWarnings ("truffle-static-method" )
668
- protected Object doCachedRegex (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , int method , boolean mustAdvance ,
666
+ protected Object doCachedRegex (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , PythonMethod method , boolean mustAdvance ,
669
667
@ Bind ("this" ) Node inliningTarget ,
670
- @ Cached ("method" ) int cachedMethod ,
668
+ @ Cached ("method" ) PythonMethod cachedMethod ,
671
669
@ Cached ("mustAdvance" ) boolean cachedMustAdvance ,
672
670
@ Cached @ Shared ReadAttributeFromObjectNode readCacheNode ,
673
671
@ Cached @ Shared TRegexCompile tRegexCompileNode ,
@@ -680,7 +678,7 @@ protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input,
680
678
@ Cached @ Shared PyNumberAsSizeNode asSizeNode ,
681
679
@ Cached @ Shared PyObjectSizeNode lengthNode ,
682
680
@ CachedLibrary (limit = "1" ) @ Shared InteropLibrary libCompiledRegex ,
683
- @ Cached ("create(getMethodName(method ))" ) GetAttributeNode getFallbackMethodNode ,
681
+ @ Cached ("create(method. getMethodName())" ) GetAttributeNode getFallbackMethodNode ,
684
682
@ Cached @ Shared TRegexCallExec tRegexCallExec ,
685
683
@ Cached @ Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode ) {
686
684
return doCached (frame , pattern , input , posArg , endPosArg , method , mustAdvance , inliningTarget , pattern , cachedMethod , mustAdvance , readCacheNode , tRegexCompileNode , tRegexCache ,
@@ -691,9 +689,9 @@ protected Object doCachedRegex(VirtualFrame frame, Object pattern, Object input,
691
689
@ Specialization (guards = "method == cachedMethod" , limit = "3" , replaces = {"doCached" , "doCachedRegex" })
692
690
@ SuppressWarnings ("truffle-static-method" )
693
691
@ ReportPolymorphism .Megamorphic
694
- protected Object doDynamic (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , int method , boolean mustAdvance ,
692
+ protected Object doDynamic (VirtualFrame frame , Object pattern , Object input , Object posArg , Object endPosArg , PythonMethod method , boolean mustAdvance ,
695
693
@ Bind ("this" ) Node inliningTarget ,
696
- @ Cached ("method" ) int cachedMethod ,
694
+ @ Cached ("method" ) PythonMethod cachedMethod ,
697
695
@ Cached @ Shared ReadAttributeFromObjectNode readCacheNode ,
698
696
@ Cached @ Shared TRegexCompile tRegexCompileNode ,
699
697
@ Cached @ Shared PyNumberIndexNode indexNode ,
@@ -703,7 +701,7 @@ protected Object doDynamic(VirtualFrame frame, Object pattern, Object input, Obj
703
701
@ Cached @ Shared InlinedConditionProfile fallbackProfile ,
704
702
@ Cached @ Shared InlinedConditionProfile truncatingInputProfile ,
705
703
@ CachedLibrary (limit = "1" ) @ Shared InteropLibrary libCompiledRegex ,
706
- @ Cached ("create(getMethodName(method ))" ) GetAttributeNode getFallbackMethodNode ,
704
+ @ Cached ("create(method. getMethodName())" ) GetAttributeNode getFallbackMethodNode ,
707
705
@ Cached @ Shared TRegexCallExec tRegexCallExec ,
708
706
@ Cached @ Shared CreateMatchFromTRegexResultNode createMatchFromTRegexResultNode ) {
709
707
TRegexCache tRegexCache = getTRegexCache (readCacheNode , pattern );
@@ -717,10 +715,6 @@ protected static TRegexCache getTRegexCache(ReadAttributeFromObjectNode readCach
717
715
return (TRegexCache ) readCacheNode .execute (pattern , T__PATTERN__TREGEX_CACHE );
718
716
}
719
717
720
- protected static TruffleString getMethodName (int method ) {
721
- return PythonMethod .fromOrdinal (method ).getMethodName ();
722
- }
723
-
724
718
private GetAttributeNode getGetFallbackCompileNode () {
725
719
if (getFallbackCompileNode == null ) {
726
720
CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments