Converting function calls

This commit is contained in:
Justin Ethier 2021-02-16 22:55:40 -05:00
parent d5ba874ae2
commit 24bbc2e39d
2 changed files with 27 additions and 21 deletions

View file

@ -253,10 +253,9 @@ object Cyc_display_va(void *data, int argc, object x, ...);
object Cyc_display_va_list(void *data, object x, object opts); object Cyc_display_va_list(void *data, object x, object opts);
object Cyc_write_char(void *data, object c, object port); object Cyc_write_char(void *data, object c, object port);
object Cyc_write(void *data, object, FILE * port); object Cyc_write(void *data, object, FILE * port);
void dispatch_write_va(void *data, int argc, object clo, object cont, void dispatch_write_va(void *data, object clo, int argc, object *args);
object x, ...);
object Cyc_write_va(void *data, int argc, object x, ...); object Cyc_write_va(void *data, int argc, object x, ...);
object Cyc_write_va_list(void *data, int argc, object x, va_list ap); object Cyc_write_va_list(void *data, object x, object opts);
port_type Cyc_stdout(void); port_type Cyc_stdout(void);
port_type Cyc_stdin(void); port_type Cyc_stdin(void);
port_type Cyc_stderr(void); port_type Cyc_stderr(void);

View file

@ -1188,38 +1188,40 @@ object Cyc_display(void *data, object x, FILE * port)
return quote_void; return quote_void;
} }
void dispatch_write_va(void *data, int argc, object clo, object cont, void dispatch_write_va(void *data, object clo, int argc, object *args)
object x, ...)
{ {
object x = args[0];
object opts = boolean_f;
object result; object result;
va_list ap; if (argc > 1) {
va_start(ap, x); opts = args[1];
result = Cyc_write_va_list(data, argc - 1, x, ap); }
va_end(ap); result = Cyc_write_va_list(data, x, opts);
return_closcall1(data, cont, result); return_closcall1(data, cont, result);
} }
object Cyc_write_va(void *data, int argc, object x, ...) object Cyc_write_va(void *data, int argc, object x, ...)
{ {
object result; object result;
object opts = boolean_f;
va_list ap; va_list ap;
va_start(ap, x); va_start(ap, x);
result = Cyc_write_va_list(data, argc, x, ap); if (argc > 1) {
opts = va_arg(ap, object);
}
result = Cyc_write_va_list(data, x, opts);
va_end(ap); va_end(ap);
return result; return result;
} }
object Cyc_write_va_list(void *data, int argc, object x, va_list ap) object Cyc_write_va_list(void *data, object x, object opts)
{ {
FILE *fp = stdout; // OK since this is the internal version of write FILE *fp = stdout; // OK since this is the internal version of write
// Longer-term maybe we get rid of varargs for this one if (opts != boolean_f) {
if (argc > 1) { Cyc_check_port(data, opts);
object tmp; fp = ((port_type *) opts)->fp;
tmp = va_arg(ap, object);
Cyc_check_port(data, tmp);
fp = ((port_type *) tmp)->fp;
if (fp == NULL) { if (fp == NULL) {
Cyc_rt_raise2(data, "Unable to write to closed port: ", tmp); Cyc_rt_raise2(data, "Unable to write to closed port: ", opts);
return quote_void; return quote_void;
} }
} }
@ -5537,8 +5539,13 @@ void _Cyc_91write(void *data, object cont, object args)
Cyc_check_num_args(data, "write", 1, args); Cyc_check_num_args(data, "write", 1, args);
{ {
object argc = Cyc_length(data, args); object argc = Cyc_length(data, args);
dispatch(data, obj_obj2int(argc), (function_type) dispatch_write_va, cont, int c = obj_obj2int(argc);
cont, args); object buf[2];
buf[0] = car(args);
if (c > 1) {
buf[1] = cadr(args);
}
dispatch_write_va(data, cont, c, buf);
}} }}
void _display(void *data, object cont, object args) void _display(void *data, object cont, object args)
@ -5552,7 +5559,7 @@ void _display(void *data, object cont, object args)
if (c > 1) { if (c > 1) {
buf[1] = cadr(args); buf[1] = cadr(args);
} }
dispatch_display_va(data, cont, argc, buf); dispatch_display_va(data, cont, c, buf);
} }
} }