75
75
import com .oracle .graal .python .builtins .objects .cext .PythonNativeObject ;
76
76
import com .oracle .graal .python .builtins .objects .cext .PythonNativeVoidPtr ;
77
77
import com .oracle .graal .python .builtins .objects .cext .capi .CApiContext .LLVMType ;
78
- import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .AllToJavaNodeGen ;
79
78
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .AllToSulongNodeGen ;
80
79
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .AsPythonObjectNodeGen ;
81
80
import com .oracle .graal .python .builtins .objects .cext .capi .CExtNodesFactory .BinaryFirstToSulongNodeGen ;
@@ -1405,6 +1404,10 @@ static Object doForeign(@SuppressWarnings("unused") CExtContext nativeContext, O
1405
1404
}
1406
1405
return asPythonObjectNode .execute (resolveNativeReferenceNode .execute (resolveHandleNode .execute (value ), false ));
1407
1406
}
1407
+
1408
+ public static ToJavaNode create () {
1409
+ return ToJavaNodeGen .create ();
1410
+ }
1408
1411
}
1409
1412
1410
1413
/**
@@ -1739,7 +1742,7 @@ Object add(Object pointer, long offset,
1739
1742
1740
1743
// -----------------------------------------------------------------------------------------------------------------
1741
1744
@ GenerateUncached
1742
- public abstract static class AllToJavaNode extends PNodeWithContext {
1745
+ public abstract static class AllToPythonNode extends PNodeWithContext {
1743
1746
1744
1747
final Object [] execute (Object [] args ) {
1745
1748
return execute (args , 0 );
@@ -1788,8 +1791,63 @@ static AsPythonObjectNode[] createNodes(int n) {
1788
1791
return nodes ;
1789
1792
}
1790
1793
1794
+ public static AllToPythonNode create () {
1795
+ return CExtNodesFactory .AllToPythonNodeGen .create ();
1796
+ }
1797
+ }
1798
+
1799
+ @ GenerateUncached
1800
+ public abstract static class AllToJavaNode extends PNodeWithContext {
1801
+
1802
+ final Object [] execute (Object [] args ) {
1803
+ return execute (args , 0 );
1804
+ }
1805
+
1806
+ abstract Object [] execute (Object [] args , int offset );
1807
+
1808
+ @ Specialization (guards = { //
1809
+ "args.length == cachedLength" , //
1810
+ "offset == cachedOffset" , //
1811
+ "effectiveLen(cachedLength, cachedOffset) < 5" }, //
1812
+ limit = "5" )
1813
+ @ ExplodeLoop
1814
+ static Object [] cached (Object [] args , @ SuppressWarnings ("unused" ) int offset ,
1815
+ @ Cached ("args.length" ) int cachedLength ,
1816
+ @ Cached ("offset" ) int cachedOffset ,
1817
+ @ Cached ("createNodes(args.length)" ) ToJavaNode [] toJavaNodes ) {
1818
+ int n = cachedLength - cachedOffset ;
1819
+ Object [] output = new Object [n ];
1820
+ for (int i = 0 ; i < n ; i ++) {
1821
+ output [i ] = toJavaNodes [i ].execute (args [i + cachedOffset ]);
1822
+ }
1823
+ return output ;
1824
+ }
1825
+
1826
+ @ Specialization (replaces = "cached" )
1827
+ static Object [] uncached (Object [] args , int offset ,
1828
+ @ Exclusive @ Cached ToJavaNode toJavaNode ) {
1829
+ int len = args .length - offset ;
1830
+ Object [] output = new Object [len ];
1831
+ for (int i = 0 ; i < len ; i ++) {
1832
+ output [i ] = toJavaNode .execute (args [i + offset ]);
1833
+ }
1834
+ return output ;
1835
+ }
1836
+
1837
+ static int effectiveLen (int len , int offset ) {
1838
+ return len - offset ;
1839
+ }
1840
+
1841
+ static ToJavaNode [] createNodes (int n ) {
1842
+ ToJavaNode [] nodes = new ToJavaNode [n ];
1843
+ for (int i = 0 ; i < n ; i ++) {
1844
+ nodes [i ] = ToJavaNode .create ();
1845
+ }
1846
+ return nodes ;
1847
+ }
1848
+
1791
1849
public static AllToJavaNode create () {
1792
- return AllToJavaNodeGen .create ();
1850
+ return CExtNodesFactory . AllToJavaNodeGen .create ();
1793
1851
}
1794
1852
}
1795
1853
@@ -1887,24 +1945,24 @@ Object upcall1(VirtualFrame frame, Object[] args,
1887
1945
@ Specialization (guards = "args.length == 3" )
1888
1946
Object upcall2 (VirtualFrame frame , Object [] args ,
1889
1947
@ Cached CallBinaryMethodNode callNode ,
1890
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ) {
1891
- Object [] converted = allToJavaNode .execute (args , 1 );
1948
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ) {
1949
+ Object [] converted = allToPythonNode .execute (args , 1 );
1892
1950
return callNode .executeObject (frame , args [0 ], converted [0 ], converted [1 ]);
1893
1951
}
1894
1952
1895
1953
@ Specialization (guards = "args.length == 4" )
1896
1954
Object upcall3 (VirtualFrame frame , Object [] args ,
1897
1955
@ Cached CallTernaryMethodNode callNode ,
1898
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ) {
1899
- Object [] converted = allToJavaNode .execute (args , 1 );
1956
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ) {
1957
+ Object [] converted = allToPythonNode .execute (args , 1 );
1900
1958
return callNode .execute (frame , args [0 ], converted [0 ], converted [1 ], converted [2 ]);
1901
1959
}
1902
1960
1903
1961
@ Specialization (replaces = {"upcall0" , "upcall1" , "upcall2" , "upcall3" })
1904
1962
Object upcall (VirtualFrame frame , Object [] args ,
1905
1963
@ Cached CallNode callNode ,
1906
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ) {
1907
- Object [] converted = allToJavaNode .execute (args , 1 );
1964
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ) {
1965
+ Object [] converted = allToPythonNode .execute (args , 1 );
1908
1966
return callNode .execute (frame , args [0 ], converted , new PKeyword [0 ]);
1909
1967
}
1910
1968
@@ -2115,9 +2173,9 @@ Object upcall1(VirtualFrame frame, Object cextModule, Object[] args,
2115
2173
@ Specialization (guards = "args.length == 3" )
2116
2174
Object upcall2 (VirtualFrame frame , Object cextModule , Object [] args ,
2117
2175
@ Cached CallBinaryMethodNode callNode ,
2118
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2176
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2119
2177
@ Shared ("getAttrNode" ) @ Cached ReadAttributeFromObjectNode getAttrNode ) {
2120
- Object [] converted = allToJavaNode .execute (args , 1 );
2178
+ Object [] converted = allToPythonNode .execute (args , 1 );
2121
2179
assert args [0 ] instanceof String ;
2122
2180
Object callable = getAttrNode .execute (cextModule , args [0 ]);
2123
2181
return callNode .executeObject (frame , callable , converted [0 ], converted [1 ]);
@@ -2126,9 +2184,9 @@ Object upcall2(VirtualFrame frame, Object cextModule, Object[] args,
2126
2184
@ Specialization (guards = "args.length == 4" )
2127
2185
Object upcall3 (VirtualFrame frame , Object cextModule , Object [] args ,
2128
2186
@ Cached CallTernaryMethodNode callNode ,
2129
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2187
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2130
2188
@ Shared ("getAttrNode" ) @ Cached ReadAttributeFromObjectNode getAttrNode ) {
2131
- Object [] converted = allToJavaNode .execute (args , 1 );
2189
+ Object [] converted = allToPythonNode .execute (args , 1 );
2132
2190
assert args [0 ] instanceof String ;
2133
2191
Object callable = getAttrNode .execute (cextModule , args [0 ]);
2134
2192
return callNode .execute (frame , callable , converted [0 ], converted [1 ], converted [2 ]);
@@ -2137,9 +2195,9 @@ Object upcall3(VirtualFrame frame, Object cextModule, Object[] args,
2137
2195
@ Specialization (replaces = {"upcall0" , "upcall1" , "upcall2" , "upcall3" })
2138
2196
Object upcall (VirtualFrame frame , Object cextModule , Object [] args ,
2139
2197
@ Cached CallNode callNode ,
2140
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2198
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2141
2199
@ Shared ("getAttrNode" ) @ Cached ReadAttributeFromObjectNode getAttrNode ) {
2142
- Object [] converted = allToJavaNode .execute (args , 1 );
2200
+ Object [] converted = allToPythonNode .execute (args , 1 );
2143
2201
assert args [0 ] instanceof String ;
2144
2202
Object callable = getAttrNode .execute (cextModule , args [0 ]);
2145
2203
return callNode .execute (frame , callable , converted , PKeyword .EMPTY_KEYWORDS );
@@ -2191,9 +2249,9 @@ Object upcall1(VirtualFrame frame, Object[] args,
2191
2249
Object upcall2 (VirtualFrame frame , Object [] args ,
2192
2250
@ Cached CallBinaryMethodNode callNode ,
2193
2251
@ Cached CExtNodes .AsPythonObjectNode receiverToJavaNode ,
2194
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2252
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2195
2253
@ Shared ("getAttrNode" ) @ Cached GetAttrNode getAttrNode ) {
2196
- Object [] converted = allToJavaNode .execute (args , 2 );
2254
+ Object [] converted = allToPythonNode .execute (args , 2 );
2197
2255
Object receiver = receiverToJavaNode .execute (args [0 ]);
2198
2256
assert PGuards .isString (args [1 ]);
2199
2257
Object callable = getAttrNode .execute (frame , receiver , args [1 ], PNone .NO_VALUE );
@@ -2204,9 +2262,9 @@ Object upcall2(VirtualFrame frame, Object[] args,
2204
2262
Object upcall3 (VirtualFrame frame , Object [] args ,
2205
2263
@ Cached CallTernaryMethodNode callNode ,
2206
2264
@ Cached CExtNodes .AsPythonObjectNode receiverToJavaNode ,
2207
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2265
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2208
2266
@ Shared ("getAttrNode" ) @ Cached GetAttrNode getAttrNode ) {
2209
- Object [] converted = allToJavaNode .execute (args , 2 );
2267
+ Object [] converted = allToPythonNode .execute (args , 2 );
2210
2268
Object receiver = receiverToJavaNode .execute (args [0 ]);
2211
2269
assert PGuards .isString (args [1 ]);
2212
2270
Object callable = getAttrNode .execute (frame , receiver , args [1 ], PNone .NO_VALUE );
@@ -2217,11 +2275,11 @@ Object upcall3(VirtualFrame frame, Object[] args,
2217
2275
Object upcall (VirtualFrame frame , Object [] args ,
2218
2276
@ Cached CallNode callNode ,
2219
2277
@ Cached CExtNodes .AsPythonObjectNode receiverToJavaNode ,
2220
- @ Shared ("allToJavaNode" ) @ Cached AllToJavaNode allToJavaNode ,
2278
+ @ Shared ("allToJavaNode" ) @ Cached AllToPythonNode allToPythonNode ,
2221
2279
@ Shared ("getAttrNode" ) @ Cached GetAttrNode getAttrNode ) {
2222
2280
// we needs at least a receiver and a member name
2223
2281
assert args .length >= 2 ;
2224
- Object [] converted = allToJavaNode .execute (args , 2 );
2282
+ Object [] converted = allToPythonNode .execute (args , 2 );
2225
2283
Object receiver = receiverToJavaNode .execute (args [0 ]);
2226
2284
assert PGuards .isString (args [1 ]);
2227
2285
Object callable = getAttrNode .execute (frame , receiver , args [1 ], PNone .NO_VALUE );
0 commit comments