on master help sign in
Merge pull request #2138 from melted/gc
222612aEdwin Brady
idris.cabal+4
@@ -346,6 +346,10 @@ Extra-source-files:
346 test/basic013/*.idr
346 test/basic013/*.idr
347 test/basic013/expected
347 test/basic013/expected
348
348
349+ test/bignum001/run
350+ test/bignum001/*.idr
351+ test/bignum001/expected
352+
349 test/delab001/*.idr
353 test/delab001/*.idr
350 test/delab001/run
354 test/delab001/run
351 test/delab001/expected
355 test/delab001/expected
rts/idris_gc.c+7
@@ -53,6 +53,13 @@ VAL copy(VM* vm, VAL x) {
53 break;
53 break;
54 case FWD:
54 case FWD:
55 return x->info.ptr;
55 return x->info.ptr;
56+ case RAWDATA:
57+ {
58+ size_t size = x->info.size + sizeof(Closure);
59+ cl = allocate(size, 0);
60+ memcpy(cl, x, size);
61+ }
62+ break;
56 default:
63 default:
57 break;
64 break;
58 }
65 }
rts/idris_rts.c+11−1
@@ -143,7 +143,10 @@ int space(VM* vm, size_t size) {
143}
143}
144
144
145void* idris_alloc(size_t size) {
145void* idris_alloc(size_t size) {
146− return allocate(size, 0);
146+ Closure* cl = (Closure*) allocate(sizeof(Closure)+size, 0);
147+ SETTY(cl, RAWDATA);
148+ cl->info.size = size;
149+ return (void*)cl+sizeof(Closure);
147}
150}
148
151
149void* idris_realloc(void* old, size_t old_size, size_t size) {
152void* idris_realloc(void* old, size_t old_size, size_t size) {
@@ -712,6 +715,13 @@ VAL doCopyTo(VM* vm, VAL x) {
712 case BITS64:
715 case BITS64:
713 cl = idris_b64CopyForGC(vm, x);
716 cl = idris_b64CopyForGC(vm, x);
714 break;
717 break;
718+ case RAWDATA:
719+ {
720+ size_t size = x->info.size + sizeof(Closure);
721+ cl = allocate(size, 0);
722+ memcpy(cl, x, size);
723+ }
724+ break;
715 default:
725 default:
716 assert(0); // We're in trouble if this happens...
726 assert(0); // We're in trouble if this happens...
717 }
727 }
rts/idris_rts.h+2−1
@@ -26,7 +26,7 @@
26typedef enum {
26typedef enum {
27 CON, INT, BIGINT, FLOAT, STRING, STROFFSET,
27 CON, INT, BIGINT, FLOAT, STRING, STROFFSET,
28 BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD,
28 BITS8, BITS16, BITS32, BITS64, UNIT, PTR, FWD,
29− MANAGEDPTR
29+ MANAGEDPTR, RAWDATA
30} ClosureType;
30} ClosureType;
31
31
32typedef struct Closure *VAL;
32typedef struct Closure *VAL;
@@ -76,6 +76,7 @@ typedef struct Closure {
76 __m128i* bits128p;
76 __m128i* bits128p;
77 Buffer* buf;
77 Buffer* buf;
78 ManagedPtr* mptr;
78 ManagedPtr* mptr;
79+ size_t size;
79 } info;
80 } info;
80} Closure;
81} Closure;
81
82
test/README+1
@@ -1,6 +1,7 @@
1Tests are categorised as follows:
1Tests are categorised as follows:
2
2
3basic: Basic language features, some complete programs
3basic: Basic language features, some complete programs
4+bignum: Bignums and GMP
4dsl: Embedded DSLs and features to support DSL development
5dsl: Embedded DSLs and features to support DSL development
5effects: Effects package
6effects: Effects package
6error: Error messages and error reflection
7error: Error messages and error reflection
test/bignum001/bignum001.idrnew file+17
@@ -0,0 +1,17 @@
1+module Main
2+
3+fac : Integer -> Integer
4+fac 0 = 1
5+fac n = n*fac(n-1)
6+
7+binomial : Integer -> Integer -> Integer
8+binomial n k = divBigInt (fac n) ((fac k)*(fac (n-k)))
9+
10+sumBinomials : Integer -> Integer
11+sumBinomials n = foldr (+) 0 (map (\k=>binomial n k) [0..n])
12+
13+main : IO ()
14+main = do
15+ if sumBinomials 1000 - pow 2 1000 == 0
16+ then putStrLn "OK"
17+ else putStrLn "ERROR"
test/bignum001/expectednew file+1
@@ -0,0 +1 @@
1+OK
test/bignum001/runnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env bash
2+idris $@ bignum001.idr -o bignum001
3+./bignum001
4+rm -f bignum001 *.ibc