Skip to content

Commit 969d379

Browse files
committed
handle more data types in PosixModuleBuiltins
1 parent 2c4b507 commit 969d379

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8282
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
8383
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
84+
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
8485
import com.oracle.graal.python.runtime.PythonCore;
8586
import com.oracle.graal.python.runtime.exception.PException;
8687
import com.oracle.graal.python.runtime.exception.PythonErrorType;
@@ -94,6 +95,7 @@
9495
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
9596
import com.oracle.truffle.api.dsl.NodeFactory;
9697
import com.oracle.truffle.api.dsl.Specialization;
98+
import com.oracle.truffle.api.dsl.TypeSystemReference;
9799
import com.oracle.truffle.api.profiles.ValueProfile;
98100

99101
@CoreFunctions(defineModule = "posix")
@@ -373,6 +375,7 @@ Object setInheritable(int fd, @SuppressWarnings("unused") Object inheritable) {
373375

374376
@Builtin(name = "stat", minNumOfArguments = 1, maxNumOfArguments = 2)
375377
@GenerateNodeFactory
378+
@TypeSystemReference(PythonArithmeticTypes.class)
376379
public abstract static class StatNode extends PythonBinaryBuiltinNode {
377380
private static final int S_IFIFO = 0010000;
378381
private static final int S_IFCHR = 0020000;
@@ -507,6 +510,7 @@ protected static StatNode create() {
507510

508511
@Builtin(name = "listdir", fixedNumOfArguments = 1)
509512
@GenerateNodeFactory
513+
@TypeSystemReference(PythonArithmeticTypes.class)
510514
public abstract static class ListdirNode extends PythonBuiltinNode {
511515
@Specialization
512516
@TruffleBoundary
@@ -533,16 +537,24 @@ Object listdir(String path) {
533537

534538
@Builtin(name = "dup", fixedNumOfArguments = 1)
535539
@GenerateNodeFactory
540+
@TypeSystemReference(PythonArithmeticTypes.class)
536541
abstract static class DupNode extends PythonFileNode {
537542
@Specialization
538543
@TruffleBoundary
539544
int dup(int fd) {
540545
return dupFile(fd);
541546
}
547+
548+
@Specialization
549+
@TruffleBoundary
550+
int dup(PInt fd) {
551+
return dupFile(fd.intValue());
552+
}
542553
}
543554

544555
@Builtin(name = "open", minNumOfArguments = 2, maxNumOfArguments = 4, keywordArguments = {"mode", "dir_fd"})
545556
@GenerateNodeFactory
557+
@TypeSystemReference(PythonArithmeticTypes.class)
546558
public abstract static class OpenNode extends PythonFileNode {
547559
@Specialization(guards = {"isNoValue(mode)", "isNoValue(dir_fd)"})
548560
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"
601613

602614
@Builtin(name = "lseek", fixedNumOfArguments = 3)
603615
@GenerateNodeFactory
616+
@TypeSystemReference(PythonArithmeticTypes.class)
604617
public abstract static class LseekNode extends PythonFileNode {
605618
@Specialization
606619
@TruffleBoundary
@@ -647,6 +660,7 @@ Object close(int fd) {
647660

648661
@Builtin(name = "unlink", fixedNumOfArguments = 1)
649662
@GenerateNodeFactory
663+
@TypeSystemReference(PythonArithmeticTypes.class)
650664
public abstract static class UnlinkNode extends PythonFileNode {
651665
@Specialization
652666
@TruffleBoundary
@@ -672,6 +686,7 @@ public abstract static class RmdirNode extends UnlinkNode {
672686

673687
@Builtin(name = "mkdir", fixedNumOfArguments = 1, keywordArguments = {"mode", "dir_fd"})
674688
@GenerateNodeFactory
689+
@TypeSystemReference(PythonArithmeticTypes.class)
675690
public abstract static class MkdirNode extends PythonFileNode {
676691
@Specialization
677692
Object mkdir(String path, @SuppressWarnings("unused") PNone mode, PNone dirFd) {
@@ -692,6 +707,7 @@ Object mkdir(String path, @SuppressWarnings("unused") int mode, @SuppressWarning
692707

693708
@Builtin(name = "write", fixedNumOfArguments = 2)
694709
@GenerateNodeFactory
710+
@TypeSystemReference(PythonArithmeticTypes.class)
695711
public abstract static class WriteNode extends PythonFileNode {
696712

697713
public abstract Object executeWith(Object fd, Object data);
@@ -736,16 +752,6 @@ Object writeStd(int fd, String data) {
736752
return writeStd(fd, data.getBytes());
737753
}
738754

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-
749755
@Specialization(guards = "fd == 0 || fd > 2")
750756
@TruffleBoundary
751757
Object write(int fd, PBytes data) {
@@ -783,6 +789,7 @@ protected WriteNode create() {
783789

784790
@Builtin(name = "read", fixedNumOfArguments = 2)
785791
@GenerateNodeFactory
792+
@TypeSystemReference(PythonArithmeticTypes.class)
786793
public abstract static class ReadNode extends PythonFileNode {
787794
@Specialization
788795
@TruffleBoundary
@@ -804,6 +811,7 @@ Object read(int fd, long requestedSize) {
804811

805812
@Builtin(name = "isatty", fixedNumOfArguments = 1)
806813
@GenerateNodeFactory
814+
@TypeSystemReference(PythonArithmeticTypes.class)
807815
public abstract static class IsATTYNode extends PythonBuiltinNode {
808816
@Specialization
809817
boolean isATTY(int fd) {
@@ -821,6 +829,7 @@ boolean isATTY(int fd) {
821829

822830
@Builtin(name = "_exit", fixedNumOfArguments = 1)
823831
@GenerateNodeFactory
832+
@TypeSystemReference(PythonArithmeticTypes.class)
824833
public abstract static class ExitNode extends PythonBuiltinNode {
825834
@TruffleBoundary
826835
@Specialization
@@ -831,6 +840,7 @@ Object exit(int status) {
831840

832841
@Builtin(name = "chmod", minNumOfArguments = 2, keywordArguments = {"dir_fd", "follow_symlinks"})
833842
@GenerateNodeFactory
843+
@TypeSystemReference(PythonArithmeticTypes.class)
834844
abstract static class ChmodNode extends PythonBuiltinNode {
835845
@Specialization
836846
@TruffleBoundary
@@ -856,6 +866,7 @@ Object chmod(Object path, Object mode, Object dir_fd, Object follow_symlinks) {
856866

857867
@Builtin(name = "utime", minNumOfArguments = 1, keywordArguments = {"times", "ns", "dir_fd", "follow_symlinks"})
858868
@GenerateNodeFactory
869+
@TypeSystemReference(PythonArithmeticTypes.class)
859870
abstract static class UtimeNode extends PythonBuiltinNode {
860871
@SuppressWarnings("unused")
861872
@Specialization
@@ -959,6 +970,7 @@ private void setAtime(String path, long mtime) {
959970
// FIXME: this is not nearly ready, just good enough for now
960971
@Builtin(name = "system", fixedNumOfArguments = 1)
961972
@GenerateNodeFactory
973+
@TypeSystemReference(PythonArithmeticTypes.class)
962974
abstract static class SystemNode extends PythonBuiltinNode {
963975
static final String[] shell = System.getProperty("os.name").toLowerCase().startsWith("windows") ? new String[]{"cmd.exe", "/c"}
964976
: new String[]{(System.getenv().getOrDefault("SHELL", "sh")), "-c"};
@@ -1106,6 +1118,7 @@ public abstract static class ReplaceNode extends RenameNode {
11061118

11071119
@Builtin(name = "urandom", fixedNumOfArguments = 1)
11081120
@GenerateNodeFactory
1121+
@TypeSystemReference(PythonArithmeticTypes.class)
11091122
abstract static class URandomNode extends PythonBuiltinNode {
11101123
@Specialization
11111124
@TruffleBoundary

0 commit comments

Comments
 (0)