From a232defd00a43ce8b6a149811140ba40c52ae05b Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Mon, 13 Jan 2014 01:47:46 +0900 Subject: [PATCH] newline can take an optional argument --- src/port.c | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/port.c b/src/port.c index a76c68e9..b29ddc17 100644 --- a/src/port.c +++ b/src/port.c @@ -27,6 +27,16 @@ pic_stdin(pic_state *pic) return pic_port_ptr(pic_apply(pic, proc, pic_nil_value())); } +struct pic_port * +pic_stdout(pic_state *pic) +{ + struct pic_proc *proc; + + proc = pic_proc_ptr(pic_ref(pic, "current-output-port")); + + return pic_port_ptr(pic_apply(pic, proc, pic_nil_value())); +} + static void write_pair(pic_state *pic, struct pic_pair *pair); static void write_str(pic_state *pic, struct pic_string *str); @@ -297,23 +307,6 @@ pic_port_output_port_open_p(pic_state *pic) return pic_bool_value(port->status == PIC_PORT_OPEN); } -static pic_value -pic_port_write_simple(pic_state *pic) -{ - pic_value v; - - pic_get_args(pic, "o", &v); - write(pic, v); - return pic_none_value(); -} - -static pic_value -pic_port_newline(pic_state *pic) -{ - puts(""); - return pic_none_value(); -} - static pic_value pic_port_eof_object_p(pic_state *pic) { @@ -412,6 +405,29 @@ pic_port_peek_char(pic_state *pic) } } +static pic_value +pic_port_newline(pic_state *pic) +{ + struct pic_port *port = pic_stdout(pic); + + pic_get_args(pic, "|p", &port); + + assert_port_profile(port, PIC_PORT_OUT | PIC_PORT_TEXT, PIC_PORT_OPEN, "newline"); + + fputs("\n", port->file); + return pic_none_value(); +} + +static pic_value +pic_port_write_simple(pic_state *pic) +{ + pic_value v; + + pic_get_args(pic, "o", &v); + write(pic, v); + return pic_none_value(); +} + void pic_init_port(pic_state *pic) {