34
34
import org .truffleruby .annotations .Primitive ;
35
35
import org .truffleruby .annotations .Visibility ;
36
36
import org .truffleruby .builtins .CoreMethodArrayArgumentsNode ;
37
- import org .truffleruby .builtins .CoreMethodNode ;
38
37
import org .truffleruby .builtins .PrimitiveArrayArgumentsNode ;
39
38
import org .truffleruby .cext .UnwrapNode .UnwrapCArrayNode ;
40
39
import org .truffleruby .core .MarkingService .ExtensionCallStack ;
87
86
import org .truffleruby .language .RubyBaseNode ;
88
87
import org .truffleruby .language .RubyDynamicObject ;
89
88
import org .truffleruby .language .RubyGuards ;
90
- import org .truffleruby .language .RubyNode ;
91
89
import org .truffleruby .language .RubyRootNode ;
92
90
import org .truffleruby .language .WarnNode ;
93
91
import org .truffleruby .language .arguments .ArgumentsDescriptor ;
127
125
import com .oracle .truffle .api .dsl .Cached ;
128
126
import com .oracle .truffle .api .dsl .Cached .Shared ;
129
127
import com .oracle .truffle .api .dsl .Fallback ;
130
- import com .oracle .truffle .api .dsl .NodeChild ;
131
128
import com .oracle .truffle .api .dsl .ReportPolymorphism ;
132
129
import com .oracle .truffle .api .dsl .Specialization ;
133
130
import com .oracle .truffle .api .frame .Frame ;
139
136
import com .oracle .truffle .api .nodes .IndirectCallNode ;
140
137
import com .oracle .truffle .api .nodes .Node ;
141
138
import com .oracle .truffle .api .nodes .RootNode ;
142
- import com .oracle .truffle .api .profiles .BranchProfile ;
143
- import com .oracle .truffle .api .profiles .ConditionProfile ;
144
139
import com .oracle .truffle .api .source .SourceSection ;
145
140
import org .truffleruby .parser .RubySource ;
146
141
@@ -682,7 +677,7 @@ public abstract static class DBL2BIGNode extends CoreMethodArrayArgumentsNode {
682
677
@ Specialization
683
678
protected Object dbl2big (double num ,
684
679
@ Cached FloatToIntegerNode floatToIntegerNode ) {
685
- return floatToIntegerNode .fixnumOrBignum ( num );
680
+ return floatToIntegerNode .execute ( this , num );
686
681
}
687
682
688
683
}
@@ -996,9 +991,7 @@ protected ImmutableRubyString rbStrUnlockTmpImmutable(ImmutableRubyString string
996
991
}
997
992
998
993
@ CoreMethod (names = "rb_const_get" , onSingleton = true , required = 2 )
999
- @ NodeChild (value = "module" , type = RubyNode .class )
1000
- @ NodeChild (value = "name" , type = RubyNode .class )
1001
- public abstract static class RbConstGetNode extends CoreMethodNode {
994
+ public abstract static class RbConstGetNode extends CoreMethodArrayArgumentsNode {
1002
995
1003
996
@ Child private LookupConstantNode lookupConstantNode = LookupConstantNode .create (true , true );
1004
997
@@ -1015,9 +1008,7 @@ protected Object rbConstGet(RubyModule module, Object name,
1015
1008
}
1016
1009
1017
1010
@ CoreMethod (names = "rb_const_get_from" , onSingleton = true , required = 2 )
1018
- @ NodeChild (value = "module" , type = RubyNode .class )
1019
- @ NodeChild (value = "name" , type = RubyNode .class )
1020
- public abstract static class RbConstGetFromNode extends CoreMethodNode {
1011
+ public abstract static class RbConstGetFromNode extends CoreMethodArrayArgumentsNode {
1021
1012
1022
1013
@ Child private LookupConstantNode lookupConstantNode = LookupConstantNode .create (true , false );
1023
1014
@@ -1034,10 +1025,7 @@ protected Object rbConstGetFrom(RubyModule module, Object name,
1034
1025
}
1035
1026
1036
1027
@ CoreMethod (names = "rb_const_set" , onSingleton = true , required = 3 )
1037
- @ NodeChild (value = "module" , type = RubyNode .class )
1038
- @ NodeChild (value = "name" , type = RubyNode .class )
1039
- @ NodeChild (value = "value" , type = RubyNode .class )
1040
- public abstract static class RbConstSetNode extends CoreMethodNode {
1028
+ public abstract static class RbConstSetNode extends CoreMethodArrayArgumentsNode {
1041
1029
1042
1030
1043
1031
@ Specialization
@@ -1106,11 +1094,10 @@ protected int getCacheLimit() {
1106
1094
@ CoreMethod (names = "cext_module_function" , onSingleton = true , required = 2 )
1107
1095
public abstract static class CextModuleFunctionNode extends CoreMethodArrayArgumentsNode {
1108
1096
1109
- @ Child SetMethodVisibilityNode setMethodVisibilityNode = SetMethodVisibilityNode .create ();
1110
-
1111
1097
@ Specialization
1112
- protected RubyModule cextModuleFunction (RubyModule module , RubySymbol name ) {
1113
- setMethodVisibilityNode .execute (module , name , Visibility .MODULE_FUNCTION );
1098
+ protected RubyModule cextModuleFunction (RubyModule module , RubySymbol name ,
1099
+ @ Cached SetMethodVisibilityNode setMethodVisibilityNode ) {
1100
+ setMethodVisibilityNode .execute (this , module , name , Visibility .MODULE_FUNCTION );
1114
1101
return module ;
1115
1102
}
1116
1103
@@ -1960,14 +1947,16 @@ public abstract static class RBSprintfFormatNode extends CoreMethodArrayArgument
1960
1947
@ Specialization (
1961
1948
guards = {
1962
1949
"libFormat.isRubyString(format)" ,
1963
- "equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1950
+ "equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
1964
1951
limit = "2" )
1965
- protected Object typesCached (VirtualFrame frame , Object format ,
1952
+
1953
+ protected static Object typesCached (VirtualFrame frame , Object format ,
1966
1954
@ Cached @ Shared RubyStringLibrary libFormat ,
1967
1955
@ Cached ("asTruffleStringUncached(format)" ) TruffleString cachedFormat ,
1968
1956
@ Cached ("libFormat.getEncoding(format)" ) RubyEncoding cachedEncoding ,
1969
1957
@ Cached ("compileArgTypes(cachedFormat, cachedEncoding, byteArrayNode)" ) RubyArray cachedTypes ,
1970
- @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ) {
1958
+ @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ,
1959
+ @ Bind ("this" ) Node node ) {
1971
1960
return cachedTypes ;
1972
1961
}
1973
1962
@@ -1993,41 +1982,43 @@ protected RubyArray compileArgTypes(AbstractTruffleString format, RubyEncoding e
1993
1982
@ ReportPolymorphism
1994
1983
public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode {
1995
1984
1996
- @ Child private TruffleString .FromByteArrayNode fromByteArrayNode ;
1997
-
1998
- private final BranchProfile exceptionProfile = BranchProfile .create ();
1999
- private final ConditionProfile resizeProfile = ConditionProfile .create ();
2000
-
2001
1985
@ Specialization (
2002
1986
guards = {
2003
1987
"libFormat.isRubyString(format)" ,
2004
- "equalNode.execute(libFormat, format, cachedFormat, cachedEncoding)" },
1988
+ "equalNode.execute(node, libFormat, format, cachedFormat, cachedEncoding)" },
2005
1989
limit = "2" )
2006
- protected RubyString formatCached (Object format , Object stringReader , RubyArray argArray ,
1990
+ protected static RubyString formatCached (Object format , Object stringReader , RubyArray argArray ,
2007
1991
@ Cached @ Shared ArrayToObjectArrayNode arrayToObjectArrayNode ,
2008
1992
@ Cached @ Shared RubyStringLibrary libFormat ,
1993
+ @ Cached @ Shared InlinedBranchProfile exceptionProfile ,
1994
+ @ Cached @ Shared InlinedConditionProfile resizeProfile ,
1995
+ @ Cached @ Shared TruffleString .FromByteArrayNode fromByteArrayNode ,
2009
1996
@ Cached ("asTruffleStringUncached(format)" ) TruffleString cachedFormat ,
2010
1997
@ Cached ("libFormat.getEncoding(format)" ) RubyEncoding cachedEncoding ,
2011
1998
@ Cached ("cachedFormat.byteLength(cachedEncoding.tencoding)" ) int cachedFormatLength ,
2012
1999
@ Cached ("create(compileFormat(cachedFormat, cachedEncoding, stringReader))" ) DirectCallNode formatNode ,
2013
- @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ) {
2000
+ @ Cached StringHelperNodes .EqualSameEncodingNode equalNode ,
2001
+ @ Bind ("this" ) Node node ) {
2014
2002
final BytesResult result ;
2015
2003
final Object [] arguments = arrayToObjectArrayNode .executeToObjectArray (argArray );
2016
2004
try {
2017
2005
result = (BytesResult ) formatNode .call (new Object []{ arguments , arguments .length , null });
2018
2006
} catch (FormatException e ) {
2019
- exceptionProfile .enter ();
2020
- throw FormatExceptionTranslator .translate (getContext (), this , e );
2007
+ exceptionProfile .enter (node );
2008
+ throw FormatExceptionTranslator .translate (getContext (node ), node , e );
2021
2009
}
2022
2010
2023
- return finishFormat (cachedFormatLength , result );
2011
+ return finishFormat (node , cachedFormatLength , result , resizeProfile , fromByteArrayNode );
2024
2012
}
2025
2013
2026
2014
@ Specialization (
2027
2015
guards = "libFormat.isRubyString(format)" ,
2028
2016
replaces = "formatCached" , limit = "1" )
2029
2017
protected RubyString formatUncached (Object format , Object stringReader , RubyArray argArray ,
2030
2018
@ Cached IndirectCallNode formatNode ,
2019
+ @ Cached @ Shared InlinedBranchProfile exceptionProfile ,
2020
+ @ Cached @ Shared InlinedConditionProfile resizeProfile ,
2021
+ @ Cached @ Shared TruffleString .FromByteArrayNode fromByteArrayNode ,
2031
2022
@ Cached @ Shared ArrayToObjectArrayNode arrayToObjectArrayNode ,
2032
2023
@ Cached @ Shared RubyStringLibrary libFormat ) {
2033
2024
var tstring = libFormat .getTString (format );
@@ -2038,26 +2029,23 @@ protected RubyString formatUncached(Object format, Object stringReader, RubyArra
2038
2029
result = (BytesResult ) formatNode .call (compileFormat (tstring , encoding , stringReader ),
2039
2030
new Object []{ arguments , arguments .length , null });
2040
2031
} catch (FormatException e ) {
2041
- exceptionProfile .enter ();
2032
+ exceptionProfile .enter (this );
2042
2033
throw FormatExceptionTranslator .translate (getContext (), this , e );
2043
2034
}
2044
2035
2045
- return finishFormat (tstring .byteLength (encoding .tencoding ), result );
2036
+ return finishFormat (this , tstring .byteLength (encoding .tencoding ), result , resizeProfile , fromByteArrayNode );
2046
2037
}
2047
2038
2048
- private RubyString finishFormat (int formatLength , BytesResult result ) {
2039
+ private static RubyString finishFormat (Node node , int formatLength , BytesResult result ,
2040
+ InlinedConditionProfile resizeProfile , TruffleString .FromByteArrayNode fromByteArrayNode ) {
2049
2041
byte [] bytes = result .getOutput ();
2050
2042
2051
- if (resizeProfile .profile (bytes .length != result .getOutputLength ())) {
2043
+ if (resizeProfile .profile (node , bytes .length != result .getOutputLength ())) {
2052
2044
bytes = Arrays .copyOf (bytes , result .getOutputLength ());
2053
2045
}
2054
2046
2055
- if (fromByteArrayNode == null ) {
2056
- CompilerDirectives .transferToInterpreterAndInvalidate ();
2057
- fromByteArrayNode = insert (TruffleString .FromByteArrayNode .create ());
2058
- }
2059
-
2060
- return createString (fromByteArrayNode , bytes , result .getEncoding ().getEncodingForLength (formatLength ));
2047
+ return createString (node , fromByteArrayNode , bytes ,
2048
+ result .getEncoding ().getEncodingForLength (formatLength ));
2061
2049
}
2062
2050
2063
2051
@ TruffleBoundary
0 commit comments