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
24 #include "st-word-array.h"
25 #include "st-universe.h"
27 #include "st-descriptor.h"
30 allocate_arrayed (st_space
*space
, st_oop
class, st_smi size
)
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
++)
51 word_array_copy (st_oop object
)
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
);
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
)));
75 word_array_contents (st_oop object
, struct contents
*contents
)
77 contents
->oops
= NULL
;
82 st_word_array_descriptor (void)
84 static st_descriptor __descriptor
=
86 .allocate_arrayed
= allocate_arrayed
,
87 .copy
= word_array_copy
,
88 .size
= word_array_size
,
89 .contents
= word_array_contents
,
91 return & __descriptor
;