@@ -27,6 +27,7 @@ VAL MKBIGC(VM* vm, char* val) {
27 mpz_t* bigint;
27 mpz_t* bigint;
29 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
29 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
30 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
31 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
32 mpz_init(*bigint);
33 mpz_init(*bigint);
@@ -43,6 +44,7 @@ VAL MKBIGM(VM* vm, void* big) {
44 mpz_t* bigint;
45 mpz_t* bigint;
45 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
46 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
46 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
48 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
48 mpz_init(*bigint);
50 mpz_init(*bigint);
@@ -59,6 +61,7 @@ VAL MKBIGMc(VM* vm, void* big) {
60 mpz_t* bigint;
62 mpz_t* bigint;
61 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
63 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
62 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
65 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
64 mpz_init_set(*bigint, *((mpz_t*)big));
67 mpz_init_set(*bigint, *((mpz_t*)big));
@@ -74,6 +77,7 @@ VAL MKBIGUI(VM* vm, unsigned long val) {
75 mpz_t* bigint;
78 mpz_t* bigint;
76 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
79 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
77 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
81 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
79 mpz_init_set_ui(*bigint, val);
83 mpz_init_set_ui(*bigint, val);
@@ -89,6 +93,7 @@ VAL MKBIGSI(VM* vm, signed long val) {
90 mpz_t* bigint;
94 mpz_t* bigint;
91 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
95 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
92 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
97 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
94 mpz_init_set_si(*bigint, val);
99 mpz_init_set_si(*bigint, val);
@@ -105,6 +110,7 @@ VAL GETBIG(VM * vm, VAL x) {
105 if (ISINT(x)) {
110 if (ISINT(x)) {
106 mpz_t* bigint;
111 mpz_t* bigint;
107 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
112 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
108 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
114 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
110 mpz_init(*bigint);
116 mpz_init(*bigint);
@@ -115,6 +121,7 @@ VAL GETBIG(VM * vm, VAL x) {
116 return cl;
122 return cl;
118 switch(GETTY(x)) {
125 switch(GETTY(x)) {
119 case FWD:
126 case FWD:
120 return GETBIG(vm, x->info.ptr);
127 return GETBIG(vm, x->info.ptr);
@@ -129,6 +136,7 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
130 mpz_t* bigint;
137 mpz_t* bigint;
131 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
138 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
132 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
140 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
133 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
141 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
134 SETTY(cl, BIGINT);
142 SETTY(cl, BIGINT);
@@ -141,6 +149,7 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
142 mpz_t* bigint;
150 mpz_t* bigint;
143 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
151 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
144 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
153 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
145 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
154 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
146 SETTY(cl, BIGINT);
155 SETTY(cl, BIGINT);
@@ -153,6 +162,7 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
154 mpz_t* bigint;
163 mpz_t* bigint;
155 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
164 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
156 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
166 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
157 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
167 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
158 SETTY(cl, BIGINT);
168 SETTY(cl, BIGINT);
@@ -165,6 +175,7 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
166 mpz_t* bigint;
176 mpz_t* bigint;
167 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
177 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
168 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
179 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
169 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
180 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
170 SETTY(cl, BIGINT);
181 SETTY(cl, BIGINT);
@@ -177,6 +188,7 @@ VAL bigMod(VM* vm, VAL x, VAL y) {
178 mpz_t* bigint;
189 mpz_t* bigint;
179 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
190 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
180 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
192 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
181 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
193 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
182 SETTY(cl, BIGINT);
194 SETTY(cl, BIGINT);
@@ -258,8 +270,6 @@ VAL idris_bigMod(VM* vm, VAL x, VAL y) {
260int bigEqConst(VAL x, int c) {
272int bigEqConst(VAL x, int c) {
261− idris_requireAlloc(IDRIS_MAXGMP);
263 if (ISINT(x)) { return (GETINT(x) == c); }
273 if (ISINT(x)) { return (GETINT(x) == c); }
265 int rv = mpz_cmp_si(GETMPZ(x), c);
275 int rv = mpz_cmp_si(GETMPZ(x), c);