@@ -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>
@@ -92,7 +92,12 @@ VAL GETBIG(VM * vm, VAL x) {
93 return cl;
93 return cl;
97+ return GETBIG(vm, x->info.ptr);
95− return x;
99+ return x;
@@ -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;