mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-12 07:17:37 +02:00
Proper formatting of (write) output
This commit is contained in:
parent
701b423edd
commit
fd9b66f071
1 changed files with 38 additions and 2 deletions
40
runtime.h
40
runtime.h
|
@ -687,8 +687,10 @@ static object Cyc_display(x) object x;
|
||||||
printf("Cyc_display: bad tag x=%ld\n", ((closure)x)->tag); getchar(); exit(0);}
|
printf("Cyc_display: bad tag x=%ld\n", ((closure)x)->tag); getchar(); exit(0);}
|
||||||
return x;}
|
return x;}
|
||||||
|
|
||||||
static object Cyc_write(x) object x;
|
static object _Cyc_write(x) object x;
|
||||||
{object tmp = nil;
|
{object tmp = nil;
|
||||||
|
object has_cycle = boolean_f;
|
||||||
|
int i = 0;
|
||||||
if (nullp(x)) {printf("()\n"); return x;}
|
if (nullp(x)) {printf("()\n"); return x;}
|
||||||
if (obj_is_char(x)) {printf("#\\%c\n", obj_obj2char(x)); return x;}
|
if (obj_is_char(x)) {printf("#\\%c\n", obj_obj2char(x)); return x;}
|
||||||
switch (type_of(x))
|
switch (type_of(x))
|
||||||
|
@ -696,11 +698,45 @@ static object Cyc_write(x) object x;
|
||||||
printf("\"%s\"", ((string_type *) x)->str);
|
printf("\"%s\"", ((string_type *) x)->str);
|
||||||
break;
|
break;
|
||||||
// TODO: what about a list? contents should be displayed per (write)
|
// TODO: what about a list? contents should be displayed per (write)
|
||||||
|
case cons_tag:
|
||||||
|
has_cycle = Cyc_has_cycle(x);
|
||||||
|
printf("(");
|
||||||
|
_Cyc_write(car(x));
|
||||||
|
|
||||||
|
// Experimenting with displaying lambda defs in REPL
|
||||||
|
// not good enough but this is a start. would probably need
|
||||||
|
// the same code in write()
|
||||||
|
if (equal(quote_Cyc_191procedure, car(x))) {
|
||||||
|
printf(" ");
|
||||||
|
_Cyc_write(cadr(x));
|
||||||
|
printf(" ...)"); /* skip body and env for now */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmp = cdr(x); tmp && ((closure) tmp)->tag == cons_tag; tmp = cdr(tmp)) {
|
||||||
|
if (has_cycle == boolean_t) {
|
||||||
|
if (i++ > 20) break; /* arbitrary number, for now */
|
||||||
|
}
|
||||||
|
printf(" ");
|
||||||
|
_Cyc_write(car(tmp));
|
||||||
|
}
|
||||||
|
if (has_cycle == boolean_t) {
|
||||||
|
printf(" ...");
|
||||||
|
} else if (tmp) {
|
||||||
|
printf(" . ");
|
||||||
|
_Cyc_write(tmp);
|
||||||
|
}
|
||||||
|
printf(")");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
Cyc_display(x);}
|
Cyc_display(x);}
|
||||||
printf("\n");
|
|
||||||
return x;}
|
return x;}
|
||||||
|
|
||||||
|
static object Cyc_write(x) object x;
|
||||||
|
{object y = _Cyc_write(x);
|
||||||
|
printf("\n");
|
||||||
|
return y;}
|
||||||
|
|
||||||
/* Some of these non-consing functions have been optimized from CPS. */
|
/* Some of these non-consing functions have been optimized from CPS. */
|
||||||
|
|
||||||
static object memberp(x,l) object x; list l;
|
static object memberp(x,l) object x; list l;
|
||||||
|
|
Loading…
Add table
Reference in a new issue