X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=src%2Falloc.c;fp=src%2Falloc.c;h=7209060bf612d300620c0679c9274da596496acf;hb=8d55156675587a770c5654362bcbd3d2a98e4aa9;hp=0000000000000000000000000000000000000000;hpb=d6e1960007fcac962144382332f7a9c8c56fa3a1;p=muddle-interpreter.git diff --git a/src/alloc.c b/src/alloc.c new file mode 100644 index 0000000..7209060 --- /dev/null +++ b/src/alloc.c @@ -0,0 +1,47 @@ +/* +Copyright (C) 2017 Keziah Wesley + +You can redistribute and/or modify this file under the terms of the +GNU Affero General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any +later version. + +This file is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public +License along with this file. If not, see +. +*/ + +#include "alloc.h" +#include "object.h" + +pool_ptr +pool_copy_array_rev (const pool_object * objs, uint32_t len) +{ + if (!len) + return 0; + pool_object *xs = pool_alloc (len); + for (int i = 0; i < (int) len; i++) + { + xs[i].type = objs[len - 1 - (unsigned) i].type; + xs[i].rest = POOL_PTR (&xs[i + 1]); + xs[i].val = objs[len - 1 - (unsigned) i].val; + } + xs[len - 1].rest = 0; + return POOL_PTR (xs); +} + +heap_ptr +heap_copy_array_rev (const object * objs, uint32_t len) +{ + object *xs = heap_alloc (len); + for (int i = 0; i < (int) len; i++) + { + xs[i] = objs[len - 1 - (unsigned) i]; + } + return HEAP_PTR_OF_OBJECT (xs); +}