From 86f3d2ba19925ccece5c2cecc46db57817ffa85b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 20 Oct 2016 05:21:40 -0700 Subject: 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. --- stream.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'stream.h') diff --git a/stream.h b/stream.h index 14ef8e4f..818ad9cd 100644 --- a/stream.h +++ b/stream.h @@ -37,12 +37,18 @@ enum indent_mode { indent_code }; +struct strm_ctx { + val obj_hash; + val counter; +}; + struct strm_base { enum indent_mode indent_mode; cnum data_width; cnum code_width; cnum indent_chars; cnum column; + struct strm_ctx *ctx; }; struct strm_ops { @@ -126,7 +132,7 @@ void strm_base_init(struct strm_base *s); void strm_base_cleanup(struct strm_base *s); void strm_base_mark(struct strm_base *s); void fill_stream_ops(struct strm_ops *ops); -void stream_print_op(val stream, val out, val pretty); +void stream_print_op(val stream, val out, val pretty, struct strm_ctx *); void stream_mark_op(val stream); void stream_destroy_op(val stream); struct stdio_mode parse_mode(val mode_str, struct stdio_mode m_dfl); @@ -189,6 +195,8 @@ val get_indent(val stream); val set_indent(val stream, val indent); val inc_indent(val stream, val delta); val width_check(val stream, val alt); +struct strm_ctx *get_set_ctx(val stream, struct strm_ctx *); +struct strm_ctx *get_ctx(val stream); val get_string(val stream, val nchars, val close_after_p); val open_directory(val path); val open_file(val path, val mode_str); -- cgit v1.2.3