on master help sign in
Take into account that GMP operations can move data
029da07Edwin Brady
rts/Makefile+4−2
@@ -1,7 +1,9 @@
1include ../config.mk
1include ../config.mk
2
2
3−OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_stdfgn.o idris_bitstring.o idris_opts.o idris_stats.o
3+OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_stdfgn.o \
4+ idris_bitstring.o idris_opts.o idris_stats.o
4−HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_stdfgn.h idris_bitstring.h idris_opts.h idris_stats.h
5+HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_stdfgn.h \
6+ idris_bitstring.h idris_opts.h idris_stats.h
5CFLAGS:=-fPIC $(CFLAGS)
7CFLAGS:=-fPIC $(CFLAGS)
6ifneq ($(GMP_INCLUDE_DIR),)
8ifneq ($(GMP_INCLUDE_DIR),)
7 CFLAGS += -isystem $(GMP_INCLUDE_DIR)
9 CFLAGS += -isystem $(GMP_INCLUDE_DIR)
rts/idris_gmp.c+12−7
@@ -1,5 +1,5 @@
1#include "idris_rts.h"
1#include "idris_rts.h"
2−#include <gmp.h>
2+#include <gmp.h>
3#include <stdlib.h>
3#include <stdlib.h>
4#include <string.h>
4#include <string.h>
5
5
@@ -92,7 +92,12 @@ VAL GETBIG(VM * vm, VAL x) {
92
92
93 return cl;
93 return cl;
94 } else {
94 } else {
95+ switch(GETTY(x)) {
96+ case FWD:
97+ return GETBIG(vm, x->info.ptr);
98+ default:
95− return x;
99+ return x;
100+ }
96 }
101 }
97}
102}
98
103
@@ -100,7 +105,7 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
100 mpz_t* bigint;
105 mpz_t* bigint;
101 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
106 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
102 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
107 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
103− mpz_add(*bigint, GETMPZ(x), GETMPZ(y));
108+ mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
104 SETTY(cl, BIGINT);
109 SETTY(cl, BIGINT);
105 cl -> info.ptr = (void*)bigint;
110 cl -> info.ptr = (void*)bigint;
106 return cl;
111 return cl;
@@ -110,7 +115,7 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
110 mpz_t* bigint;
115 mpz_t* bigint;
111 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
116 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
112 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
117 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
113− mpz_sub(*bigint, GETMPZ(x), GETMPZ(y));
118+ mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
114 SETTY(cl, BIGINT);
119 SETTY(cl, BIGINT);
115 cl -> info.ptr = (void*)bigint;
120 cl -> info.ptr = (void*)bigint;
116 return cl;
121 return cl;
@@ -120,7 +125,7 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
120 mpz_t* bigint;
125 mpz_t* bigint;
121 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
126 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
122 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
127 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
123− mpz_mul(*bigint, GETMPZ(x), GETMPZ(y));
128+ mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
124 SETTY(cl, BIGINT);
129 SETTY(cl, BIGINT);
125 cl -> info.ptr = (void*)bigint;
130 cl -> info.ptr = (void*)bigint;
126 return cl;
131 return cl;
@@ -130,7 +135,7 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
130 mpz_t* bigint;
135 mpz_t* bigint;
131 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
136 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
132 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
137 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
133− mpz_div(*bigint, GETMPZ(x), GETMPZ(y));
138+ mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
134 SETTY(cl, BIGINT);
139 SETTY(cl, BIGINT);
135 cl -> info.ptr = (void*)bigint;
140 cl -> info.ptr = (void*)bigint;
136 return cl;
141 return cl;
@@ -140,7 +145,7 @@ VAL bigMod(VM* vm, VAL x, VAL y) {
140 mpz_t* bigint;
145 mpz_t* bigint;
141 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
146 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
142 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
147 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
143− mpz_mod(*bigint, GETMPZ(x), GETMPZ(y));
148+ mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
144 SETTY(cl, BIGINT);
149 SETTY(cl, BIGINT);
145 cl -> info.ptr = (void*)bigint;
150 cl -> info.ptr = (void*)bigint;
146 return cl;
151 return cl;
src/Core/CaseTree.hs+1
@@ -493,6 +493,7 @@ depatt ns tm = dp [] tm
493 applyMaps ms (App f a) = App (applyMaps ms f) (applyMaps ms a)
493 applyMaps ms (App f a) = App (applyMaps ms f) (applyMaps ms a)
494 applyMaps ms t = t
494 applyMaps ms t = t
495
495
496+-- FIXME: Do this for SucCase too
496prune :: Bool -- ^ Convert single branches to projections (only useful at runtime)
497prune :: Bool -- ^ Convert single branches to projections (only useful at runtime)
497 -> SC -> SC
498 -> SC -> SC
498prune proj (Case n alts)
499prune proj (Case n alts)
src/IRTS/CodegenC.hs+1−1
@@ -67,7 +67,7 @@ codegenC defs out exec incs objs libs flags dbg
67headers xs =
67headers xs =
68 concatMap
68 concatMap
69 (\h -> "#include <" ++ h ++ ">\n")
69 (\h -> "#include <" ++ h ++ ">\n")
70− (xs ++ ["idris_rts.h", "idris_bitstring.h", "idris_stdfgn.h", "gmp.h", "assert.h"])
70+ (xs ++ ["idris_rts.h", "idris_bitstring.h", "idris_stdfgn.h", "assert.h"])
71
71
72debug TRACE = "#define IDRIS_TRACE\n\n"
72debug TRACE = "#define IDRIS_TRACE\n\n"
73debug _ = ""
73debug _ = ""