48
48
import java .util .ArrayList ;
49
49
import java .util .Arrays ;
50
50
51
- import com .oracle .graal .python .PythonLanguage ;
52
51
import com .oracle .graal .python .annotations .ClinicConverterFactory ;
53
52
import com .oracle .graal .python .annotations .ClinicConverterFactory .ArgumentIndex ;
54
53
import com .oracle .graal .python .builtins .PythonBuiltinClassType ;
70
69
import com .oracle .graal .python .nodes .ErrorMessages ;
71
70
import com .oracle .graal .python .nodes .PGuards ;
72
71
import com .oracle .graal .python .nodes .PNodeWithContext ;
73
- import com .oracle .graal .python .nodes .PRaiseNode ;
72
+ import com .oracle .graal .python .nodes .PNodeWithRaise ;
74
73
import com .oracle .graal .python .nodes .SpecialMethodNames ;
75
74
import com .oracle .graal .python .nodes .control .GetNextNode ;
76
75
import com .oracle .graal .python .nodes .function .builtins .clinic .ArgumentCastNode ;
@@ -109,32 +108,32 @@ public abstract static class CreateBytesNode extends Node {
109
108
public abstract PBytesLike execute (PythonObjectFactory factory , PBytesLike basedOn , Object bytes );
110
109
111
110
@ Specialization
112
- PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , byte [] bytes ) {
111
+ static PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , byte [] bytes ) {
113
112
return factory .createBytes (bytes );
114
113
}
115
114
116
115
@ Specialization
117
- PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , byte [] bytes ) {
116
+ static PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , byte [] bytes ) {
118
117
return factory .createByteArray (bytes );
119
118
}
120
119
121
120
@ Specialization
122
- PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , SequenceStorage bytes ) {
121
+ static PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , SequenceStorage bytes ) {
123
122
return factory .createBytes (bytes );
124
123
}
125
124
126
125
@ Specialization
127
- PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , SequenceStorage bytes ) {
126
+ static PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , SequenceStorage bytes ) {
128
127
return factory .createByteArray (bytes );
129
128
}
130
129
131
130
@ Specialization
132
- PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , PBytesLike bytes ) {
131
+ static PBytesLike bytes (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PBytes basedOn , PBytesLike bytes ) {
133
132
return factory .createBytes (bytes .getSequenceStorage ());
134
133
}
135
134
136
135
@ Specialization
137
- PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , PBytesLike bytes ) {
136
+ static PBytesLike bytearray (PythonObjectFactory factory , @ SuppressWarnings ("unused" ) PByteArray basedOn , PBytesLike bytes ) {
138
137
return factory .createByteArray (bytes .getSequenceStorage ());
139
138
}
140
139
@@ -195,11 +194,9 @@ public static BytesJoinNode create() {
195
194
}
196
195
197
196
@ ImportStatic ({PGuards .class , SpecialMethodNames .class })
198
- public abstract static class ToBytesNode extends PNodeWithContext {
197
+ public abstract static class ToBytesNode extends PNodeWithRaise {
199
198
private static final String DEFAULT_FORMAT = "expected a bytes-like object, %p found" ;
200
199
201
- @ Child private PRaiseNode raise = PRaiseNode .create ();
202
-
203
200
private final PythonBuiltinClassType errorType ;
204
201
private final String errorMessageFormat ;
205
202
@@ -234,7 +231,7 @@ static byte[] doBuffer(Object buffer,
234
231
235
232
@ Fallback
236
233
byte [] doError (Object obj ) {
237
- throw raise . raise (errorType , errorMessageFormat , obj );
234
+ throw raise (errorType , errorMessageFormat , obj );
238
235
}
239
236
240
237
public static ToBytesNode create () {
@@ -246,8 +243,7 @@ public static ToBytesNode create(PythonBuiltinClassType errorType, String errorM
246
243
}
247
244
}
248
245
249
- public abstract static class FindNode extends PNodeWithContext {
250
- @ Child private PRaiseNode raise = PRaiseNode .create ();
246
+ public abstract static class FindNode extends PNodeWithRaise {
251
247
252
248
public abstract int execute (Object self , int len1 , Object sub , int start , int end );
253
249
@@ -369,7 +365,7 @@ protected int findElement(byte[] haystack, byte sub, int start, int end) {
369
365
@ SuppressWarnings ("unused" )
370
366
@ Fallback
371
367
int doError (Object bytes , int len1 , Object sub , int start , int end ) {
372
- throw raise . raise (TypeError , ErrorMessages .EXPECTED_S_P_FOUND , "a bytes-like object" , sub );
368
+ throw raise (TypeError , ErrorMessages .EXPECTED_S_P_FOUND , "a bytes-like object" , sub );
373
369
}
374
370
375
371
public static FindNode create () {
@@ -412,9 +408,9 @@ public static RFindNode create() {
412
408
413
409
public static class FromSequenceStorageNode extends Node {
414
410
415
- @ Node . Child private SequenceStorageNodes .GetItemNode getItemNode ;
416
- @ Node . Child private CastToByteNode castToByteNode ;
417
- @ Node . Child private SequenceStorageNodes .LenNode lenNode ;
411
+ @ Child private SequenceStorageNodes .GetItemNode getItemNode ;
412
+ @ Child private CastToByteNode castToByteNode ;
413
+ @ Child private SequenceStorageNodes .LenNode lenNode ;
418
414
419
415
public byte [] execute (VirtualFrame frame , SequenceStorage storage ) {
420
416
int len = getLenNode ().execute (storage );
@@ -581,70 +577,68 @@ public static ExpectStringNode create(@ArgumentIndex int argNum, String classNam
581
577
582
578
@ TypeSystemReference (PythonArithmeticTypes .class )
583
579
@ ImportStatic (PGuards .class )
584
- public abstract static class BytesInitNode extends Node {
580
+ public abstract static class BytesInitNode extends PNodeWithRaise {
585
581
586
582
public abstract byte [] execute (VirtualFrame frame , Object source , Object encoding , Object errors );
587
583
588
584
@ Specialization
589
- byte [] none (@ SuppressWarnings ("unused" ) PNone source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ) {
585
+ static byte [] none (@ SuppressWarnings ("unused" ) PNone source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ) {
590
586
return PythonUtils .EMPTY_BYTE_ARRAY ;
591
587
}
592
588
593
589
@ Specialization (guards = "isByteStorage(source)" )
594
- byte [] byteslike (PBytesLike source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ) {
590
+ static byte [] byteslike (PBytesLike source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ) {
595
591
return (byte []) ((ByteSequenceStorage ) source .getSequenceStorage ()).getCopyOfInternalArrayObject ();
596
592
}
597
593
598
594
@ Specialization (guards = "lib.canBeIndex(source)" , limit = "3" )
599
- byte [] size (VirtualFrame frame , Object source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ,
595
+ static byte [] fromIndex (VirtualFrame frame , Object source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ,
600
596
@ CachedLibrary ("source" ) PythonObjectLibrary lib ) {
601
597
int cap = lib .asSizeWithState (source , PArguments .getThreadState (frame ));
602
598
return BytesUtils .fromSize (getCore (), cap );
603
599
}
604
600
605
- @ Specialization (guards = {"!isString(source)" , "!isNoValue(source)" , "!lib.canBeIndex(source)" }, limit = "3" )
606
- public byte [] iterable (VirtualFrame frame , Object source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ,
601
+ @ Specialization (guards = {"!isString(source)" , "!isNoValue(source)" , "!lib.canBeIndex(source)" , "!lib.isBuffer(source)" }, limit = "3" )
602
+ static byte [] fromIterable (VirtualFrame frame , Object source , @ SuppressWarnings ("unused" ) PNone encoding , @ SuppressWarnings ("unused" ) PNone errors ,
607
603
@ Cached IteratorNodes .GetLength lenNode ,
608
604
@ Cached ("createCast()" ) IterableToByteNode toByteNode ,
609
605
@ SuppressWarnings ("unused" ) @ CachedLibrary ("source" ) PythonObjectLibrary lib ) {
610
606
return toByteNode .execute (frame , source , lenNode .execute (frame , source ));
611
607
}
612
608
613
609
@ Specialization
614
- byte [] fromString (String source , String encoding , @ SuppressWarnings ("unused" ) Object errors ,
615
- @ Cached PRaiseNode raise ) {
610
+ byte [] fromString (String source , String encoding , @ SuppressWarnings ("unused" ) Object errors ) {
616
611
String e = errors instanceof String ? (String ) errors : "strict" ;
617
- return BytesBuiltins .stringToByte (source , encoding , e , raise );
612
+ return BytesBuiltins .stringToByte (source , encoding , e , getRaiseNode () );
618
613
}
619
614
620
615
@ Specialization
621
616
@ SuppressWarnings ("unused" )
622
- byte [] fromString (String source , PNone encoding , Object errors ,
623
- @ Cached PRaiseNode raise ) {
624
- throw raise .raise (TypeError , ErrorMessages .STRING_ARG_WO_ENCODING );
617
+ byte [] fromString (String source , PNone encoding , Object errors ) {
618
+ throw raise (TypeError , ErrorMessages .STRING_ARG_WO_ENCODING );
625
619
}
626
620
627
621
@ Fallback
628
622
@ SuppressWarnings ("unused" )
629
623
public byte [] error (Object source , Object encoding , Object errors ) {
630
624
if (PGuards .isNone (encoding )) {
631
- throw PythonLanguage . getCore (). raise (TypeError , ErrorMessages .ENCODING_ARG_WO_STRING );
625
+ throw raise (TypeError , ErrorMessages .ENCODING_ARG_WO_STRING );
632
626
}
633
- throw PythonLanguage . getCore (). raise (TypeError , ErrorMessages .ERRORS_WITHOUT_STR_ARG );
627
+ throw raise (TypeError , ErrorMessages .ERRORS_WITHOUT_STR_ARG );
634
628
}
635
629
636
- protected static BytesNodes .IterableToByteNode createCast () {
637
- return BytesNodes .IterableToByteNode .create (val -> PythonLanguage . getCore (). raise (TypeError , ErrorMessages .ERRORS_WITHOUT_STR_ARG ));
630
+ protected BytesNodes .IterableToByteNode createCast () {
631
+ return BytesNodes .IterableToByteNode .create (val -> raise (TypeError , ErrorMessages .ERRORS_WITHOUT_STR_ARG ));
638
632
}
639
633
}
640
634
641
635
@ GenerateNodeFactory
642
- public abstract static class ByteToHexNode extends PNodeWithContext {
636
+ public abstract static class ByteToHexNode extends PNodeWithRaise {
643
637
644
638
public abstract String execute (byte [] argbuf , int arglen , byte sep , int bytesPerSepGroup );
645
639
646
640
@ Specialization (guards = "bytesPerSepGroup == 0" )
647
- public String zero (byte [] argbuf , int arglen , @ SuppressWarnings ("unused" ) byte sep , @ SuppressWarnings ("unused" ) int bytesPerSepGroup ) {
641
+ public static String zero (byte [] argbuf , int arglen , @ SuppressWarnings ("unused" ) byte sep , @ SuppressWarnings ("unused" ) int bytesPerSepGroup ) {
648
642
649
643
int resultlen = arglen * 2 ;
650
644
byte [] retbuf = new byte [resultlen ];
@@ -661,16 +655,15 @@ public String zero(byte[] argbuf, int arglen, @SuppressWarnings("unused") byte s
661
655
@ Specialization (guards = "bytesPerSepGroup < 0" )
662
656
public String negative (byte [] argbuf , int arglen , byte sep , int bytesPerSepGroup ,
663
657
@ Cached ConditionProfile earlyExit ,
664
- @ Cached ConditionProfile memoryError ,
665
- @ Cached .Shared ("error" ) @ Cached PRaiseNode raiseNode ) {
658
+ @ Cached ConditionProfile memoryError ) {
666
659
if (earlyExit .profile (arglen == 0 )) {
667
660
return "" ;
668
661
}
669
662
int absBytesPerSepGroup = -bytesPerSepGroup ;
670
663
/* How many sep characters we'll be inserting. */
671
664
int resultlen = (arglen - 1 ) / absBytesPerSepGroup ;
672
665
if (memoryError .profile (arglen >= SysModuleBuiltins .MAXSIZE / 2 - resultlen )) {
673
- raiseNode . raise (MemoryError );
666
+ throw raise (MemoryError );
674
667
}
675
668
676
669
resultlen += arglen * 2 ;
@@ -702,16 +695,15 @@ public String negative(byte[] argbuf, int arglen, byte sep, int bytesPerSepGroup
702
695
@ Specialization (guards = "absBytesPerSepGroup > 0" )
703
696
public String positive (byte [] argbuf , int arglen , byte sep , int absBytesPerSepGroup ,
704
697
@ Cached ConditionProfile earlyExit ,
705
- @ Cached ConditionProfile memoryError ,
706
- @ Cached .Shared ("error" ) @ Cached PRaiseNode raiseNode ) {
698
+ @ Cached ConditionProfile memoryError ) {
707
699
if (earlyExit .profile (arglen == 0 )) {
708
700
return "" ;
709
701
}
710
702
/* How many sep characters we'll be inserting. */
711
703
int resultlen = (arglen - 1 ) / absBytesPerSepGroup ;
712
704
713
705
if (memoryError .profile (arglen >= SysModuleBuiltins .MAXSIZE / 2 - resultlen )) {
714
- raiseNode . raise (MemoryError );
706
+ throw raise (MemoryError );
715
707
}
716
708
717
709
resultlen += arglen * 2 ;
@@ -741,10 +733,9 @@ public String positive(byte[] argbuf, int arglen, byte sep, int absBytesPerSepGr
741
733
}
742
734
}
743
735
744
- public abstract static class IterableToByteNode extends PNodeWithContext {
736
+ public abstract static class IterableToByteNode extends PNodeWithRaise {
745
737
746
738
private final Function <Object , Object > typeErrorHandler ;
747
- @ Child private PRaiseNode raise = PRaiseNode .create ();
748
739
749
740
abstract byte [] execute (VirtualFrame frame , Object iterable , int len );
750
741
@@ -753,7 +744,7 @@ protected IterableToByteNode(Function<Object, Object> typeErrorHandler) {
753
744
}
754
745
755
746
@ Specialization (guards = "!lib.canBeIndex(iterable)" )
756
- public byte [] bytearray (VirtualFrame frame , Object iterable , int len ,
747
+ public static byte [] bytearray (VirtualFrame frame , Object iterable , int len ,
757
748
@ Cached GetNextNode getNextNode ,
758
749
@ Cached IsBuiltinClassProfile stopIterationProfile ,
759
750
@ Cached CastToByteNode castToByteNode ,
@@ -787,9 +778,9 @@ public static IterableToByteNode create(Function<Object, Object> typeErrorHandle
787
778
788
779
protected CastToByteNode createCast () {
789
780
return CastToByteNode .create (val -> {
790
- throw raise . raise (TypeError , ErrorMessages .OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER , "bytes" );
781
+ throw raise (TypeError , ErrorMessages .OBJ_CANNOT_BE_INTERPRETED_AS_INTEGER , "bytes" );
791
782
}, val -> {
792
- throw raise . raise (ValueError , ErrorMessages .BYTE_MUST_BE_IN_RANGE );
783
+ throw raise (ValueError , ErrorMessages .BYTE_MUST_BE_IN_RANGE );
793
784
});
794
785
}
795
786
0 commit comments