@@ -1,5 +1,5 @@
11#include "idris_rts.h"
2−#include <gmp.h>
2+#include <gmp.h>
33#include <stdlib.h>
44#include <string.h>
55
@@ -92,7 +92,12 @@ VAL GETBIG(VM * vm, VAL x) {
9292
9393 return cl;
9494 } else {
95− return x;
95+ switch(GETTY(x)) {
96+ case FWD:
97+ return GETBIG(vm, x->info.ptr);
98+ default:
99+ return x;
100+ }
96101 }
97102}
98103
@@ -100,7 +105,7 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
100105 mpz_t* bigint;
101106 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
102107 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)));
104109 SETTY(cl, BIGINT);
105110 cl -> info.ptr = (void*)bigint;
106111 return cl;
@@ -110,7 +115,7 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
110115 mpz_t* bigint;
111116 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
112117 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)));
114119 SETTY(cl, BIGINT);
115120 cl -> info.ptr = (void*)bigint;
116121 return cl;
@@ -120,7 +125,7 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
120125 mpz_t* bigint;
121126 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
122127 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)));
124129 SETTY(cl, BIGINT);
125130 cl -> info.ptr = (void*)bigint;
126131 return cl;
@@ -130,7 +135,7 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
130135 mpz_t* bigint;
131136 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
132137 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)));
134139 SETTY(cl, BIGINT);
135140 cl -> info.ptr = (void*)bigint;
136141 return cl;
@@ -140,7 +145,7 @@ VAL bigMod(VM* vm, VAL x, VAL y) {
140145 mpz_t* bigint;
141146 VAL cl = allocate(vm, sizeof(Closure) + sizeof(mpz_t), 0);
142147 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)));
144149 SETTY(cl, BIGINT);
145150 cl -> info.ptr = (void*)bigint;
146151 return cl;