From 307ddfe0bbb4ad7997cccbda5abb750b599b10be Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 16 Apr 2017 22:26:12 -0700 Subject: New buffer data type. Work in progress. * gc.c (finalize): Add cast to switch expression so gcc flags when we are missing one of the enumerations. Handle new BUF enum to free dynamic buffers. (mark_obj): Mark len and size fields of buf, in case they aren't just nil or integers. * hash.c (hash_buf): New static function. (equal_hash): Route BUF type to hash_buf. * lib.c (buf_s): New symbol variable. (code2type): Handle BUF. (equal): Handle BUF using memcmp on the data. (obj_init): Intern buf symbol and initialize buf_s. * lib.h (type_t): New enum member BUF. (struct buf): New type. (union obj): New member b, of struct buf type. (buf_s): Declared. --- lib.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index c9456cca..44074453 100644 --- a/lib.h +++ b/lib.h @@ -59,7 +59,7 @@ typedef int_ptr_t cnum; typedef enum type { NIL = TAG_PTR, NUM = TAG_NUM, CHR = TAG_CHR, LIT = TAG_LIT, CONS, STR, SYM, PKG, FUN, VEC, LCONS, LSTR, COBJ, ENV, - BGNUM, FLNUM, RNG, MAXTYPE = RNG + BGNUM, FLNUM, RNG, BUF, MAXTYPE = BUF /* If extending, check TYPE_SHIFT */ } type_t; @@ -279,6 +279,13 @@ struct range { val from, to; }; +struct buf { + obj_common; + mem_t *data; + val len; + val size; +}; + union obj { struct any t; struct cons c; @@ -295,6 +302,7 @@ union obj { struct bignum bn; struct flonum fl; struct range rn; + struct buf b; }; #if CONFIG_GEN_GC @@ -426,7 +434,7 @@ extern val null_s, t, cons_s, str_s, chr_s, fixnum_sl; extern val sym_s, pkg_s, fun_s, vec_s; extern val stream_s, hash_s, hash_iter_s, lcons_s, lstr_s, cobj_s, cptr_s; extern val atom_s, integer_s, number_s, sequence_s, string_s; -extern val env_s, bignum_s, float_s, range_s, rcons_s; +extern val env_s, bignum_s, float_s, range_s, rcons_s, buf_s; extern val var_s, expr_s, regex_s, chset_s, set_s, cset_s, wild_s, oneplus_s; extern val nongreedy_s; extern val quote_s, qquote_s, unquote_s, splice_s; -- cgit v1.2.3