Mercurial > repos > rhope
comparison runtime/array.c @ 49:3e20ed8959c4
Added initial FFI implementation, Array type and 64-bit integers
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 08 Apr 2010 01:02:18 -0400 |
parents | d61550e2c001 |
children | 70af7fa155d0 |
comparison
equal
deleted
inserted
replaced
48:a24eb366195c | 49:3e20ed8959c4 |
---|---|
1 #include "array.h" | |
2 #include "integer.h" | 1 #include "integer.h" |
2 #include "object.h" | |
3 | 3 |
4 Func(Array,0, | 4 void _internal_array_copyout(object * array, int32_t index, object * dest) |
5 ;) | 5 { |
6 Ret(0, new_object(TYPE_ARRAY)) | 6 t_Array * arr = (t_Array *)array; |
7 Return | 7 memcpy(((char *)dest) + sizeof(object), ((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, get_blueprint(dest)->size); |
8 EndFunc | 8 } |
9 | 9 |
10 Method(Index,Array,2, | 10 void _internal_array_copyin(object * array, int32_t index, object * val) |
11 _t_Int32 * idx;) | 11 { |
12 Param(1,idx,Int32) | 12 t_Array * arr = (t_Array *)array; |
13 if (idx->num < 0 || idx->num >= me->numels) { | 13 memcpy(((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, ((char *)val) + sizeof(object), arr->payload.Eltype->bp->size); |
14 Ret(0, NULL) | 14 } |
15 Ret(1, me) | |
16 } else { | |
17 Ret(1, NULL) | |
18 if (me->contents_type) { | |
19 Ret(0, copy_from_raw(me->conents_type, (char *)me + sizeof(*me) + (idx->num * sizeof(object *)))) | |
20 } else { | |
21 Ret(0, add_ref((object *)((char *)me + sizeof(*me) + (idx->num * sizeof(object *))))) | |
22 } | |
23 release_ref(me); | |
24 } | |
25 EndFunc | |
26 | 15 |
16 object * _internal_array_getboxed(object * array, int32_t index) | |
17 { | |
18 object * ret; | |
19 object ** intarr = (object *)(((char *) array) + sizeof(t_Array)); | |
20 ret = add_ref(intarr[index]); | |
21 release_ref(array); | |
22 return ret; | |
23 } | |
24 | |
25 void _internal_array_setboxed(object *array, int32_t index, object * val) | |
26 { | |
27 object ** intarr = (object *)(((char *) array) + sizeof(t_Array)); | |
28 intarr[index] = val; | |
29 } | |
30 | |
31 object *_internal_array_allocboxed(int32_t size) | |
32 { | |
33 t_Array * ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+sizeof(object *)*size); | |
34 ret->payload.Length = 0; | |
35 ret->payload.Storage = size; | |
36 ret->payload.Eltype = (t_Blueprint *)make_Blueprint(0); | |
37 | |
38 return ret; | |
39 } | |
40 | |
41 object * _internal_array_allocnaked(int32_t size , object * type) | |
42 { | |
43 t_Array * ret; | |
44 t_Blueprint * bp = (t_Blueprint *)type; | |
45 if (bp->bp->size < 0) { | |
46 return _internal_array_allocboxed(size); | |
47 } | |
48 ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+bp->bp->size*size); | |
49 ret->payload.Length = 0; | |
50 ret->payload.Storage = size; | |
51 ret->payload.Eltype = bp; | |
52 | |
53 return ret; | |
54 } | |
55 |