sys: make_list constructor
Takes a fixed array of lisp_t pointers, and makes a cons list out of them.
This commit is contained in:
@@ -30,6 +30,7 @@ u64 sys_cost(sys_t *);
|
|||||||
lisp_t *make_int(i64);
|
lisp_t *make_int(i64);
|
||||||
lisp_t *intern(sys_t *, sv_t);
|
lisp_t *intern(sys_t *, sv_t);
|
||||||
lisp_t *cons(sys_t *, lisp_t *, lisp_t *);
|
lisp_t *cons(sys_t *, lisp_t *, lisp_t *);
|
||||||
|
lisp_t *make_list(sys_t *, lisp_t **, u64);
|
||||||
lisp_t *make_vec(sys_t *, u64);
|
lisp_t *make_vec(sys_t *, u64);
|
||||||
lisp_t *make_str(sys_t *, u64);
|
lisp_t *make_str(sys_t *, u64);
|
||||||
|
|
||||||
|
|||||||
11
src/sys.c
11
src/sys.c
@@ -59,6 +59,17 @@ lisp_t *cons(sys_t *sys, lisp_t *car, lisp_t *cdr)
|
|||||||
return cons;
|
return cons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lisp_t *make_list(sys_t *sys, lisp_t **lisps, u64 size)
|
||||||
|
{
|
||||||
|
lisp_t *root = NIL;
|
||||||
|
for (u64 i = size; i > 0; --i)
|
||||||
|
{
|
||||||
|
lisp_t *node = lisps[i - 1];
|
||||||
|
root = cons(sys, node, root);
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
lisp_t *make_vec(sys_t *sys, u64 capacity)
|
lisp_t *make_vec(sys_t *sys, u64 capacity)
|
||||||
{
|
{
|
||||||
lisp_t *vec = sys_alloc(sys, TAG_VEC);
|
lisp_t *vec = sys_alloc(sys, TAG_VEC);
|
||||||
|
|||||||
Reference in New Issue
Block a user