diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | eval.c | 1 | ||||
-rw-r--r-- | lib.c | 30 | ||||
-rw-r--r-- | lib.h | 1 | ||||
-rw-r--r-- | txr.1 | 2 |
5 files changed, 44 insertions, 0 deletions
@@ -1,5 +1,15 @@ 2011-12-20 Kaz Kylheku <kaz@kylheku.com> + * eval.c (eval_init): New function registered. + + * lib.c (cat_vec): New function. + + * lib.h (cat_vec): Declared. + + * txr.1: Documentation stub. + +2011-12-20 Kaz Kylheku <kaz@kylheku.com> + Bug #35137 * unwind.c (uw_unwind_to_exit_point): When jumping to a catch frame, @@ -1387,6 +1387,7 @@ void eval_init(void) reg_fun(intern(lit("list-vector"), user_package), func_n1(list_vector)); reg_fun(intern(lit("copy-vec"), user_package), func_n1(copy_vec)); reg_fun(intern(lit("sub-vec"), user_package), func_n3(sub_vec)); + reg_fun(intern(lit("cat-vec"), user_package), func_n1(cat_vec)); reg_fun(intern(lit("assoc"), user_package), func_n2(assoc)); reg_fun(intern(lit("assq"), user_package), func_n2(assq)); @@ -2453,6 +2453,36 @@ val sub_vec(val vec_in, val from, val to) } } +val cat_vec(val list) +{ + cnum total = 0; + val iter; + val vec, *v; + + for (iter = list; iter != nil; iter = cdr(iter)) + total += c_num(length_vec(car(iter))); + + vec = make_obj(); + v = (val *) chk_malloc((total + 2) * sizeof *v); + +#ifdef HAVE_VALGRIND + vec->v.vec_true_start = v; +#endif + v += 2; + vec->v.type = VEC; + vec->v.vec = v; + v[vec_length] = v[vec_alloc] = num(total); + + for (iter = list; iter != nil; iter = cdr(iter)) { + val item = car(iter); + cnum len = c_num(item->v.vec[vec_length]); + memcpy(v, item->v.vec, len * sizeof *v); + v += len; + } + + return vec; +} + static val lazy_stream_func(val env, val lcons) { val stream = car(env); @@ -505,6 +505,7 @@ val vector_list(val list); val list_vector(val vector); val copy_vec(val vec); val sub_vec(val vec_in, val from, val to); +val cat_vec(val list); val lazy_stream_cons(val stream); val lazy_str(val list, val term, val limit); val lazy_str_force_upto(val lstr, val index); @@ -5668,6 +5668,8 @@ yields (1 2 3 4 5). In TXR Lisp, this usage can be simulated using .SS Function sub-vec +.SS Function cat-vec + .SS Function assoc .SS Function assq |