|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.objects.socket;
|
42 | 42 |
|
43 |
| -import java.util.ArrayList; |
44 | 43 | import java.util.List;
|
45 | 44 |
|
| 45 | +import com.oracle.graal.python.builtins.Builtin; |
46 | 46 | import com.oracle.graal.python.builtins.CoreFunctions;
|
47 | 47 | import com.oracle.graal.python.builtins.PythonBuiltinClassType;
|
48 | 48 | import com.oracle.graal.python.builtins.PythonBuiltins;
|
| 49 | +import com.oracle.graal.python.builtins.objects.PNone; |
| 50 | +import com.oracle.graal.python.builtins.objects.PNotImplemented; |
49 | 51 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
| 52 | +import com.oracle.graal.python.nodes.function.PythonBuiltinNode; |
| 53 | +import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode; |
| 54 | +import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode; |
| 55 | +import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode; |
| 56 | +import com.oracle.truffle.api.dsl.GenerateNodeFactory; |
50 | 57 | import com.oracle.truffle.api.dsl.NodeFactory;
|
| 58 | +import com.oracle.truffle.api.dsl.Specialization; |
51 | 59 |
|
52 | 60 | @CoreFunctions(extendClasses = PythonBuiltinClassType.PSocket)
|
53 | 61 | public class SocketBuiltins extends PythonBuiltins {
|
54 | 62 |
|
55 | 63 | @Override
|
56 | 64 | protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
|
57 |
| - return new ArrayList<>(); |
| 65 | + return SocketBuiltinsFactory.getFactories(); |
| 66 | + } |
| 67 | + |
| 68 | + // accept() |
| 69 | + @Builtin(name = "accept", fixedNumOfPositionalArgs = 1) |
| 70 | + @GenerateNodeFactory |
| 71 | + abstract static class AcceptNode extends PythonUnaryBuiltinNode { |
| 72 | + @Specialization |
| 73 | + Object accept(PSocket socket) { |
| 74 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + // bind(address) |
| 79 | + @Builtin(name = "bind", fixedNumOfPositionalArgs = 2) |
| 80 | + @GenerateNodeFactory |
| 81 | + abstract static class BindNode extends PythonBinaryBuiltinNode { |
| 82 | + @Specialization |
| 83 | + Object bind(PSocket socket, Object address) { |
| 84 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + // close() |
| 89 | + @Builtin(name = "close", fixedNumOfPositionalArgs = 1) |
| 90 | + @GenerateNodeFactory |
| 91 | + abstract static class CloseNode extends PythonUnaryBuiltinNode { |
| 92 | + @Specialization |
| 93 | + Object close(PSocket socket) { |
| 94 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + // connect(address) |
| 99 | + @Builtin(name = "connect", fixedNumOfPositionalArgs = 2) |
| 100 | + @GenerateNodeFactory |
| 101 | + abstract static class ConnectNode extends PythonBinaryBuiltinNode { |
| 102 | + @Specialization |
| 103 | + Object connect(PSocket socket, Object address) { |
| 104 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + // getpeername() |
| 109 | + @Builtin(name = "getpeername", fixedNumOfPositionalArgs = 1) |
| 110 | + @GenerateNodeFactory |
| 111 | + abstract static class GetPeerNameNode extends PythonUnaryBuiltinNode { |
| 112 | + @Specialization |
| 113 | + Object get(PSocket socket) { |
| 114 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + // getsockname() |
| 119 | + @Builtin(name = "getsockname", fixedNumOfPositionalArgs = 1) |
| 120 | + @GenerateNodeFactory |
| 121 | + abstract static class GetSockNameNode extends PythonUnaryBuiltinNode { |
| 122 | + @Specialization |
| 123 | + Object get(PSocket socket) { |
| 124 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + // getblocking() |
| 129 | + @Builtin(name = "getblocking", fixedNumOfPositionalArgs = 1) |
| 130 | + @GenerateNodeFactory |
| 131 | + abstract static class GetBlockingNode extends PythonUnaryBuiltinNode { |
| 132 | + @Specialization |
| 133 | + boolean get(PSocket socket) { |
| 134 | + return false; |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + // gettimeout |
| 139 | + @Builtin(name = "gettimeout", fixedNumOfPositionalArgs = 1) |
| 140 | + @GenerateNodeFactory |
| 141 | + abstract static class GetTimeoutNode extends PythonUnaryBuiltinNode { |
| 142 | + @Specialization |
| 143 | + Object get(PSocket socket) { |
| 144 | + return PNone.NONE; |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + // listen |
| 149 | + @Builtin(name = "listen", fixedNumOfPositionalArgs = 1) |
| 150 | + @GenerateNodeFactory |
| 151 | + abstract static class ListenNode extends PythonUnaryBuiltinNode { |
| 152 | + @Specialization |
| 153 | + Object listen(PSocket socket) { |
| 154 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + // recv(bufsize[, flags]) |
| 159 | + @Builtin(name = "recv", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3) |
| 160 | + @GenerateNodeFactory |
| 161 | + abstract static class RecvNode extends PythonTernaryBuiltinNode { |
| 162 | + @Specialization |
| 163 | + Object recv(PSocket socket, int bufsize, int flags) { |
| 164 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + // recvfrom(bufsize[, flags]) |
| 169 | + @Builtin(name = "recvfrom", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3) |
| 170 | + @GenerateNodeFactory |
| 171 | + abstract static class RecvFromNode extends PythonTernaryBuiltinNode { |
| 172 | + @Specialization |
| 173 | + Object recvFrom(PSocket socket, int bufsize, int flags) { |
| 174 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + // recvmsg(bufsize[, ancbufsize[, flags]]) |
| 179 | + @Builtin(name = "recvmsg", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 4) |
| 180 | + @GenerateNodeFactory |
| 181 | + abstract static class RecvMsgNode extends PythonBuiltinNode { |
| 182 | + @Specialization |
| 183 | + Object recvFrom(PSocket socket, int bufsize, int ancbufsize, int flags) { |
| 184 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + // send(bytes[, flags]) |
| 189 | + @Builtin(name = "send", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3) |
| 190 | + @GenerateNodeFactory |
| 191 | + abstract static class SendNode extends PythonTernaryBuiltinNode { |
| 192 | + @Specialization |
| 193 | + Object send(PSocket socket, Object bytes, int flags) { |
| 194 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 195 | + } |
| 196 | + } |
| 197 | + |
| 198 | + // sendall(bytes[, flags]) |
| 199 | + @Builtin(name = "sendall", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 3) |
| 200 | + @GenerateNodeFactory |
| 201 | + abstract static class SendAllNode extends PythonTernaryBuiltinNode { |
| 202 | + @Specialization |
| 203 | + Object sendAll(PSocket socket, Object bytes, int flags) { |
| 204 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + // sendto(bytes, address) |
| 209 | + // sendto(bytes, flags, address) |
| 210 | + @Builtin(name = "sendto", minNumOfPositionalArgs = 3, maxNumOfPositionalArgs = 4) |
| 211 | + @GenerateNodeFactory |
| 212 | + abstract static class SendToNode extends PythonBuiltinNode { |
| 213 | + @Specialization |
| 214 | + Object sendTo(PSocket socket, Object bytes, int flags, Object address) { |
| 215 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 216 | + } |
| 217 | + } |
| 218 | + |
| 219 | + // sendmsg(buffers[, ancdata[, flags[, address]]]) |
| 220 | + @Builtin(name = "sendmsg", minNumOfPositionalArgs = 2, maxNumOfPositionalArgs = 5) |
| 221 | + @GenerateNodeFactory |
| 222 | + abstract static class SendMsgNode extends PythonBuiltinNode { |
| 223 | + @Specialization |
| 224 | + Object sendMsg(PSocket socket, Object buffers, Object ancdata, int flags, Object address) { |
| 225 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 226 | + } |
| 227 | + } |
| 228 | + |
| 229 | + // settimeout(value) |
| 230 | + @Builtin(name = "settimeout", fixedNumOfPositionalArgs = 2) |
| 231 | + @GenerateNodeFactory |
| 232 | + abstract static class SetTimeoutNode extends PythonBinaryBuiltinNode { |
| 233 | + @Specialization |
| 234 | + Object family(PSocket socket, double value) { |
| 235 | + return PNone.NONE; |
| 236 | + } |
| 237 | + } |
| 238 | + |
| 239 | + // shutdown(how) |
| 240 | + @Builtin(name = "shutdown", fixedNumOfPositionalArgs = 2) |
| 241 | + @GenerateNodeFactory |
| 242 | + abstract static class shutdownNode extends PythonBinaryBuiltinNode { |
| 243 | + @Specialization |
| 244 | + Object family(PSocket socket, Object how) { |
| 245 | + return PNotImplemented.NOT_IMPLEMENTED; |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + // family |
| 250 | + @Builtin(name = "family", fixedNumOfPositionalArgs = 1, isGetter = true) |
| 251 | + @GenerateNodeFactory |
| 252 | + abstract static class SocketFamilyNode extends PythonUnaryBuiltinNode { |
| 253 | + @Specialization |
| 254 | + int family(PSocket socket) { |
| 255 | + return socket.getFamily(); |
| 256 | + } |
| 257 | + } |
| 258 | + |
| 259 | + // type |
| 260 | + @Builtin(name = "type", fixedNumOfPositionalArgs = 1, isGetter = true) |
| 261 | + @GenerateNodeFactory |
| 262 | + abstract static class SocketTypeNode extends PythonUnaryBuiltinNode { |
| 263 | + @Specialization |
| 264 | + int type(PSocket socket) { |
| 265 | + return socket.getType(); |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + // proto |
| 270 | + @Builtin(name = "proto", fixedNumOfPositionalArgs = 1, isGetter = true) |
| 271 | + @GenerateNodeFactory |
| 272 | + abstract static class SockProtoNode extends PythonUnaryBuiltinNode { |
| 273 | + @Specialization |
| 274 | + int proto(PSocket socket) { |
| 275 | + return socket.getProto(); |
| 276 | + } |
58 | 277 | }
|
59 | 278 | }
|
0 commit comments