mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
Issue #102 - Added a data parameter to Cyc_write()
This commit is contained in:
parent
764c12db15
commit
f60fed7344
3 changed files with 19 additions and 17 deletions
|
@ -149,11 +149,11 @@ void dispatch_display_va(void *data, int argc, object clo, object cont,
|
||||||
object Cyc_display_va(int argc, object x, ...);
|
object Cyc_display_va(int argc, object x, ...);
|
||||||
object Cyc_display_va_list(int argc, object x, va_list ap);
|
object Cyc_display_va_list(int argc, object x, va_list ap);
|
||||||
object Cyc_write_char(void *data, object c, object port);
|
object Cyc_write_char(void *data, object c, object port);
|
||||||
object Cyc_write(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, int argc, object clo, object cont,
|
||||||
object x, ...);
|
object x, ...);
|
||||||
object Cyc_write_va(int argc, object x, ...);
|
object Cyc_write_va(void *data, int argc, object x, ...);
|
||||||
object Cyc_write_va_list(int argc, object x, va_list ap);
|
object Cyc_write_va_list(void *data, int argc, object x, va_list ap);
|
||||||
|
|
||||||
object Cyc_has_cycle(object lst);
|
object Cyc_has_cycle(object lst);
|
||||||
object Cyc_num_eq(void *, object cont, int argc, object n, ...);
|
object Cyc_num_eq(void *, object cont, int argc, object n, ...);
|
||||||
|
|
28
runtime.c
28
runtime.c
|
@ -492,7 +492,7 @@ object Cyc_default_exception_handler(void *data, int argc, closure _,
|
||||||
Cyc_display(car(err), stderr);
|
Cyc_display(car(err), stderr);
|
||||||
fprintf(stderr, ": ");
|
fprintf(stderr, ": ");
|
||||||
} else {
|
} else {
|
||||||
Cyc_write(car(err), stderr);
|
Cyc_write(data, car(err), stderr);
|
||||||
fprintf(stderr, " ");
|
fprintf(stderr, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,22 +852,22 @@ void dispatch_write_va(void *data, int argc, object clo, object cont,
|
||||||
object result;
|
object result;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, x);
|
va_start(ap, x);
|
||||||
result = Cyc_write_va_list(argc - 1, x, ap);
|
result = Cyc_write_va_list(data, argc - 1, x, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return_closcall1(data, cont, result);
|
return_closcall1(data, cont, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
object Cyc_write_va(int argc, object x, ...)
|
object Cyc_write_va(void *data, int argc, object x, ...)
|
||||||
{
|
{
|
||||||
object result;
|
object result;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, x);
|
va_start(ap, x);
|
||||||
result = Cyc_write_va_list(argc, x, ap);
|
result = Cyc_write_va_list(data, argc, x, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
object Cyc_write_va_list(int argc, object x, va_list ap)
|
object Cyc_write_va_list(void *data, int argc, object x, va_list ap)
|
||||||
{
|
{
|
||||||
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
|
// Longer-term maybe we get rid of varargs for this one
|
||||||
|
@ -886,10 +886,10 @@ object Cyc_write_va_list(int argc, object x, va_list ap)
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Cyc_write(x, fp);
|
return Cyc_write(data, x, fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object _Cyc_write(object x, FILE * port)
|
static object _Cyc_write(void *data, object x, FILE * port)
|
||||||
{
|
{
|
||||||
object tmp = NULL;
|
object tmp = NULL;
|
||||||
object has_cycle = boolean_f;
|
object has_cycle = boolean_f;
|
||||||
|
@ -952,14 +952,14 @@ static object _Cyc_write(object x, FILE * port)
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
fprintf(port, " ");
|
fprintf(port, " ");
|
||||||
}
|
}
|
||||||
_Cyc_write(((vector) x)->elements[i], port);
|
_Cyc_write(data, ((vector) x)->elements[i], port);
|
||||||
}
|
}
|
||||||
fprintf(port, ")");
|
fprintf(port, ")");
|
||||||
break;
|
break;
|
||||||
case pair_tag:
|
case pair_tag:
|
||||||
has_cycle = Cyc_has_cycle(x);
|
has_cycle = Cyc_has_cycle(x);
|
||||||
fprintf(port, "(");
|
fprintf(port, "(");
|
||||||
_Cyc_write(car(x), port);
|
_Cyc_write(data, car(x), port);
|
||||||
|
|
||||||
// Experimenting with displaying lambda defs in REPL
|
// Experimenting with displaying lambda defs in REPL
|
||||||
// not good enough but this is a start. would probably need
|
// not good enough but this is a start. would probably need
|
||||||
|
@ -967,7 +967,7 @@ static object _Cyc_write(object x, FILE * port)
|
||||||
if (Cyc_is_symbol(car(x)) == boolean_t &&
|
if (Cyc_is_symbol(car(x)) == boolean_t &&
|
||||||
strncmp(((symbol) car(x))->desc, "procedure", 10) == 0) {
|
strncmp(((symbol) car(x))->desc, "procedure", 10) == 0) {
|
||||||
fprintf(port, " ");
|
fprintf(port, " ");
|
||||||
_Cyc_write(cadr(x), port);
|
_Cyc_write(data, cadr(x), port);
|
||||||
fprintf(port, " ...)"); /* skip body and env for now */
|
fprintf(port, " ...)"); /* skip body and env for now */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -978,13 +978,13 @@ static object _Cyc_write(object x, FILE * port)
|
||||||
break; /* arbitrary number, for now */
|
break; /* arbitrary number, for now */
|
||||||
}
|
}
|
||||||
fprintf(port, " ");
|
fprintf(port, " ");
|
||||||
_Cyc_write(car(tmp), port);
|
_Cyc_write(data, car(tmp), port);
|
||||||
}
|
}
|
||||||
if (has_cycle == boolean_t) {
|
if (has_cycle == boolean_t) {
|
||||||
fprintf(port, " ...");
|
fprintf(port, " ...");
|
||||||
} else if (tmp) {
|
} else if (tmp) {
|
||||||
fprintf(port, " . ");
|
fprintf(port, " . ");
|
||||||
_Cyc_write(tmp, port);
|
_Cyc_write(data, tmp, port);
|
||||||
}
|
}
|
||||||
fprintf(port, ")");
|
fprintf(port, ")");
|
||||||
break;
|
break;
|
||||||
|
@ -994,9 +994,9 @@ static object _Cyc_write(object x, FILE * port)
|
||||||
return quote_void;
|
return quote_void;
|
||||||
}
|
}
|
||||||
|
|
||||||
object Cyc_write(object x, FILE * port)
|
object Cyc_write(void *data, object x, FILE * port)
|
||||||
{
|
{
|
||||||
object y = _Cyc_write(x, port);
|
object y = _Cyc_write(data, x, port);
|
||||||
//fprintf(port, "\n");
|
//fprintf(port, "\n");
|
||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -607,6 +607,8 @@
|
||||||
close-input-port
|
close-input-port
|
||||||
close-output-port
|
close-output-port
|
||||||
Cyc-flush-output-port
|
Cyc-flush-output-port
|
||||||
|
; TODO: Cyc-display
|
||||||
|
Cyc-write
|
||||||
file-exists?
|
file-exists?
|
||||||
delete-file
|
delete-file
|
||||||
read-char
|
read-char
|
||||||
|
|
Loading…
Add table
Reference in a new issue