on master help sign in
Message passing fixes in VM
cdfaa9fEdwin Brady
rts/idris_gmp.c+12−2
@@ -27,6 +27,7 @@ VAL MKBIGC(VM* vm, char* val) {
27 mpz_t* bigint;
27 mpz_t* bigint;
28
28
29 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
29 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
30+ idris_doneAlloc();
30 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
31 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
31
32
32 mpz_init(*bigint);
33 mpz_init(*bigint);
@@ -43,6 +44,7 @@ VAL MKBIGM(VM* vm, void* big) {
43
44
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);
47+ idris_doneAlloc();
46 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
48 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
47
49
48 mpz_init(*bigint);
50 mpz_init(*bigint);
@@ -59,6 +61,7 @@ VAL MKBIGMc(VM* vm, void* big) {
59
61
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);
64+ idris_doneAlloc();
62 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
65 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
63
66
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) {
74
77
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);
80+ idris_doneAlloc();
77 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
81 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
78
82
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) {
89
93
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);
96+ idris_doneAlloc();
92 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
97 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
93
98
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);
113+ idris_doneAlloc();
108 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
114 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
109
115
110 mpz_init(*bigint);
116 mpz_init(*bigint);
@@ -115,6 +121,7 @@ VAL GETBIG(VM * vm, VAL x) {
115
121
116 return cl;
122 return cl;
117 } else {
123 } else {
124+ idris_doneAlloc();
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) {
129
136
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);
139+ idris_doneAlloc();
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) {
141
149
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);
152+ idris_doneAlloc();
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) {
153
162
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);
165+ idris_doneAlloc();
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) {
165
175
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);
178+ idris_doneAlloc();
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) {
177
188
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);
191+ idris_doneAlloc();
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) {
258}
270}
259
271
260int bigEqConst(VAL x, int c) {
272int bigEqConst(VAL x, int c) {
261− idris_requireAlloc(IDRIS_MAXGMP);
262−
263 if (ISINT(x)) { return (GETINT(x) == c); }
273 if (ISINT(x)) { return (GETINT(x) == c); }
264 else {
274 else {
265 int rv = mpz_cmp_si(GETMPZ(x), c);
275 int rv = mpz_cmp_si(GETMPZ(x), c);
rts/idris_rts.c+10−2
@@ -1005,7 +1005,7 @@ void* vmThread(VM* callvm, func f, VAL arg) {
1005
1005
1006// VM is assumed to be a different vm from the one x lives on
1006// VM is assumed to be a different vm from the one x lives on
1007
1007
1008−VAL copyTo(VM* vm, VAL x) {
1008+VAL doCopyTo(VM* vm, VAL x) {
1009 int i, ar;
1009 int i, ar;
1010 VAL* argptr;
1010 VAL* argptr;
1011 Closure* cl;
1011 Closure* cl;
@@ -1022,7 +1022,7 @@ VAL copyTo(VM* vm, VAL x) {
1022
1022
1023 argptr = (VAL*)(cl->info.c.args);
1023 argptr = (VAL*)(cl->info.c.args);
1024 for(i = 0; i < ar; ++i) {
1024 for(i = 0; i < ar; ++i) {
1025− *argptr = copyTo(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
1025+ *argptr = doCopyTo(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
1026 argptr++;
1026 argptr++;
1027 }
1027 }
1028 }
1028 }
@@ -1063,6 +1063,14 @@ VAL copyTo(VM* vm, VAL x) {
1063 return cl;
1063 return cl;
1064}
1064}
1065
1065
1066+VAL copyTo(VM* vm, VAL x) {
1067+ VM* current = pthread_getspecific(vm_key);
1068+ pthread_setspecific(vm_key, vm);
1069+ VAL ret = doCopyTo(vm, x);
1070+ pthread_setspecific(vm_key, current);
1071+ return ret;
1072+}
1073+
1066// Add a message to another VM's message queue
1074// Add a message to another VM's message queue
1067void idris_sendMessage(VM* sender, VM* dest, VAL msg) {
1075void idris_sendMessage(VM* sender, VM* dest, VAL msg) {
1068 // FIXME: If GC kicks in in the middle of the copy, we're in trouble.
1076 // FIXME: If GC kicks in in the middle of the copy, we're in trouble.