Removed the notion of a "large" context. For simplicity, all contexts
[panda.git] / src / st-word-array.c
blobb78be95a782b29098e1f48ffd351e98bc494eb85
1 /*
2 * st-array.c
4 * Copyright (c) 2008 Vincent Geddes
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
24 #include "st-word-array.h"
25 #include "st-universe.h"
26 #include "st-utils.h"
27 #include "st-descriptor.h"
29 static st_oop
30 allocate_arrayed (st_space *space, st_oop class, st_smi size)
32 st_oop array;
33 st_smi size_oops;
34 st_uint *elements;
36 st_assert (size >= 0);
38 size_oops = size / (sizeof (st_oop) / sizeof (st_uint));
40 array = st_space_allocate_object (space, class, ST_SIZE_OOPS (struct st_word_array) + size_oops);
42 ST_ARRAYED_OBJECT (array)->size = st_smi_new (size);
43 elements = st_word_array_elements (array);
44 for (st_smi i = 0; i < size; i++)
45 elements[i] = 0;
47 return array;
50 static st_oop
51 word_array_copy (st_oop object)
53 st_oop copy;
54 st_smi size;
56 size = st_smi_value (st_arrayed_object_size (object));
58 copy = allocate_arrayed (memory->moving_space, st_object_class (object), size);
60 memcpy (st_word_array_elements (copy),
61 st_word_array_elements (object),
62 sizeof (st_uint) * size);
64 return copy;
67 static st_uint
68 word_array_size (st_oop object)
70 return ST_SIZE_OOPS (struct st_arrayed_object)
71 + (st_smi_value (st_arrayed_object_size (object)) / (sizeof (st_oop) / sizeof (st_uint)));
74 static void
75 word_array_contents (st_oop object, struct contents *contents)
77 contents->oops = NULL;
78 contents->size = 0;
81 st_descriptor *
82 st_word_array_descriptor (void)
84 static st_descriptor __descriptor =
85 { .allocate = NULL,
86 .allocate_arrayed = allocate_arrayed,
87 .copy = word_array_copy,
88 .size = word_array_size,
89 .contents = word_array_contents,
91 return & __descriptor;