Turn print_princ into print_readably
This commit is contained in:
parent
4550e1ba79
commit
098a991ed8
34
c/print.h
34
c/print.h
|
@ -1,7 +1,7 @@
|
||||||
extern void *memrchr(const void *s, int c, size_t n);
|
extern void *memrchr(const void *s, int c, size_t n);
|
||||||
|
|
||||||
// not *print-readably* -- use `display` repr instead of `write` repr
|
// *print-readably* -- use `write` repr instead of `display` repr
|
||||||
static int print_princ;
|
static int print_readably;
|
||||||
|
|
||||||
// *print-pretty* -- indent instead of printing everything on one long line
|
// *print-pretty* -- indent instead of printing everything on one long line
|
||||||
static int print_pretty;
|
static int print_pretty;
|
||||||
|
@ -404,7 +404,7 @@ void fl_print_child(struct ios *f, value_t v)
|
||||||
break;
|
break;
|
||||||
case TAG_SYM:
|
case TAG_SYM:
|
||||||
name = symbol_name(v);
|
name = symbol_name(v);
|
||||||
if (print_princ)
|
if (!print_readably)
|
||||||
outs(name, f);
|
outs(name, f);
|
||||||
else if (ismanaged(v)) {
|
else if (ismanaged(v)) {
|
||||||
outsn("#:", f, 2);
|
outsn("#:", f, 2);
|
||||||
|
@ -422,12 +422,12 @@ void fl_print_child(struct ios *f, value_t v)
|
||||||
} else if (v == FL_EOF) {
|
} else if (v == FL_EOF) {
|
||||||
outsn("#<eof>", f, 6);
|
outsn("#<eof>", f, 6);
|
||||||
} else if (isbuiltin(v)) {
|
} else if (isbuiltin(v)) {
|
||||||
if (!print_princ)
|
if (print_readably)
|
||||||
outsn("#.", f, 2);
|
outsn("#.", f, 2);
|
||||||
outs(builtin_names[uintval(v)], f);
|
outs(builtin_names[uintval(v)], f);
|
||||||
} else {
|
} else {
|
||||||
assert(isclosure(v));
|
assert(isclosure(v));
|
||||||
if (!print_princ) {
|
if (print_readably) {
|
||||||
struct function *fn;
|
struct function *fn;
|
||||||
char *data;
|
char *data;
|
||||||
size_t i, sz;
|
size_t i, sz;
|
||||||
|
@ -468,7 +468,7 @@ void fl_print_child(struct ios *f, value_t v)
|
||||||
case TAG_CVALUE:
|
case TAG_CVALUE:
|
||||||
case TAG_VECTOR:
|
case TAG_VECTOR:
|
||||||
case TAG_CONS:
|
case TAG_CONS:
|
||||||
if (!print_princ && print_circle_prefix(f, v))
|
if (print_readably && print_circle_prefix(f, v))
|
||||||
break;
|
break;
|
||||||
if (isvector(v)) {
|
if (isvector(v)) {
|
||||||
int newindent, est, sz, i;
|
int newindent, est, sz, i;
|
||||||
|
@ -639,7 +639,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
{
|
{
|
||||||
if (type == bytesym) {
|
if (type == bytesym) {
|
||||||
unsigned char ch = *(unsigned char *)data;
|
unsigned char ch = *(unsigned char *)data;
|
||||||
if (print_princ)
|
if (!print_readably)
|
||||||
outc(ch, f);
|
outc(ch, f);
|
||||||
else if (weak)
|
else if (weak)
|
||||||
HPOS += ios_printf(f, "#x%hhx", ch);
|
HPOS += ios_printf(f, "#x%hhx", ch);
|
||||||
|
@ -651,7 +651,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
size_t nb = u8_toutf8(seq, sizeof(seq), &wc, 1);
|
size_t nb = u8_toutf8(seq, sizeof(seq), &wc, 1);
|
||||||
|
|
||||||
seq[nb] = '\0';
|
seq[nb] = '\0';
|
||||||
if (print_princ) {
|
if (!print_readably) {
|
||||||
// TODO: better multibyte handling
|
// TODO: better multibyte handling
|
||||||
if (wc == 0)
|
if (wc == 0)
|
||||||
ios_putc(0, f);
|
ios_putc(0, f);
|
||||||
|
@ -705,7 +705,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
rep = sign_bit(d) ? "-nan.0" : "+nan.0";
|
rep = sign_bit(d) ? "-nan.0" : "+nan.0";
|
||||||
else
|
else
|
||||||
rep = sign_bit(d) ? "-inf.0" : "+inf.0";
|
rep = sign_bit(d) ? "-inf.0" : "+inf.0";
|
||||||
if (type == floatsym && !print_princ && !weak)
|
if (type == floatsym && print_readably && !weak)
|
||||||
HPOS += ios_printf(f, "#%s(%s)", symbol_name(type), rep);
|
HPOS += ios_printf(f, "#%s(%s)", symbol_name(type), rep);
|
||||||
else
|
else
|
||||||
outs(rep, f);
|
outs(rep, f);
|
||||||
|
@ -714,7 +714,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
outsn("-0.0", f, 4);
|
outsn("-0.0", f, 4);
|
||||||
else
|
else
|
||||||
outsn("0.0", f, 3);
|
outsn("0.0", f, 3);
|
||||||
if (type == floatsym && !print_princ && !weak)
|
if (type == floatsym && print_readably && !weak)
|
||||||
outc('f', f);
|
outc('f', f);
|
||||||
} else {
|
} else {
|
||||||
int hasdec;
|
int hasdec;
|
||||||
|
@ -724,7 +724,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
outs(buf, f);
|
outs(buf, f);
|
||||||
if (!hasdec)
|
if (!hasdec)
|
||||||
outsn(".0", f, 2);
|
outsn(".0", f, 2);
|
||||||
if (type == floatsym && !print_princ && !weak)
|
if (type == floatsym && print_readably && !weak)
|
||||||
outc('f', f);
|
outc('f', f);
|
||||||
}
|
}
|
||||||
} else if (type == uint64sym
|
} else if (type == uint64sym
|
||||||
|
@ -733,7 +733,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
uint64_t ui64 = *(uint64_t *)data;
|
uint64_t ui64 = *(uint64_t *)data;
|
||||||
if (weak || print_princ)
|
if (weak || !print_readably)
|
||||||
HPOS += ios_printf(f, "%llu", ui64);
|
HPOS += ios_printf(f, "%llu", ui64);
|
||||||
else
|
else
|
||||||
HPOS += ios_printf(f, "#%s(%llu)", symbol_name(type), ui64);
|
HPOS += ios_printf(f, "#%s(%llu)", symbol_name(type), ui64);
|
||||||
|
@ -745,7 +745,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
HPOS += ios_printf(f, "#<%s>", symbol_name(type));
|
HPOS += ios_printf(f, "#<%s>", symbol_name(type));
|
||||||
} else {
|
} else {
|
||||||
int64_t i64 = conv_to_int64(data, nt);
|
int64_t i64 = conv_to_int64(data, nt);
|
||||||
if (weak || print_princ)
|
if (weak || !print_readably)
|
||||||
HPOS += ios_printf(f, "%lld", i64);
|
HPOS += ios_printf(f, "%lld", i64);
|
||||||
else
|
else
|
||||||
HPOS += ios_printf(f, "#%s(%lld)", symbol_name(type), i64);
|
HPOS += ios_printf(f, "#%s(%lld)", symbol_name(type), i64);
|
||||||
|
@ -765,7 +765,7 @@ static void cvalue_printdata(struct ios *f, void *data, size_t len,
|
||||||
cnt = elsize ? len / elsize : 0;
|
cnt = elsize ? len / elsize : 0;
|
||||||
}
|
}
|
||||||
if (eltype == bytesym) {
|
if (eltype == bytesym) {
|
||||||
if (print_princ) {
|
if (!print_readably) {
|
||||||
ios_write(f, data, len);
|
ios_write(f, data, len);
|
||||||
/*
|
/*
|
||||||
char *nl = memrchr(data, '\n', len);
|
char *nl = memrchr(data, '\n', len);
|
||||||
|
@ -837,7 +837,7 @@ static void cvalue_print(struct ios *f, value_t v)
|
||||||
HPOS +=
|
HPOS +=
|
||||||
ios_printf(f, "#<builtin @#x%08zx>", (size_t)(builtin_t)fptr);
|
ios_printf(f, "#<builtin @#x%08zx>", (size_t)(builtin_t)fptr);
|
||||||
} else {
|
} else {
|
||||||
if (print_princ) {
|
if (!print_readably) {
|
||||||
outs(symbol_name(label), f);
|
outs(symbol_name(label), f);
|
||||||
} else {
|
} else {
|
||||||
outsn("#fn(", f, 4);
|
outsn("#fn(", f, 4);
|
||||||
|
@ -872,7 +872,7 @@ void fl_print(struct ios *f, value_t v)
|
||||||
print_pretty = (symbol_value(printprettysym) != FL_F);
|
print_pretty = (symbol_value(printprettysym) != FL_F);
|
||||||
if (print_pretty)
|
if (print_pretty)
|
||||||
set_print_width();
|
set_print_width();
|
||||||
print_princ = (symbol_value(printreadablysym) == FL_F);
|
print_readably = (symbol_value(printreadablysym) != FL_F);
|
||||||
|
|
||||||
pl = symbol_value(printlengthsym);
|
pl = symbol_value(printlengthsym);
|
||||||
if (isfixnum(pl))
|
if (isfixnum(pl))
|
||||||
|
@ -887,7 +887,7 @@ void fl_print(struct ios *f, value_t v)
|
||||||
P_LEVEL = 0;
|
P_LEVEL = 0;
|
||||||
|
|
||||||
printlabel = 0;
|
printlabel = 0;
|
||||||
if (!print_princ)
|
if (print_readably)
|
||||||
print_traverse(v);
|
print_traverse(v);
|
||||||
HPOS = VPOS = 0;
|
HPOS = VPOS = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue