4242
4343import com .oracle .truffle .api .CallTarget ;
4444import com .oracle .truffle .api .CompilerDirectives ;
45- import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
4645import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
4746import com .oracle .truffle .api .RootCallTarget ;
4847import com .oracle .truffle .api .TruffleLanguage ;
5756import com .oracle .truffle .api .interop .InteropLibrary ;
5857import com .oracle .truffle .api .interop .TruffleObject ;
5958import com .oracle .truffle .api .interop .UnknownIdentifierException ;
60- import com .oracle .truffle .api .interop .UnsupportedMessageException ;
61- import com .oracle .truffle .api .interop .UnsupportedTypeException ;
6259import com .oracle .truffle .api .library .ExportLibrary ;
6360import com .oracle .truffle .api .library .ExportMessage ;
6461import com .oracle .truffle .api .nodes .DirectCallNode ;
6764import com .oracle .truffle .api .strings .TruffleString ;
6865import com .oracle .truffle .regex .literal .LiteralRegexExecNode ;
6966import com .oracle .truffle .regex .result .RegexResult ;
70- import com .oracle .truffle .regex .tregex .TRegexCompilationRequest ;
7167import com .oracle .truffle .regex .util .TruffleReadOnlyKeysArray ;
7268
7369/**
@@ -147,26 +143,26 @@ public final class RegexObject extends AbstractConstantKeysObject {
147143 private static final String PROP_IS_BACKTRACKING = "isBacktracking" ;
148144 private static final TruffleReadOnlyKeysArray KEYS = new TruffleReadOnlyKeysArray (PROP_EXEC , PROP_EXEC_BOOLEAN , PROP_PATTERN , PROP_FLAGS , PROP_GROUP_COUNT , PROP_GROUPS , PROP_IS_BACKTRACKING );
149145
150- private final RegexLanguage language ;
151146 private final RegexSource source ;
152147 private final AbstractRegexObject flags ;
153148 private final int numberOfCaptureGroups ;
154149 private final AbstractRegexObject namedCaptureGroups ;
155- @ CompilationFinal private RootCallTarget execRootCallTarget ;
156- @ CompilationFinal private RootCallTarget execBooleanRootCallTarget ;
150+ private final RootCallTarget execRootCallTarget ;
151+ private final RootCallTarget execBooleanRootCallTarget ;
157152 private final boolean backtracking ;
158153
159- public RegexObject (RegexExecNode execNode , RegexSource source , AbstractRegexObject flags , int numberOfCaptureGroups , AbstractRegexObject namedCaptureGroups ) {
160- this .language = execNode .getRegexLanguage ();
154+ public RegexObject (RegexLanguage language , RegexSource source , RegexExecNode execNode , AbstractRegexObject flags , int numberOfCaptureGroups , AbstractRegexObject namedCaptureGroups ) {
161155 this .source = source ;
162156 this .flags = flags ;
163157 this .numberOfCaptureGroups = numberOfCaptureGroups ;
164158 this .namedCaptureGroups = namedCaptureGroups ;
165- RegexRootNode rootNode = new RegexRootNode (execNode .getRegexLanguage (), execNode );
166- if (execNode .isBooleanMatch ()) {
159+ RegexRootNode rootNode = new RegexRootNode (language , source , execNode );
160+ if (source .getOptions ().isBooleanMatch ()) {
161+ this .execRootCallTarget = new RegexRootNode (language , source .withoutBooleanMatch (), null ).getCallTarget ();
167162 this .execBooleanRootCallTarget = rootNode .getCallTarget ();
168163 } else {
169164 this .execRootCallTarget = rootNode .getCallTarget ();
165+ this .execBooleanRootCallTarget = new RegexRootNode (language , source .withBooleanMatch (), null ).getCallTarget ();
170166 }
171167 this .backtracking = execNode .isBacktracking ();
172168 }
@@ -209,19 +205,10 @@ private static RegexRootNode getRootNode(RootCallTarget execRootCallTarget) {
209205 }
210206
211207 public CallTarget getExecCallTarget () {
212- if (execRootCallTarget == null ) {
213- CompilerDirectives .transferToInterpreterAndInvalidate ();
214- execRootCallTarget = new RegexRootNode (language ,
215- new TRegexCompilationRequest (language , getRootNode (execBooleanRootCallTarget ).getSource ().withoutBooleanMatch ()).compile ()).getCallTarget ();
216- }
217208 return execRootCallTarget ;
218209 }
219210
220211 public CallTarget getExecBooleanCallTarget () {
221- if (execBooleanRootCallTarget == null ) {
222- CompilerDirectives .transferToInterpreterAndInvalidate ();
223- execBooleanRootCallTarget = new RegexRootNode (language , new TRegexCompilationRequest (language , getRootNode (execRootCallTarget ).getSource ().withBooleanMatch ()).compile ()).getCallTarget ();
224- }
225212 return execBooleanRootCallTarget ;
226213 }
227214
@@ -313,8 +300,7 @@ static boolean isInvocable(RegexObject receiver, String symbol) {
313300
314301 @ ExportMessage
315302 Object invokeMember (String member , Object [] args ,
316- @ Cached InvokeCacheNode invokeCache )
317- throws UnknownIdentifierException , ArityException , UnsupportedTypeException , UnsupportedMessageException {
303+ @ Cached InvokeCacheNode invokeCache ) throws UnknownIdentifierException , ArityException {
318304 checkArity (args );
319305 return invokeCache .execute (member , this , args );
320306 }
@@ -324,46 +310,45 @@ Object invokeMember(String member, Object[] args,
324310 @ GenerateUncached
325311 abstract static class InvokeCacheNode extends Node {
326312
327- abstract Object execute (String symbol , RegexObject receiver , Object [] args )
328- throws UnsupportedMessageException , ArityException , UnsupportedTypeException , UnknownIdentifierException ;
313+ abstract Object execute (String symbol , RegexObject receiver , Object [] args ) throws UnknownIdentifierException ;
329314
330315 @ SuppressWarnings ("unused" )
331316 @ Specialization (guards = {"symbol == cachedSymbol" , "cachedSymbol.equals(PROP_EXEC)" }, limit = N_METHODS )
332317 Object execIdentity (String symbol , RegexObject receiver , Object [] args ,
333318 @ Cached ("symbol" ) String cachedSymbol ,
334- @ Cached @ Shared ExecCompiledRegexNode execNode ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException {
319+ @ Cached @ Shared ExecCompiledRegexNode execNode ) {
335320 return execNode .execute (receiver , args );
336321 }
337322
338323 @ SuppressWarnings ("unused" )
339324 @ Specialization (guards = {"symbol.equals(cachedSymbol)" , "cachedSymbol.equals(PROP_EXEC)" }, limit = N_METHODS , replaces = "execIdentity" )
340325 Object execEquals (String symbol , RegexObject receiver , Object [] args ,
341326 @ Cached ("symbol" ) String cachedSymbol ,
342- @ Cached @ Shared ExecCompiledRegexNode execNode ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException {
327+ @ Cached @ Shared ExecCompiledRegexNode execNode ) {
343328 return execNode .execute (receiver , args );
344329 }
345330
346331 @ SuppressWarnings ("unused" )
347332 @ Specialization (guards = {"symbol == cachedSymbol" , "cachedSymbol.equals(PROP_EXEC_BOOLEAN)" }, limit = N_METHODS )
348333 boolean execBooleanIdentity (String symbol , RegexObject receiver , Object [] args ,
349334 @ Cached ("symbol" ) String cachedSymbol ,
350- @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException {
335+ @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) {
351336 return execBoolNode .execute (receiver , args ) != RegexResult .getNoMatchInstance ();
352337 }
353338
354339 @ SuppressWarnings ("unused" )
355340 @ Specialization (guards = {"symbol.equals(cachedSymbol)" , "cachedSymbol.equals(PROP_EXEC_BOOLEAN)" }, limit = N_METHODS , replaces = "execBooleanIdentity" )
356341 boolean execBooleanEquals (String symbol , RegexObject receiver , Object [] args ,
357342 @ Cached ("symbol" ) String cachedSymbol ,
358- @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException {
343+ @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) {
359344 return execBoolNode .execute (receiver , args ) != RegexResult .getNoMatchInstance ();
360345 }
361346
362347 @ ReportPolymorphism .Megamorphic
363348 @ Specialization (replaces = {"execEquals" , "execBooleanEquals" })
364349 static Object invokeGeneric (String symbol , RegexObject receiver , Object [] args ,
365350 @ Cached @ Shared ExecCompiledRegexNode execNode ,
366- @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException , UnknownIdentifierException {
351+ @ Cached @ Shared ExecBooleanCompiledRegexNode execBoolNode ) throws UnknownIdentifierException {
367352 switch (symbol ) {
368353 case PROP_EXEC :
369354 return execNode .execute (receiver , args );
@@ -393,7 +378,7 @@ boolean isExecutable() {
393378
394379 @ ExportMessage
395380 Object execute (Object [] args ,
396- @ Cached ExecCompiledRegexNode execNode ) throws ArityException , UnsupportedTypeException , UnsupportedMessageException {
381+ @ Cached ExecCompiledRegexNode execNode ) throws ArityException {
397382 checkArity (args );
398383 return execNode .execute (regex , args );
399384 }
@@ -422,7 +407,7 @@ boolean isExecutable() {
422407
423408 @ ExportMessage
424409 boolean execute (Object [] args ,
425- @ Cached ExecBooleanCompiledRegexNode execNode ) throws ArityException , UnsupportedTypeException , UnsupportedMessageException {
410+ @ Cached ExecBooleanCompiledRegexNode execNode ) throws ArityException {
426411 checkArity (args );
427412 return execNode .execute (regex , args ) != RegexResult .getNoMatchInstance ();
428413 }
@@ -439,7 +424,7 @@ public String toString() {
439424 @ GenerateUncached
440425 abstract static class ExecCompiledRegexNode extends Node {
441426
442- abstract Object execute (RegexObject receiver , Object [] args ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException ;
427+ abstract Object execute (RegexObject receiver , Object [] args );
443428
444429 @ SuppressWarnings ("unused" )
445430 @ Specialization (guards = "receiver == cachedReceiver" , limit = "4" )
@@ -462,7 +447,7 @@ static Object doIndirectCall(RegexObject receiver, Object[] args,
462447 @ GenerateUncached
463448 abstract static class ExecBooleanCompiledRegexNode extends Node {
464449
465- abstract Object execute (RegexObject receiver , Object [] args ) throws UnsupportedMessageException , ArityException , UnsupportedTypeException ;
450+ abstract Object execute (RegexObject receiver , Object [] args );
466451
467452 @ SuppressWarnings ("unused" )
468453 @ Specialization (guards = "receiver == cachedReceiver" , limit = "4" )
0 commit comments