summaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-10-20 05:21:40 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-10-20 05:21:40 -0700
commit86f3d2ba19925ccece5c2cecc46db57817ffa85b (patch)
treee3100caf6b5b4d92d0361e8b873508f0fa0d9a4c /struct.c
parenta22082e8325d6eb9911604ead620485184c1df6e (diff)
downloadtxr-86f3d2ba19925ccece5c2cecc46db57817ffa85b.tar.gz
txr-86f3d2ba19925ccece5c2cecc46db57817ffa85b.tar.bz2
txr-86f3d2ba19925ccece5c2cecc46db57817ffa85b.zip
Add stream printing context.
This is some infrastructure which will support *print-circle*. * lib.h (struct strm_ctx): Forward declared. (struct cobj_ops): Add context parameter to print function pointer. (cobj_print_op, obj_print_impl): Add context parameter to declarations. * hash.c (hash_print_op): Take context argument and pass it down in obj_print_impl calls. * lib.c (cobj_print_op, out_quasi_str): Likewise (obj_print_impl): Likewise, and also pass to COBJ print method. (obj_print, obj_pprint): Pass null pointer as context argument to obj_print_impl. * regex.c (regex_print): Take context parameter and ignore it. * socket.c (dgram_print): Likewise. * stream.h (struct strm_ctx): New struct type. (struct strm_base): New ctx member, pointer to struct strm_ctx. (stream_print_op): Add context parameter to declaration. (get_set_ctx, get_ctx): Declared. * stream.c (strm_base_init): Add null pointer to initializer. (strm_base_cleanup): Add assertion against context pointer being non-null: that indicates that some stream operation installed a context pointer and neglected to restore it to null before returning, which is bad because context will be stack allocated. (stream_print_op, stdio_stream_print, cat_stream_print): Take context parameter and ignore it. (get_set_ctx, get_ctx): New functions. * struct.c (struct_type_print): Take context parameter and ignore it. (struct_inst_print): Take context parameter and pass down to obj_print_impl.
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/struct.c b/struct.c
index 54631098..b109751c 100644
--- a/struct.c
+++ b/struct.c
@@ -373,9 +373,10 @@ val super(val type)
}
}
-static void struct_type_print(val obj, val out, val pretty)
+static void struct_type_print(val obj, val out, val pretty, struct strm_ctx *c)
{
struct struct_type *st = coerce(struct struct_type *, obj->co.handle);
+ (void) c;
format(out, lit("#<struct-type ~s>"), st->name, nao);
}
@@ -1225,7 +1226,8 @@ val umethod(val slot, struct args *args)
return func_f0v(cons(slot, args_get_list(args)), umethod_args_fun);
}
-static void struct_inst_print(val obj, val out, val pretty)
+static void struct_inst_print(val obj, val out, val pretty,
+ struct strm_ctx *ctx)
{
struct struct_inst *si = coerce(struct struct_inst *, obj->co.handle);
struct struct_type *st = si->type;
@@ -1242,7 +1244,7 @@ static void struct_inst_print(val obj, val out, val pretty)
}
put_string(lit("#S("), out);
- obj_print_impl(st->name, out, pretty);
+ obj_print_impl(st->name, out, pretty, ctx);
save_indent = inc_indent(out, one);
for (iter = st->slots, once = t; iter; iter = cdr(iter)) {
@@ -1254,9 +1256,9 @@ static void struct_inst_print(val obj, val out, val pretty)
} else {
width_check(out, chr(' '));
}
- obj_print_impl(sym, out, pretty);
+ obj_print_impl(sym, out, pretty, ctx);
put_char(chr(' '), out);
- obj_print_impl(slot(obj, sym), out, pretty);
+ obj_print_impl(slot(obj, sym), out, pretty, ctx);
}
}
put_char(chr(')'), out);