|
@@ -3,18 +3,26 @@
|
3
|
3
|
TURMIT_OP(mem_sz)
|
4
|
4
|
{
|
5
|
5
|
turmit_int *new;
|
6
|
|
- turmit_int new_sz, old_sz;
|
|
6
|
+ turmit_int new_sz, old_sz, new_blc, old_blc;
|
7
|
7
|
|
8
|
8
|
old_sz = turmit->stack_sz;
|
|
9
|
+ old_blc = (old_sz / TURMIT_STACK_GROW) + 1;
|
|
10
|
+
|
9
|
11
|
new_sz = SPOP(turmit);
|
10
|
12
|
new_sz = new_sz<2?2:new_sz;
|
|
13
|
+ new_sz %= TURMIT_STACK_MAX;
|
|
14
|
+ new_blc = (new_sz / TURMIT_STACK_GROW) + 1;
|
11
|
15
|
|
12
|
|
- new = realloc(turmit->stack, sizeof(turmit_int) * new_sz);
|
13
|
|
- if(!new) {
|
14
|
|
- perror("Unable to reallocate memory for stack");
|
15
|
|
- return;
|
|
16
|
+ if(new_blc != old_blc)
|
|
17
|
+ {
|
|
18
|
+ new = realloc(turmit->stack,
|
|
19
|
+ sizeof(turmit_int) * (new_blc * TURMIT_STACK_GROW));
|
|
20
|
+ if(!new) {
|
|
21
|
+ perror("Unable to reallocate memory for stack");
|
|
22
|
+ return;
|
|
23
|
+ }
|
|
24
|
+ turmit->stack = new;
|
16
|
25
|
}
|
17
|
|
- turmit->stack = new;
|
18
|
26
|
turmit->stack_sz = new_sz;
|
19
|
27
|
turmit->stack_cur %= new_sz;
|
20
|
28
|
if(old_sz < new_sz)
|
|
@@ -170,7 +178,8 @@ turmit_t *turmit_init(turmit_t *turmit, ssize_t stack_sz, ssize_t int_max,
|
170
|
178
|
turmit->stack_cur = turmit->stack_sz - 1;
|
171
|
179
|
turmit->err = 0;
|
172
|
180
|
turmit->err_str = NULL;
|
173
|
|
- turmit->stack = malloc(sizeof(turmit_int) * turmit->stack_sz);
|
|
181
|
+ turmit->stack = malloc(sizeof(turmit_int) *
|
|
182
|
+ ((turmit->stack_sz / TURMIT_STACK_GROW)+1) * TURMIT_STACK_GROW);
|
174
|
183
|
|
175
|
184
|
if(!turmit->stack)
|
176
|
185
|
{
|
|
@@ -189,6 +198,8 @@ turmit_t *turmit_init(turmit_t *turmit, ssize_t stack_sz, ssize_t int_max,
|
189
|
198
|
turmit_t *turmit_copy(turmit_t *turmit)
|
190
|
199
|
{
|
191
|
200
|
turmit_t *res;
|
|
201
|
+ turmit_int stack_blck;
|
|
202
|
+
|
192
|
203
|
res = malloc(sizeof(turmit_t));
|
193
|
204
|
if(!res)
|
194
|
205
|
{
|
|
@@ -202,9 +213,11 @@ turmit_t *turmit_copy(turmit_t *turmit)
|
202
|
213
|
}
|
203
|
214
|
if(turmit->stack)
|
204
|
215
|
{
|
205
|
|
- res->stack = malloc(sizeof(turmit_int) * res->stack_sz);
|
|
216
|
+ stack_blck = (res->stack_sz / TURMIT_STACK_GROW) + 1;
|
|
217
|
+ res->stack = malloc(
|
|
218
|
+ sizeof(turmit_int) * stack_blck * TURMIT_STACK_GROW);
|
206
|
219
|
memcpy(res->stack, turmit->stack,
|
207
|
|
- sizeof(turmit_int) * res->stack_sz);
|
|
220
|
+ sizeof(turmit_int) * stack_blck * TURMIT_STACK_GROW);
|
208
|
221
|
}
|
209
|
222
|
if(turmit->op_expr)
|
210
|
223
|
{
|