diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-06-17 00:26:08 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-06-17 00:26:08 -0700 |
commit | 775e10c4007c024981d0b27f5f2e54c8ac54c73d (patch) | |
tree | a5e1f86e95f7490b802ae73da14f030f413b14a9 /stream.c | |
parent | 959c9394dcdee41b0515b705bf8d60921e1532a6 (diff) | |
download | txr-775e10c4007c024981d0b27f5f2e54c8ac54c73d.tar.gz txr-775e10c4007c024981d0b27f5f2e54c8ac54c73d.tar.bz2 txr-775e10c4007c024981d0b27f5f2e54c8ac54c73d.zip |
cobj: clone method streamlines copy; structs get copy method.
* lib.h (struct cobj_ops): New function pointer, clone.
(cobj_ops_init, cobj_ops_init_ex): Add clone argument to macros.
* lib.c (seq_iter_cobj_ops): Use copy_iter as the clone operation.
(cptr_ops): Use copy_cptr as clone operation.
(copy): Replace if statements by check whether COBJ has a clone
operation. If so, we use it to copy the object.
* struct.h (enum special_slot): New member, copy_m.
* struct.c (copy_s): New symbol variable.
(special_sym): Associate copy_m enum value with copy symbol.
(struct_init): Initialize copy_s with interned symbol.
(struct_inst_clone): New static function.
(struct_type_ops): Specify no clone operation via null pointer.
(struct_inst_ops): Specify struct_inst_clone as clone
operation.
* arith.c (psq_ops): Indicate no clone operation via null pointer.
* buf.c (buf_strm_ops): Likewise.
* chksum.c (sha1_ops, sha256_ops, md5_ops): Likewise.
* ffi.c (ffi_type_builtin_ops, ffi_type_struct_ops,
ffi_type_ptr_ops, ffi_type_enum_ops, ffi_closure_ops,
union_ops): Likewise.
(carray_borrowed_ops, carry_owned_ops, carray_mmap_ops):
Specify copy_carray as clone operation.
* gc.c (prot_array_ops): Indicate no clone operation via
null pointer.
* gzip.c (gzio_ops_rd, gzip_ops_wr): Likewise.
* hash.c (hash_iter_ops): Likewise.
(hash_ops): Specify copy_hash as clone operation.
* parser.c (parser_ops): Indicate no clone operation via
null pointer.
* rand.c (random_state_clone): New static function.
(random_state_ops): Use random_state_clone as clone function.
* regex.c (char_set_obj_ops, regex_obj_ops): Indicate no clone
operation via null pointer.
* socket.c (dgram_strm_ops): Likewise.
* stream.c (null-ops, stdio_ops, tail_ops, pipe_ops,
dir_ops, string_in_ops, byte_in_ops, strlist_in_ops,
string_out_ops, strlist_out_ops, cat_stream_ops,
record_adapter_ops): Likewise.
* strudel.c (strudel_ops): Likewise.
* sysif.c (cptr_dl_ops, opendir_ops): Likewise.
* syslog.c (syslog_strm_ops): Likewise.
* unwind.c (cont_ops): Likewise.
* vm.c (vm_desc_ops, vm_closure_ops): Likewise.
* tree.c (tree_ops): Use copy_search_tree for clone
operation.
(tree_iter_ops): Use copy_tree_iter for clone operation.
* genchksum.txr: Changes in chksum.c specified in one
place here.
* tests/012/oop.tl: Couple of new tests.
* txr.1: Documented.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -491,7 +491,8 @@ static struct strm_ops null_ops = stream_print_op, stream_destroy_op, stream_mark_op, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("null-stream"), null_put_string, null_put_char, null_put_byte, null_get_line, null_get_char, null_get_byte, @@ -1094,7 +1095,8 @@ static struct strm_ops stdio_ops = stdio_stream_print, stdio_stream_destroy, stdio_stream_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("file-stream"), stdio_put_string, stdio_put_char, @@ -1332,7 +1334,8 @@ static struct strm_ops tail_ops = stdio_stream_print, stdio_stream_destroy, stdio_stream_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("tail-stream"), stdio_put_string, stdio_put_char, @@ -1413,7 +1416,8 @@ static struct strm_ops pipe_ops = stdio_stream_print, stdio_stream_destroy, stdio_stream_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("pipe-stream"), stdio_put_string, stdio_put_char, @@ -1892,7 +1896,8 @@ static struct strm_ops dir_ops = stream_print_op, dir_destroy, dir_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("dir-stream"), 0, 0, 0, dir_get_line, @@ -2011,7 +2016,8 @@ static struct strm_ops string_in_ops = stream_print_op, stream_destroy_op, string_in_stream_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("string-input-stream"), 0, 0, 0, string_in_get_line, @@ -2090,7 +2096,8 @@ static struct strm_ops byte_in_ops = stream_print_op, byte_in_stream_destroy, stream_mark_op, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("byte-input-stream"), 0, 0, 0, 0, 0, byte_in_get_byte, @@ -2225,7 +2232,8 @@ static struct strm_ops strlist_in_ops = stream_print_op, stream_destroy_op, strlist_in_stream_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("strlist-input-stream"), 0, 0, 0, strlist_in_get_line, @@ -2374,7 +2382,8 @@ static struct strm_ops string_out_ops = stream_print_op, string_out_stream_destroy, stream_mark_op, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("string-output-stream"), string_out_put_string, string_out_put_char, @@ -2497,7 +2506,8 @@ static struct strm_ops strlist_out_ops = stream_print_op, stream_destroy_op, strlist_out_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("strlist-output-stream"), strlist_out_put_string, strlist_out_put_char, @@ -2678,7 +2688,8 @@ static struct strm_ops cat_stream_ops = cat_stream_print, stream_destroy_op, cat_mark, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("catenated-stream"), 0, 0, 0, cat_get_line, @@ -2937,7 +2948,8 @@ static struct strm_ops record_adapter_ops = stream_print_op, stream_destroy_op, record_adapter_mark_op, - cobj_eq_hash_op), + cobj_eq_hash_op, + 0), wli("record-adapter"), delegate_put_string, delegate_put_char, delegate_put_byte, record_adapter_get_line, delegate_get_char, delegate_get_byte, |