Permalink
Browse files

Fix allocation size

  • Loading branch information...
1 parent f2766a6 commit 13e17a41b44713c459a0f5e1b5cc6ba278334e12 Edwin Brady committed Sep 6, 2012
Showing with 15 additions and 17 deletions.
  1. +1 −1 Makefile
  2. +1 −1 rts/idris_gmp.c
  3. +13 −15 rts/idris_rts.c
View
@@ -19,7 +19,7 @@ relib: .PHONY
make -C lib IDRIS=../dist/build/idris/idris
linecount : .PHONY
- wc -l src/Idris/*.hs src/Core/*.hs src/RTS/*.hs
+ wc -l src/Idris/*.hs src/Core/*.hs src/IRTS/*.hs
.PHONY:
View
@@ -196,7 +196,7 @@ VAL idris_bigLt(VM* vm, VAL x, VAL y) {
VAL idris_bigLe(VM* vm, VAL x, VAL y) {
if (ISINT(x) && ISINT(y)) {
- return MKINT((i_int)GETINT(x) <= GETINT(y));
+ return MKINT((i_int)(GETINT(x) <= GETINT(y)));
} else {
return bigLe(vm, x, y);
}
View
@@ -50,36 +50,35 @@ void* allocate(VM* vm, size_t size) {
}
void* allocCon(VM* vm, int arity) {
- Closure* cl = allocate(vm, sizeof(ClosureType) +
- sizeof(con) + sizeof(VAL)*arity);
+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(VAL)*arity);
cl -> ty = CON;
if (arity == 0) {
cl -> info.c.args = NULL;
} else {
- cl -> info.c.args = (void*)((char*)cl + sizeof(ClosureType)
- + sizeof(con));
+ cl -> info.c.args = (void*)((char*)cl + sizeof(Closure));
}
return (void*)cl;
}
VAL MKFLOAT(VM* vm, double val) {
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(double));
+ Closure* cl = allocate(vm, sizeof(Closure));
cl -> ty = FLOAT;
cl -> info.f = val;
return cl;
}
VAL MKSTR(VM* vm, char* str) {
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
+ Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
sizeof(char)*strlen(str)+1);
cl -> ty = STRING;
- cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
+ cl -> info.str = (char*)cl + sizeof(Closure);
+
strcpy(cl -> info.str, str);
return cl;
}
VAL MKPTR(VM* vm, void* ptr) {
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(void*));
+ Closure* cl = allocate(vm, sizeof(Closure));
cl -> ty = PTR;
cl -> info.ptr = ptr;
return cl;
@@ -138,9 +137,9 @@ void dumpVal(VAL v) {
}
VAL idris_castIntStr(VM* vm, VAL i) {
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) + sizeof(char)*16);
+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*16);
cl -> ty = STRING;
- cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
+ cl -> info.str = (char*)cl + sizeof(Closure);
sprintf(cl -> info.str, "%ld", GETINT(i));
return cl;
}
@@ -152,9 +151,9 @@ VAL idris_castStrInt(VM* vm, VAL i) {
}
VAL idris_castFloatStr(VM* vm, VAL i) {
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) + sizeof(char)*32);
+ Closure* cl = allocate(vm, sizeof(Closure) + sizeof(char)*32);
cl -> ty = STRING;
- cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
+ cl -> info.str = (char*)cl + sizeof(Closure);
sprintf(cl -> info.str, "%g", GETFLOAT(i));
return cl;
}
@@ -166,15 +165,14 @@ VAL idris_castStrFloat(VM* vm, VAL i) {
VAL idris_concat(VM* vm, VAL l, VAL r) {
char *ls = GETSTR(l);
char *rs = GETSTR(r);
- Closure* cl = allocate(vm, sizeof(ClosureType) + sizeof(char*) +
- strlen(ls) + strlen(rs) + 1);
+ Closure* cl = allocate(vm, sizeof(Closure) + strlen(ls) + strlen(rs) + 1);
// Oops! problem if the second allocate triggers a gc because cl has
// to be a root. Fix by allocating all in one go.
// Also note that l/r may be in from space, so don't delete after collection,
// rather, delete just before the next collection.
cl -> ty = STRING;
- cl -> info.str = (char*)cl + sizeof(ClosureType) + sizeof(char*);
+ cl -> info.str = (char*)cl + sizeof(Closure);
strcpy(cl -> info.str, ls);
strcat(cl -> info.str, rs);
return cl;

0 comments on commit 13e17a4

Please sign in to comment.