Mercurial > repos > rhope
diff runtime/array.c @ 63:04baa003de5a
Merged latest changes with better C branch
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 05 May 2010 22:12:23 -0400 |
parents | 70af7fa155d0 |
children | 4d5ea487f810 |
line wrap: on
line diff
--- a/runtime/array.c Sat Oct 10 16:43:37 2009 -0400 +++ b/runtime/array.c Wed May 05 22:12:23 2010 -0400 @@ -1,26 +1,55 @@ -#include "array.h" -#include "integer.h" - -Func(Array,0, - ;) - Ret(0, new_object(TYPE_ARRAY)) - Return -EndFunc +#include "integer.h" +#include "object.h" -Method(Index,Array,2, - _t_Int32 * idx;) - Param(1,idx,Int32) - if (idx->num < 0 || idx->num >= me->numels) { - Ret(0, NULL) - Ret(1, me) - } else { - Ret(1, NULL) - if (me->contents_type) { - Ret(0, copy_from_raw(me->conents_type, (char *)me + sizeof(*me) + (idx->num * sizeof(object *)))) - } else { - Ret(0, add_ref((object *)((char *)me + sizeof(*me) + (idx->num * sizeof(object *))))) - } - release_ref(me); - } -EndFunc +void _internal_array_copyout(object * array, int32_t index, object * dest) +{ + t_Array * arr = (t_Array *)array; + memcpy(((char *)dest) + sizeof(object), ((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, get_blueprint(dest)->size); +} + +void _internal_array_copyin(object * array, int32_t index, object * val) +{ + t_Array * arr = (t_Array *)array; + memcpy(((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, ((char *)val) + sizeof(object), arr->payload.Eltype->bp->size); +} + +object * _internal_array_getboxed(object * array, int32_t index) +{ + object * ret; + object ** intarr = (object **)(((char *) array) + sizeof(t_Array)); + ret = add_ref(intarr[index]); + release_ref(array); + return ret; +} + +void _internal_array_setboxed(object *array, int32_t index, object * val) +{ + object ** intarr = (object **)(((char *) array) + sizeof(t_Array)); + intarr[index] = val; +} + +object *_internal_array_allocboxed(int32_t size) +{ + t_Array * ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+sizeof(object *)*size); + ret->payload.Length = 0; + ret->payload.Storage = size; + ret->payload.Eltype = (t_Blueprint *)make_Blueprint(0); + + return (object *)ret; +} + +object * _internal_array_allocnaked(int32_t size , object * type) +{ + t_Array * ret; + t_Blueprint * bp = (t_Blueprint *)type; + if (bp->bp->size < 0) { + return _internal_array_allocboxed(size); + } + ret = (t_Array *)new_multisize(TYPE_ARRAY, sizeof(nt_Array)+bp->bp->size*size); + ret->payload.Length = 0; + ret->payload.Storage = size; + ret->payload.Eltype = bp; + + return ret; +}