diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-10-20 21:36:33 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-10-20 21:36:33 -0700 |
commit | 6d8df2a98bae323078951e4d4268a30b4743e31e (patch) | |
tree | feae27bbcc443512d1ade58098c71bb79baa7727 /struct.c | |
parent | eb6b20a502f7c20b6a5cfc9155dcbf2cb06c895e (diff) | |
download | txr-6d8df2a98bae323078951e4d4268a30b4743e31e.tar.gz txr-6d8df2a98bae323078951e4d4268a30b4743e31e.tar.bz2 txr-6d8df2a98bae323078951e4d4268a30b4743e31e.zip |
Changes to the printing framework.
The print function now takes an optional boolean
for pretty printing.
The print method is also called with a third argument;
hence structures can customize both standard printing
and pretty printing.
* lib.c (obj_print): Take pretty argument, and pass it down
to obj_print_impl. This makes obj_pprint redundant.
(obj_pprint): Function removed: it was identical to obj_print
except for passing t down to obj_print_impl for the
pretty argument. These two wrappers had started small and
got bigger with identical changes done in parallel.
(pprint): New function.
(tostring, dump): Pass nil for pretty argument of obj_print.
(tostringp): Use pprint instead of obj_pprint.
* lib.h (obj_print): Declaration updated.
(obj_pprint): Declaration removed.
(print, pprint): Declared.
* eval.c (prinl): Pass nil for pretty_p argument of obj_print.
Do the stream defaulting here; obj_print doesn't do it.
(pprinl): Pass t for pretty_p argument of obj_print,
and do stream argument defaulting.
(eval_init): Register print to new print function rather
than directly to obj_print.
Register pprint to new pprint function rather than obj_pprint.
* hash.c (hash_print_op): Call obj_print_impl to print
the :equal-based keyword, rather than obj_print. Pass
down the pretty flag. All the other keywords are treated
this way; this fixes an inconsistency.
* match.c (dump_var): Call pprint instead of obj_pprint.
* stream.c (formatv): Call obj_print, with a calculated
pretty argument instead of switching between obj_pprint
and obj_print.
* struct.c (struct_inst_print): Except when in backward
compatibility mode, call the object's print method in both
pretty and regular printing mode, passing the mode as a third
argument.
* tests/012/oop.tl (defstruct animal): Support third argument
in print method. Make it optional because there are some
explicit calls which don't pass the argument.
* txr.1: Documentation updated for print method and the
print function. Revised text for some of the related
functions. Added compat notes.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -1251,11 +1251,15 @@ static void struct_inst_print(val obj, val out, val pretty, val save_mode = test_set_indent_mode(out, num_fast(indent_off), num_fast(indent_data)); val save_indent, iter, once; + int compat = opt_compat && opt_compat <= 154; - if (pretty) { + if (!compat || pretty) { loc ptr = lookup_static_slot_load(st->self, st, print_s); if (!nullocp(ptr)) { - funcall2(deref(ptr), obj, out); + if (compat) + funcall2(deref(ptr), obj, out); + else + funcall3(deref(ptr), obj, out, pretty); return; } } |