54
54
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
55
55
import com .oracle .graal .python .builtins .PythonBuiltins ;
56
56
import com .oracle .graal .python .builtins .objects .PNone ;
57
+ import com .oracle .graal .python .builtins .objects .function .PArguments ;
57
58
import com .oracle .graal .python .builtins .objects .ints .PInt ;
58
59
import com .oracle .graal .python .builtins .objects .lzma .PLZMACompressor ;
59
60
import com .oracle .graal .python .builtins .objects .lzma .PLZMADecompressor ;
66
67
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
67
68
import com .oracle .graal .python .nodes .subscript .GetItemNode ;
68
69
import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
69
- import com .oracle .graal .python .nodes .util .CastToIndexNode ;
70
70
import com .oracle .graal .python .runtime .ExecutionContext .IndirectCallContext ;
71
71
import com .oracle .graal .python .runtime .PythonContext ;
72
72
import com .oracle .graal .python .runtime .PythonCore ;
75
75
import com .oracle .truffle .api .CompilerDirectives .CompilationFinal ;
76
76
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
77
77
import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
78
- import com .oracle .truffle .api .dsl .Cached ;
79
78
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
80
79
import com .oracle .truffle .api .dsl .NodeFactory ;
81
80
import com .oracle .truffle .api .dsl .Specialization ;
@@ -173,7 +172,7 @@ public void initialize(PythonCore core) {
173
172
abstract static class LZMANode extends PythonBuiltinNode {
174
173
175
174
@ Child private GetItemNode getItemNode ;
176
- @ Child private CastToIndexNode castToLongNode ;
175
+ @ Child private PythonObjectLibrary castToLongNode ;
177
176
@ Child private BuiltinFunctions .LenNode lenNode ;
178
177
@ CompilationFinal private IsBuiltinClassProfile keyErrorProfile ;
179
178
@@ -281,9 +280,9 @@ private IsBuiltinClassProfile ensureKeyErrorProfile() {
281
280
private int asInt (VirtualFrame frame , Object obj ) {
282
281
if (castToLongNode == null ) {
283
282
CompilerDirectives .transferToInterpreterAndInvalidate ();
284
- castToLongNode = insert (CastToIndexNode . create ( ));
283
+ castToLongNode = insert (PythonObjectLibrary . getFactory (). createDispatched ( 2 ));
285
284
}
286
- return castToLongNode .execute ( frame , obj );
285
+ return castToLongNode .asSizeWithState ( obj , PArguments . getThreadState ( frame ) );
287
286
}
288
287
289
288
private int len (VirtualFrame frame , Object obj ) {
@@ -310,21 +309,18 @@ abstract static class LZMACompressorNode extends LZMANode {
310
309
311
310
@ Specialization
312
311
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 ) {
317
313
318
314
int format = FORMAT_XZ ;
319
315
int check = -1 ;
320
316
int preset = LZMA2Options .PRESET_DEFAULT ;
321
317
322
318
if (!isNoneOrNoValue (formatObj )) {
323
- format = castFormatToIntNode . execute ( frame , formatObj );
319
+ format = lib . asSizeWithState ( formatObj , PArguments . getThreadState ( frame ) );
324
320
}
325
321
326
322
if (!isNoneOrNoValue (checkObj )) {
327
- check = castCheckToIntNode . execute ( frame , checkObj );
323
+ check = lib . asSizeWithState ( checkObj , PArguments . getThreadState ( frame ) );
328
324
}
329
325
330
326
if (format != FORMAT_XZ && check != -1 && check != XZ .CHECK_NONE ) {
@@ -335,7 +331,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
335
331
}
336
332
337
333
if (!isNoneOrNoValue (presetObj )) {
338
- preset = castToIntNode . execute ( frame , presetObj );
334
+ preset = lib . asSizeWithState ( presetObj , PArguments . getThreadState ( frame ) );
339
335
}
340
336
341
337
try {
@@ -351,7 +347,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
351
347
LZMA2Options lzmaOptions = parseLZMAOptions (preset );
352
348
xzOutputStream = createXZOutputStream (check , bos , lzmaOptions );
353
349
} else {
354
- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
350
+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
355
351
xzOutputStream = createXZOutputStream (check , bos , optionsChain );
356
352
}
357
353
return factory ().createLZMACompressor (cls , xzOutputStream , bos );
@@ -362,7 +358,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
362
358
LZMA2Options lzmaOptions = parseLZMAOptions (preset );
363
359
lzmaOutputStream = createLZMAOutputStream (bos , lzmaOptions );
364
360
} else {
365
- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
361
+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
366
362
if (optionsChain .length != 1 && !(optionsChain [0 ] instanceof LZMA2Options )) {
367
363
throw raise (ValueError , "Invalid filter chain for FORMAT_ALONE - must be a single LZMA1 filter" );
368
364
}
@@ -375,7 +371,7 @@ PLZMACompressor doCreate(VirtualFrame frame, LazyPythonClass cls, Object formatO
375
371
LZMA2Options lzmaOptions = parseLZMAOptions (preset );
376
372
lzmaOutputStream = createLZMAOutputStream (bos , lzmaOptions );
377
373
} else {
378
- FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , dataModelLibrary );
374
+ FilterOptions [] optionsChain = parseFilterChainSpec (frame , filters , lib );
379
375
if (optionsChain .length != 1 && !(optionsChain [0 ] instanceof LZMA2Options )) {
380
376
throw raise (ValueError , "Invalid filter chain for FORMAT_ALONE - must be a single LZMA1 filter" );
381
377
}
@@ -423,28 +419,26 @@ private static LZMAOutputStream createLZMAOutputStream(ByteArrayOutputStream bos
423
419
abstract static class LZMADecompressorNode extends LZMANode {
424
420
425
421
@ Child private GetItemNode getItemNode ;
426
- @ Child private CastToIndexNode castToLongNode ;
427
422
@ Child private BuiltinFunctions .LenNode lenNode ;
428
423
429
424
@ CompilationFinal private IsBuiltinClassProfile keyErrorProfile ;
430
425
431
426
@ Specialization
432
427
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 ) {
435
429
436
430
int format = FORMAT_AUTO ;
437
431
int memlimit = Integer .MAX_VALUE ;
438
432
439
433
if (!isNoneOrNoValue (formatObj )) {
440
- format = castFormatToIntNode . execute ( frame , formatObj );
434
+ format = lib . asSizeWithState ( formatObj , PArguments . getThreadState ( frame ) );
441
435
}
442
436
443
437
if (!isNoneOrNoValue (memlimitObj )) {
444
438
if (format == FORMAT_RAW ) {
445
439
throw raise (ValueError , "Cannot specify memory limit with FORMAT_RAW" );
446
440
}
447
- memlimit = castCheckToIntNode . execute ( frame , memlimitObj );
441
+ memlimit = lib . asSizeWithState ( memlimitObj , PArguments . getThreadState ( frame ) );
448
442
}
449
443
450
444
if (format == FORMAT_RAW && isNoneOrNoValue (filters )) {
0 commit comments