Add a new Closure type for raw data and have that be allocated

with idris_alloc.
This commit is contained in:
Niklas Larsson 2015-04-10 10:12:31 +02:00
parent 68d844cdf8
commit 610387c171
3 changed files with 20 additions and 2 deletions

View File

@ -53,6 +53,13 @@ VAL copy(VM* vm, VAL x) {
break;
case FWD:
return x->info.ptr;
case RAWDATA:
{
size_t size = x->info.size + sizeof(Closure);
cl = allocate(size, 0);
memcpy(cl, x, size);
}
break;
default:
break;
}

View File

@ -143,7 +143,10 @@ int space(VM* vm, size_t size) {
}
void* idris_alloc(size_t size) {
return allocate(size, 0);
Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
SETTY(cl, RAWDATA);
cl->info.size = size;
return (void*)cl+sizeof(Closure);
}
void* idris_realloc(void* old, size_t old_size, size_t size) {
@ -712,6 +715,13 @@ VAL doCopyTo(VM* vm, VAL x) {
case BITS64:
cl = idris_b64CopyForGC(vm, x);
break;
case RAWDATA:
{
size_t size = x->info.size + sizeof(Closure);
cl = allocate(size, 0);
memcpy(cl, x, size);
}
break;
default:
assert(0); // We're in trouble if this happens...
}

View File

@ -26,7 +26,7 @@
typedef enum {
CON, INT, BIGINT, FLOAT, STRING, STROFFSET,
BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD,
MANAGEDPTR
MANAGEDPTR, RAWDATA
} ClosureType;
typedef struct Closure *VAL;
@ -76,6 +76,7 @@ typedef struct Closure {
__m128i* bits128p;
Buffer* buf;
ManagedPtr* mptr;
size_t size;
} info;
} Closure;