Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jacereda committed Mar 19, 2018
1 parent 5ff3350 commit 807f009
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 99 deletions.
32 changes: 0 additions & 32 deletions rts/idris_bitstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,6 @@

#include "idris_rts.h"

VAL idris_b8CopyForGC(VM *vm, VAL a) {
uint8_t A = GETBITS8(a);
VAL cl = allocate(sizeof(Closure), 1);
SETTY(cl, CT_BITS8);
cl->info.bits8 = A;
return cl;
}

VAL idris_b16CopyForGC(VM *vm, VAL a) {
uint16_t A = GETBITS16(a);
VAL cl = allocate(sizeof(Closure), 1);
SETTY(cl, CT_BITS16);
cl->info.bits16 = A;
return cl;
}

VAL idris_b32CopyForGC(VM *vm, VAL a) {
uint32_t A = GETBITS32(a);
VAL cl = allocate(sizeof(Closure), 1);
SETTY(cl, CT_BITS32);
cl->info.bits32 = A;
return cl;
}

VAL idris_b64CopyForGC(VM *vm, VAL a) {
uint64_t A = GETBITS64(a);
VAL cl = allocate(sizeof(Closure), 1);
SETTY(cl, CT_BITS64);
cl->info.bits64 = A;
return cl;
}

VAL idris_b8(VM *vm, VAL a) {
uint8_t A = GETINT(a);
VAL cl = allocate(sizeof(Closure), 0);
Expand Down
5 changes: 0 additions & 5 deletions rts/idris_bitstring.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#ifndef _IDRISBITSTRING_H
#define _IDRISBITSTRING_H

VAL idris_b8CopyForGC(VM *vm, VAL a);
VAL idris_b16CopyForGC(VM *vm, VAL a);
VAL idris_b32CopyForGC(VM *vm, VAL a);
VAL idris_b64CopyForGC(VM *vm, VAL a);

VAL idris_b8(VM *vm, VAL a);
VAL idris_b16(VM *vm, VAL a);
VAL idris_b32(VM *vm, VAL a);
Expand Down
51 changes: 12 additions & 39 deletions rts/idris_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,39 @@ VAL copy(VM* vm, VAL x) {
return x;
}
switch(GETTY(x)) {
case CT_FWD:
return GETPTR(x);
case CT_CDATA:
cl = MKCDATAc(vm, GETCDATA(x));
c_heap_mark_item(GETCDATA(x));
break;
case CT_BIGINT:
cl = MKBIGMc(vm, GETPTR(x));
break;
case CT_CON:
ar = CARITY(x);
if (ar == 0 && CTAG(x) < 256) {
return x;
} else {
allocCon(cl, vm, CTAG(x), ar, 1);
memcpy(cl->extra.cargs, x->extra.cargs, sizeof(VAL)*ar);
}
break;
// FALLTHROUGH
case CT_ARRAY:
len = CELEM(x);
allocArray(cl, vm, len, 1);
memcpy(cl->extra.array, x->extra.array, len * sizeof(VAL));
break;
case CT_FLOAT:
cl = MKFLOATc(vm, GETFLOAT(x));
break;
case CT_STRING:
cl = MKSTRclen(vm, getstr(x), getstrlen(x));
break;
case CT_REF:
case CT_FLOAT:
case CT_STROFFSET:
cl = MKSTROFFc(vm, x->extra.basestr[0]);
break;
case CT_BIGINT:
cl = MKBIGMc(vm, GETPTR(x));
break;
case CT_PTR:
cl = MKPTRc(vm, GETPTR(x));
break;
case CT_MANAGEDPTR:
cl = MKMPTRc(vm, x->extra.mptr, x->extrasz);
break;
case CT_BITS8:
cl = idris_b8CopyForGC(vm, x);
break;
case CT_BITS16:
cl = idris_b16CopyForGC(vm, x);
break;
case CT_BITS32:
cl = idris_b32CopyForGC(vm, x);
break;
case CT_BITS64:
cl = idris_b64CopyForGC(vm, x);
break;
case CT_REF:
cl = idris_newRefLock((VAL)(GETPTR(x)), 1);
break;
case CT_FWD:
return GETPTR(x);
case CT_RAWDATA:
{
size_t size = sizeof(Closure) + x->extrasz;
cl = allocate(size, 1);
memcpy(cl, x, size);
}
break;
case CT_CDATA:
cl = MKCDATAc(vm, GETCDATA(x));
c_heap_mark_item(GETCDATA(x));
break;
default:
break;
}
Expand Down
30 changes: 7 additions & 23 deletions rts/idris_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,12 @@ static VAL doCopyTo(VM* vm, VAL x) {
return x;
}
switch(GETTY(x)) {
case CT_CDATA:
cl = MKCDATAc(vm, GETCDATA(x));
break;
case CT_BIGINT:
cl = MKBIGMc(vm, GETPTR(x));
break;
case CT_CON:
ar = CARITY(x);
if (ar == 0 && CTAG(x) < 256) { // globally allocated
Expand All @@ -867,36 +873,14 @@ static VAL doCopyTo(VM* vm, VAL x) {
allocArray(cl, vm, len, 1);
copyArray(vm, cl->extra.array, x->extra.array, len);
break;
case CT_FLOAT:
cl = MKFLOATc(vm, GETFLOAT(x));
break;
case CT_STRING:
cl = MKSTRclen(vm, x->extra.str, getstrlen(x));
break;
case CT_BIGINT:
cl = MKBIGMc(vm, GETPTR(x));
break;
case CT_FLOAT:
case CT_PTR:
cl = MKPTRc(vm, GETPTR(x));
break;
case CT_MANAGEDPTR:
cl = MKMPTRc(vm, x->extra.mptr, x->extrasz);
break;
case CT_CDATA:
cl = MKCDATAc(vm, GETCDATA(x));
break;
case CT_BITS8:
cl = idris_b8CopyForGC(vm, x);
break;
case CT_BITS16:
cl = idris_b16CopyForGC(vm, x);
break;
case CT_BITS32:
cl = idris_b32CopyForGC(vm, x);
break;
case CT_BITS64:
cl = idris_b64CopyForGC(vm, x);
break;
case CT_RAWDATA:
{
size_t size = sizeof(Closure) + x->extrasz;
Expand Down

0 comments on commit 807f009

Please sign in to comment.