diff --git a/native/read.c b/native/unix/read.c similarity index 99% rename from native/read.c rename to native/unix/read.c index 75a1cd9a5b..1f22f949f2 100644 --- a/native/read.c +++ b/native/unix/read.c @@ -1,4 +1,4 @@ -#include "factor.h" +#include "../factor.h" /* Return true if something was read */ bool read_step(F_PORT* port) diff --git a/native/signal.c b/native/unix/signal.c similarity index 98% rename from native/signal.c rename to native/unix/signal.c index 37db15c3c8..f101c6fa3e 100644 --- a/native/signal.c +++ b/native/unix/signal.c @@ -1,4 +1,4 @@ -#include "factor.h" +#include "../factor.h" void signal_handler(int signal, siginfo_t* siginfo, void* uap) { diff --git a/native/socket.c b/native/unix/socket.c similarity index 99% rename from native/socket.c rename to native/unix/socket.c index 5456091947..cf0d9e536f 100644 --- a/native/socket.c +++ b/native/unix/socket.c @@ -1,4 +1,4 @@ -#include "factor.h" +#include "../factor.h" void init_sockaddr(struct sockaddr_in* name, const char* hostname, uint16_t port) diff --git a/native/write.c b/native/unix/write.c similarity index 99% rename from native/write.c rename to native/unix/write.c index a781756b26..81008c4d36 100644 --- a/native/write.c +++ b/native/unix/write.c @@ -1,4 +1,4 @@ -#include "factor.h" +#include "../factor.h" /* Return true if write was done */ void write_step(F_PORT* port) diff --git a/native/win32/write.c b/native/win32/write.c new file mode 100644 index 0000000000..4361e43103 --- /dev/null +++ b/native/win32/write.c @@ -0,0 +1,50 @@ +#include "../factor.h" + +void primitive_add_write_io_task (void) +{ + callback_list = cons(dpop(), callback_list); + dpop(); +} + +void primitive_can_write (void) +{ + dpop(); dpop(); + box_boolean(true); +} + +void write_char_8 (PORT *port, FIXNUM ch) +{ + char buf = (char)ch; + WriteFile((HANDLE)port->fd, &buf, 1, NULL, NULL); +} + +void write_string_8 (PORT *port, STRING *str) +{ + WriteFile((HANDLE)port->fd, to_c_string(str), str->capacity, NULL, NULL); +} + +void primitive_write_8 (void) +{ + PORT *port; + CELL text, type; + + maybe_garbage_collection(); + + port = untag_port(dpop()); + text = dpop(); + type = type_of(text); + + switch (type) + { + case FIXNUM_TYPE: + case BIGNUM_TYPE: + write_char_8(port, to_fixnum(text)); + break; + case STRING_TYPE: + write_string_8(port, untag_string(text)); + break; + default: + type_error(TEXT_TYPE, text); + break; + } +}