5454import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
5555import com .oracle .graal .python .builtins .PythonBuiltins ;
5656import com .oracle .graal .python .builtins .objects .PNone ;
57+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
5758import com .oracle .graal .python .builtins .objects .ints .PInt ;
5859import com .oracle .graal .python .builtins .objects .lzma .PLZMACompressor ;
5960import com .oracle .graal .python .builtins .objects .lzma .PLZMADecompressor ;
6667import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
6768import com .oracle .graal .python .nodes .subscript .GetItemNode ;
6869import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
69- import com .oracle .graal .python .nodes .util .CastToIndexNode ;
7070import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
7171import com .oracle .graal .python .runtime .PythonContext ;
7272import com .oracle .graal .python .runtime .PythonCore ;
7575import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
7676import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
7777import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
78- import com .oracle .truffle .api .dsl .Cached ;
7978import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
8079import com .oracle .truffle .api .dsl .NodeFactory ;
8180import com .oracle .truffle .api .dsl .Specialization ;
@@ -173,7 +172,7 @@ public void initialize(PythonCore core) {
173172 abstract static class LZMANode extends PythonBuiltinNode {
174173
175174 @ Child private GetItemNode getItemNode ;
176- @ Child private CastToIndexNode castToLongNode ;
175+ @ Child private PythonObjectLibrary castToLongNode ;
177176 @ Child private BuiltinFunctions .LenNode lenNode ;
178177 @ CompilationFinal private IsBuiltinClassProfile keyErrorProfile ;
179178
@@ -281,9 +280,9 @@ private IsBuiltinClassProfile ensureKeyErrorProfile() {
281280 private int asInt (VirtualFrame frame , Object obj ) {
282281 if (castToLongNode == null ) {
283282 CompilerDirectives .transferToInterpreterAndInvalidate ();
284- castToLongNode = insert (CastToIndexNode . create ( ));
283+ castToLongNode = insert (PythonObjectLibrary . getFactory (). createDispatched ( 2 ));
285284 }
286- return castToLongNode .execute ( frame , obj );
285+ return castToLongNode .asSizeWithState ( obj , PArguments . getThreadState ( frame ) );
287286 }
288287
289288 private int len (VirtualFrame frame , Object obj ) {
@@ -310,21 +309,18 @@ abstract static class LZMACompressorNode extends LZMANode {
310309
311310 @ Specialization
312311 PLZMACompressor doCreate (VirtualFrame frame , LazyPythonClass cls , Object formatObj , Object checkObj , Object presetObj , Object filters ,
313- @ Cached CastToIndexNode castFormatToIntNode ,
314- @ Cached CastToIndexNode castCheckToIntNode ,
315- @ Cached CastToIndexNode castToIntNode ,
316- @ CachedLibrary (limit = "1" ) PythonObjectLibrary dataModelLibrary ) {
312+ @ CachedLibrary (limit = "4" ) PythonObjectLibrary lib ) {
317313
318314 int format = FORMAT_XZ ;
319315 int check = -1 ;
320316 int preset = LZMA2Options .PRESET_DEFAULT ;
321317
322318 if (!isNoneOrNoValue (formatObj )) {
323- format = castFormatToIntNode . execute ( frame , formatObj );
319+ format = lib . asSizeWithState ( formatObj , PArguments . getThreadState ( frame ) );
324320 }
325321
326322 if (!isNoneOrNoValue (checkObj )) {
327- check = castCheckToIntNode . execute ( frame , checkObj );
323+ check = lib . asSizeWithState ( checkObj , PArguments . getThreadState ( frame ) );
328324 }
329325
330326 if (format != FORMAT_XZ && check != -1 && check != XZ .CHECK_NONE ) {
@@ -335,7 +331,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
335331 }
336332
337333 if (!isNoneOrNoValue (presetObj )) {
338- preset = castToIntNode . execute ( frame , presetObj );
334+ preset = lib . asSizeWithState ( presetObj , PArguments . getThreadState ( frame ) );
339335 }
340336
341337 try {
@@ -351,7 +347,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
351347 LZMA2Options lzmaOptions = parseLZMAOptions (preset );
352348 xzOutputStream = createXZOutputStream (check , bos , lzmaOptions );
353349 } else {
354- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
350+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
355351 xzOutputStream = createXZOutputStream (check , bos , optionsChain );
356352 }
357353 return factory ().createLZMACompressor (cls , xzOutputStream , bos );
@@ -362,7 +358,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
362358 LZMA2Options lzmaOptions = parseLZMAOptions (preset );
363359 lzmaOutputStream = createLZMAOutputStream (bos , lzmaOptions );
364360 } else {
365- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
361+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
366362 if (optionsChain .length != 1 && !(optionsChain [0 ] instanceof LZMA2Options )) {
367363 throw raise (ValueError , "Invalid filter chain for FORMAT_ALONE - must be a single LZMA1 filter" );
368364 }
@@ -375,7 +371,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
375371 LZMA2Options lzmaOptions = parseLZMAOptions (preset );
376372 lzmaOutputStream = createLZMAOutputStream (bos , lzmaOptions );
377373 } else {
378- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
374+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
379375 if (optionsChain .length != 1 && !(optionsChain [0 ] instanceof LZMA2Options )) {
380376 throw raise (ValueError , "Invalid filter chain for FORMAT_ALONE - must be a single LZMA1 filter" );
381377 }
@@ -423,28 +419,26 @@ private static LZMAOutputStream createLZMAOutputStream(ByteArrayOutputStream bos
423419 abstract static class LZMADecompressorNode extends LZMANode {
424420
425421 @ Child private GetItemNode getItemNode ;
426- @ Child private CastToIndexNode castToLongNode ;
427422 @ Child private BuiltinFunctions .LenNode lenNode ;
428423
429424 @ CompilationFinal private IsBuiltinClassProfile keyErrorProfile ;
430425
431426 @ Specialization
432427 PLZMADecompressor doCreate (VirtualFrame frame , LazyPythonClass cls , Object formatObj , Object memlimitObj , Object filters ,
433- @ Cached CastToIndexNode castFormatToIntNode ,
434- @ Cached CastToIndexNode castCheckToIntNode ) {
428+ @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
435429
436430 int format = FORMAT_AUTO ;
437431 int memlimit = Integer .MAX_VALUE ;
438432
439433 if (!isNoneOrNoValue (formatObj )) {
440- format = castFormatToIntNode . execute ( frame , formatObj );
434+ format = lib . asSizeWithState ( formatObj , PArguments . getThreadState ( frame ) );
441435 }
442436
443437 if (!isNoneOrNoValue (memlimitObj )) {
444438 if (format == FORMAT_RAW ) {
445439 throw raise (ValueError , "Cannot specify memory limit with FORMAT_RAW" );
446440 }
447- memlimit = castCheckToIntNode . execute ( frame , memlimitObj );
441+ memlimit = lib . asSizeWithState ( memlimitObj , PArguments . getThreadState ( frame ) );
448442 }
449443
450444 if (format == FORMAT_RAW && isNoneOrNoValue (filters )) {
0 commit comments