beginnings of REPL
[muddle-interpreter.git] / src / alloc.c
1 /*
2 Copyright (C) 2017 Keziah Wesley
3
4 You can redistribute and/or modify this file under the terms of the
5 GNU Affero General Public License as published by the Free Software
6 Foundation, either version 3 of the License, or (at your option) any
7 later version.
8
9 This file is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Affero General Public License for more details.
13
14 You should have received a copy of the GNU Affero General Public
15 License along with this file. If not, see
16 <http://www.gnu.org/licenses/>.
17 */
18
19 #include "alloc.h"
20 #include "object.h"
21
22 pool_ptr
23 pool_copy_array_rev (const pool_object * objs, uint32_t len)
24 {
25   if (!len)
26     return 0;
27   pool_object *xs = pool_alloc (len);
28   for (int i = 0; i < (int) len; i++)
29     {
30       xs[i].type = objs[len - 1 - (unsigned) i].type;
31       xs[i].rest = POOL_PTR (&xs[i + 1]);
32       xs[i].val = objs[len - 1 - (unsigned) i].val;
33     }
34   xs[len - 1].rest = 0;
35   return POOL_PTR (xs);
36 }
37
38 heap_ptr
39 heap_copy_array_rev (const object * objs, uint32_t len)
40 {
41   object *xs = heap_alloc (len);
42   for (int i = 0; i < (int) len; i++)
43     {
44       xs[i] = objs[len - 1 - (unsigned) i];
45     }
46   return HEAP_PTR_OF_OBJECT (xs);
47 }