From: Kaz Wesley Date: Sat, 10 Feb 2018 02:14:06 +0000 (-0800) Subject: Implement pool_copy_array X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=6329da4e468e5429ad2d56eb274edaac72704cab;p=muddle-interpreter.git Implement pool_copy_array Forwards version of pool_copy_array_rev. Signed-off-by: Kaz Wesley --- diff --git a/src/alloc.c b/src/alloc.c index 356a038..ccd9691 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -42,6 +42,22 @@ POOL_OBJECT (pool_ptr p) return &pool[p]; } +pool_ptr +pool_copy_array (const pool_object * objs, uint32_t len) +{ + if (!len) + return 0; + pool_ptr p = pool_alloc (len); + for (int i = 0; i < len; i++) + { + pool[p + i] = (pool_object) + { + .type = objs[i].type,.rest = p + i + 1,.val = objs[i].val}; + } + pool[p + len - 1].rest = 0; + return p; +} + pool_ptr pool_copy_array_rev (const pool_object * objs, uint32_t len) { diff --git a/src/alloc.h b/src/alloc.h index bd7c46b..89e1dab 100644 --- a/src/alloc.h +++ b/src/alloc.h @@ -44,7 +44,9 @@ heap_alloc_uv (uint32_t len) } // given a headerless array of objects of known size, -// copy it backwards into newly-allocated pool space +// copy it into newly-allocated pool space +pool_ptr pool_copy_array (const pool_object * objs, uint32_t len); +// same as above, but backwards pool_ptr pool_copy_array_rev (const pool_object * objs, uint32_t len); heap_ptr heap_copy_array_rev (const object * objs, uint32_t len);