Mercurial > repos > rhope
view runtime/array.c @ 180:c40e0faa1c92
Add Call to Dict and List
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 19 Jun 2011 10:43:11 -0700 |
parents | 72c648bca43b |
children |
line wrap: on
line source
#include "integer.h" #include "object.h" #include <stdio.h> 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); get_blueprint(dest)->copy(dest); release_ref(array); } void _internal_array_copyin(object * array, int32_t index, object * val) { char *dest; t_Array * arr = (t_Array *)array; t_Blueprint * bp = arr->payload.Eltype; if(bp->bp->type_id >= TYPE_ARRAY && index < arr->payload.Length) { //Ugly hack dest = ((char *)(arr+1))-sizeof(object) + bp->bp->size * index; bp->bp->cleanup((object *)dest); } memcpy(((char *)array) + sizeof(t_Array) + arr->payload.Eltype->bp->size * index, ((char *)val) + sizeof(object), arr->payload.Eltype->bp->size); get_blueprint(val)->copy(val); release_ref(val); } void _internal_array_copychunk(object * src, int32_t srcidx, object * dest, int32_t destidx, int32_t len) { int32_t idx; object * cur; t_Array *sarr,*darr; sarr = (t_Array *)src; darr = (t_Array *)dest; memcpy((char *)(darr+1) + darr->payload.Eltype->bp->size * destidx, (char *)(sarr+1) + sarr->payload.Eltype->bp->size * srcidx, len*sarr->payload.Eltype->bp->size); cur = (object *)((char *)(darr+1) + darr->payload.Eltype->bp->size * destidx - sizeof(object)); for (idx = 0; idx < len; ++idx) { darr->payload.Eltype->bp->copy(cur); cur++; } release_ref(src); } object * _internal_array_getboxed(object * array, int32_t index) { object * ret; object ** intarr = (object **)(((char *) array) + sizeof(t_BoxedSP_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_BoxedSP_Array)); if (index < ((t_BoxedSP_Array *)array)->payload.Length) { release_ref(intarr[index]); } intarr[index] = val; } object *_internal_array_allocboxed(int32_t size) { t_BoxedSP_Array * ret = (t_BoxedSP_Array *)new_multisize(TYPE_BOXEDARRAY, sizeof(nt_BoxedSP_Array)+sizeof(object *)*size); ret->payload.Length = 0; ret->payload.Storage = size; return (object *)ret; } object *_internal_array_allocboxedcopy(object * osource, int32_t size) { int32_t tocopy,idx; object **srcarr, **destarr; t_BoxedSP_Array * source = (t_BoxedSP_Array *)osource; t_BoxedSP_Array * ret = (t_BoxedSP_Array *)new_multisize(TYPE_BOXEDARRAY, sizeof(nt_BoxedSP_Array)+sizeof(object *)*size); ret->payload.Length = 0; ret->payload.Storage = size; tocopy = size < source->payload.Length ? size : source->payload.Length; srcarr = (object **)(source+1); destarr = (object **)(ret+1); for(idx = 0; idx < tocopy; ++idx) destarr[idx] = add_ref(srcarr[idx]); release_ref(osource); 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) { release_ref(type); 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 (object *)ret; } object * _internal_array_allocnakedcopy(object * osource, int32_t size) { int32_t tocopy,idx; char *cur; t_Array * ret, *source = (t_Array *)osource; t_Blueprint * bp = source->payload.Eltype; 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; add_ref((object *)bp); tocopy = size < source->payload.Length ? size : source->payload.Length; memcpy(ret+1, source+1, tocopy*bp->bp->size); if(bp->bp->type_id >= TYPE_ARRAY) { //Ugly hack cur = ((char *)(ret+1))-sizeof(object) ; for(idx=0; idx < tocopy; ++idx) { bp->bp->copy((object *)cur); cur += bp->bp->size; } } release_ref(osource); return (object *)ret; } void internalarrayboxedcopy(object * obj) { int32_t idx; object **elarr; t_BoxedSP_Array * arr = (t_BoxedSP_Array *)obj; elarr = (object **)(arr+1); for(idx = 0; idx < arr->payload.Length; ++idx) { add_ref(elarr[idx]); } } void internalarraynakedcopy(object * obj) { int32_t tocopy,idx; char *cur; t_Array *arr = (t_Array *)obj; t_Blueprint * bp = arr->payload.Eltype; //Lower type IDs don't have any reference params so we can safely skip this for those if(bp->bp->type_id >= TYPE_ARRAY) { //Ugly hack cur = ((char *)(arr+1))-sizeof(object) ; for(idx=0; idx < arr->payload.Length; ++idx) { bp->bp->copy((object *)cur); cur += bp->bp->size; } } add_ref((object *)bp); } void internalarrayboxedcleanup(object * obj) { int32_t idx; object **elarr; t_BoxedSP_Array * arr = (t_BoxedSP_Array *)obj; elarr = (object **)(arr+1); for(idx = 0; idx < arr->payload.Length; ++idx) { release_ref(elarr[idx]); } } void internalarraynakedcleanup(object * obj) { int32_t tocopy,idx; char *cur; t_Array *arr = (t_Array *)obj; t_Blueprint * bp = arr->payload.Eltype; //Lower type IDs don't have any reference params so we can safely skip this for those if(bp->bp->type_id >= TYPE_ARRAY) { //Ugly hack cur = ((char *)(arr+1))-sizeof(object) ; for(idx=0; idx < arr->payload.Length; ++idx) { bp->bp->cleanup((object *)cur); cur += bp->bp->size; } } release_ref((object *)bp); } int32_t _internal_memcmp_offset(void * left, int32_t loff, void * right, int32_t roff, int32_t len) { return memcmp(((char *)left)+loff, ((char *)right)+roff, len); }