4 #include "shotgun/lib/shotgun.h"
5 #include "shotgun/lib/object.h"
6 #include "shotgun/lib/bytearray.h"
8 OBJECT
bytearray_new(STATE
, unsigned int size
) {
12 words
= size
/ SIZE_OF_OBJECT
;
13 if(size
% SIZE_OF_OBJECT
!= 0) {
17 obj
= bytearray_allocate_with_extra(state
, words
);
18 object_make_byte_storage(state
, obj
);
19 fast_memfill(BYTES_OF(obj
), 0, words
);
20 object_initialize_bytes(state
, obj
);
24 OBJECT
bytearray_new_dirty(STATE
, unsigned int size
) {
28 words
= size
/ SIZE_OF_OBJECT
;
29 if(size
% SIZE_OF_OBJECT
!= 0) {
33 obj
= object_memory_new_dirty_object(state
->om
, BASIC_CLASS(bytearray
), words
);
34 object_make_byte_storage(state
, obj
);
39 OBJECT
bytearray_dup(STATE
, OBJECT self
) {
41 int words
= NUM_FIELDS(self
);
43 obj
= object_memory_new_dirty_object(state
->om
, BASIC_CLASS(bytearray
), words
);
44 object_make_byte_storage(state
, obj
);
46 object_copy_body(state
, self
, obj
);
51 char *bytearray_as_string(STATE
, OBJECT self
) {
56 str
= (char*)bytearray_byte_address(state
, self
);
58 sz
= object_size(state
, self
);
59 out
= ALLOC_N(char, sz
);
65 OBJECT
iseq_new(STATE
, unsigned int sz
) {
69 fields
= sz
/ SIZE_OF_OBJECT
;
70 if(sz
% SIZE_OF_OBJECT
!= 0) {
73 obj
= NEW_OBJECT(state
->global
->iseq
, fields
);
74 object_make_byte_storage(state
, obj
);
79 static inline uint32_t read_int_from_be(uint8_t *str
) {
80 return (uint32_t)((str
[0] << 24)
86 void iseq_flip(STATE
, OBJECT self
, OBJECT output
) {
92 f
= object_size(state
, self
);
93 buf
= (uint8_t*)bytearray_byte_address(state
, self
);
94 ibuf
= (uint32_t*)bytearray_byte_address(state
, output
);
96 /* A sanity check. The first thing is always an instruction,
97 * and we've got less that 1024 instructions, so if it's less
98 * it's already been flipped. */
99 if(*(uint32_t*)buf
< 1024) return;
101 for(i
= 0; i
< f
; i
+= 4, ibuf
++) {
102 val
= read_int_from_be(buf
+ i
);