From 611b273dcdb4e3d18b1205de6d7d5d6c297c2f06 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 30 Oct 2013 10:12:04 +0900 Subject: [PATCH] missed to add src/vector.c --- src/vector.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/vector.c diff --git a/src/vector.c b/src/vector.c new file mode 100644 index 00000000..0160775f --- /dev/null +++ b/src/vector.c @@ -0,0 +1,29 @@ +#include "picrin.h" +#include "picrin/pair.h" + +struct pic_vector * +pic_vec_new(pic_state *pic, size_t len) +{ + struct pic_vector *vec; + + vec = (struct pic_vector *)pic_obj_alloc(pic, sizeof(struct pic_vector), PIC_TT_VECTOR); + vec->len = len; + vec->data = (pic_value *)pic_alloc(pic, sizeof(pic_value) * len); + return vec; +} + +struct pic_vector * +pic_vec_new_from_list(pic_state *pic, pic_value data) +{ + struct pic_vector *vec; + int i, len; + + len = pic_length(pic, data); + + vec = pic_vec_new(pic, len); + for (i = 0; i < len; ++i) { + vec->data[i] = pic_car(pic, data); + data = pic_cdr(pic, data); + } + return vec; +}