81
81
import com .oracle .graal .python .nodes .function .PythonBuiltinBaseNode ;
82
82
import com .oracle .graal .python .nodes .function .PythonBuiltinNode ;
83
83
import com .oracle .graal .python .nodes .function .builtins .PythonBinaryBuiltinNode ;
84
+ import com .oracle .graal .python .nodes .truffle .PythonArithmeticTypes ;
84
85
import com .oracle .graal .python .runtime .PythonCore ;
85
86
import com .oracle .graal .python .runtime .exception .PException ;
86
87
import com .oracle .graal .python .runtime .exception .PythonErrorType ;
94
95
import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
95
96
import com .oracle .truffle .api .dsl .NodeFactory ;
96
97
import com .oracle .truffle .api .dsl .Specialization ;
98
+ import com .oracle .truffle .api .dsl .TypeSystemReference ;
97
99
import com .oracle .truffle .api .profiles .ValueProfile ;
98
100
99
101
@ CoreFunctions (defineModule = "posix" )
@@ -373,6 +375,7 @@ Object setInheritable(int fd, @SuppressWarnings("unused") Object inheritable) {
373
375
374
376
@ Builtin (name = "stat" , minNumOfArguments = 1 , maxNumOfArguments = 2 )
375
377
@ GenerateNodeFactory
378
+ @ TypeSystemReference (PythonArithmeticTypes .class )
376
379
public abstract static class StatNode extends PythonBinaryBuiltinNode {
377
380
private static final int S_IFIFO = 0010000 ;
378
381
private static final int S_IFCHR = 0020000 ;
@@ -507,6 +510,7 @@ protected static StatNode create() {
507
510
508
511
@ Builtin (name = "listdir" , fixedNumOfArguments = 1 )
509
512
@ GenerateNodeFactory
513
+ @ TypeSystemReference (PythonArithmeticTypes .class )
510
514
public abstract static class ListdirNode extends PythonBuiltinNode {
511
515
@ Specialization
512
516
@ TruffleBoundary
@@ -533,16 +537,24 @@ Object listdir(String path) {
533
537
534
538
@ Builtin (name = "dup" , fixedNumOfArguments = 1 )
535
539
@ GenerateNodeFactory
540
+ @ TypeSystemReference (PythonArithmeticTypes .class )
536
541
abstract static class DupNode extends PythonFileNode {
537
542
@ Specialization
538
543
@ TruffleBoundary
539
544
int dup (int fd ) {
540
545
return dupFile (fd );
541
546
}
547
+
548
+ @ Specialization
549
+ @ TruffleBoundary
550
+ int dup (PInt fd ) {
551
+ return dupFile (fd .intValue ());
552
+ }
542
553
}
543
554
544
555
@ Builtin (name = "open" , minNumOfArguments = 2 , maxNumOfArguments = 4 , keywordArguments = {"mode" , "dir_fd" })
545
556
@ GenerateNodeFactory
557
+ @ TypeSystemReference (PythonArithmeticTypes .class )
546
558
public abstract static class OpenNode extends PythonFileNode {
547
559
@ Specialization (guards = {"isNoValue(mode)" , "isNoValue(dir_fd)" })
548
560
Object open (String pathname , int flags , @ SuppressWarnings ("unused" ) PNone mode , PNone dir_fd ) {
@@ -601,6 +613,7 @@ Object open(String pathname, int flags, int fileMode, @SuppressWarnings("unused"
601
613
602
614
@ Builtin (name = "lseek" , fixedNumOfArguments = 3 )
603
615
@ GenerateNodeFactory
616
+ @ TypeSystemReference (PythonArithmeticTypes .class )
604
617
public abstract static class LseekNode extends PythonFileNode {
605
618
@ Specialization
606
619
@ TruffleBoundary
@@ -647,6 +660,7 @@ Object close(int fd) {
647
660
648
661
@ Builtin (name = "unlink" , fixedNumOfArguments = 1 )
649
662
@ GenerateNodeFactory
663
+ @ TypeSystemReference (PythonArithmeticTypes .class )
650
664
public abstract static class UnlinkNode extends PythonFileNode {
651
665
@ Specialization
652
666
@ TruffleBoundary
@@ -672,6 +686,7 @@ public abstract static class RmdirNode extends UnlinkNode {
672
686
673
687
@ Builtin (name = "mkdir" , fixedNumOfArguments = 1 , keywordArguments = {"mode" , "dir_fd" })
674
688
@ GenerateNodeFactory
689
+ @ TypeSystemReference (PythonArithmeticTypes .class )
675
690
public abstract static class MkdirNode extends PythonFileNode {
676
691
@ Specialization
677
692
Object mkdir (String path , @ SuppressWarnings ("unused" ) PNone mode , PNone dirFd ) {
@@ -692,6 +707,7 @@ Object mkdir(String path, @SuppressWarnings("unused") int mode, @SuppressWarning
692
707
693
708
@ Builtin (name = "write" , fixedNumOfArguments = 2 )
694
709
@ GenerateNodeFactory
710
+ @ TypeSystemReference (PythonArithmeticTypes .class )
695
711
public abstract static class WriteNode extends PythonFileNode {
696
712
697
713
public abstract Object executeWith (Object fd , Object data );
@@ -736,16 +752,6 @@ Object writeStd(int fd, String data) {
736
752
return writeStd (fd , data .getBytes ());
737
753
}
738
754
739
- @ Specialization (guards = "fd == 0 || fd > 2" )
740
- Object write (int fd , PString data ) {
741
- return write (fd , data .getValue ());
742
- }
743
-
744
- @ Specialization (guards = {"fd <= 2" , "fd > 0" })
745
- Object writeStd (int fd , PString data ) {
746
- return writeStd (fd , data .getValue ());
747
- }
748
-
749
755
@ Specialization (guards = "fd == 0 || fd > 2" )
750
756
@ TruffleBoundary
751
757
Object write (int fd , PBytes data ) {
@@ -783,6 +789,7 @@ protected WriteNode create() {
783
789
784
790
@ Builtin (name = "read" , fixedNumOfArguments = 2 )
785
791
@ GenerateNodeFactory
792
+ @ TypeSystemReference (PythonArithmeticTypes .class )
786
793
public abstract static class ReadNode extends PythonFileNode {
787
794
@ Specialization
788
795
@ TruffleBoundary
@@ -804,6 +811,7 @@ Object read(int fd, long requestedSize) {
804
811
805
812
@ Builtin (name = "isatty" , fixedNumOfArguments = 1 )
806
813
@ GenerateNodeFactory
814
+ @ TypeSystemReference (PythonArithmeticTypes .class )
807
815
public abstract static class IsATTYNode extends PythonBuiltinNode {
808
816
@ Specialization
809
817
boolean isATTY (int fd ) {
@@ -821,6 +829,7 @@ boolean isATTY(int fd) {
821
829
822
830
@ Builtin (name = "_exit" , fixedNumOfArguments = 1 )
823
831
@ GenerateNodeFactory
832
+ @ TypeSystemReference (PythonArithmeticTypes .class )
824
833
public abstract static class ExitNode extends PythonBuiltinNode {
825
834
@ TruffleBoundary
826
835
@ Specialization
@@ -831,6 +840,7 @@ Object exit(int status) {
831
840
832
841
@ Builtin (name = "chmod" , minNumOfArguments = 2 , keywordArguments = {"dir_fd" , "follow_symlinks" })
833
842
@ GenerateNodeFactory
843
+ @ TypeSystemReference (PythonArithmeticTypes .class )
834
844
abstract static class ChmodNode extends PythonBuiltinNode {
835
845
@ Specialization
836
846
@ TruffleBoundary
@@ -856,6 +866,7 @@ Object chmod(Object path, Object mode, Object dir_fd, Object follow_symlinks) {
856
866
857
867
@ Builtin (name = "utime" , minNumOfArguments = 1 , keywordArguments = {"times" , "ns" , "dir_fd" , "follow_symlinks" })
858
868
@ GenerateNodeFactory
869
+ @ TypeSystemReference (PythonArithmeticTypes .class )
859
870
abstract static class UtimeNode extends PythonBuiltinNode {
860
871
@ SuppressWarnings ("unused" )
861
872
@ Specialization
@@ -959,6 +970,7 @@ private void setAtime(String path, long mtime) {
959
970
// FIXME: this is not nearly ready, just good enough for now
960
971
@ Builtin (name = "system" , fixedNumOfArguments = 1 )
961
972
@ GenerateNodeFactory
973
+ @ TypeSystemReference (PythonArithmeticTypes .class )
962
974
abstract static class SystemNode extends PythonBuiltinNode {
963
975
static final String [] shell = System .getProperty ("os.name" ).toLowerCase ().startsWith ("windows" ) ? new String []{"cmd.exe" , "/c" }
964
976
: new String []{(System .getenv ().getOrDefault ("SHELL" , "sh" )), "-c" };
@@ -1106,6 +1118,7 @@ public abstract static class ReplaceNode extends RenameNode {
1106
1118
1107
1119
@ Builtin (name = "urandom" , fixedNumOfArguments = 1 )
1108
1120
@ GenerateNodeFactory
1121
+ @ TypeSystemReference (PythonArithmeticTypes .class )
1109
1122
abstract static class URandomNode extends PythonBuiltinNode {
1110
1123
@ Specialization
1111
1124
@ TruffleBoundary
0 commit comments