|
@@ -10,13 +10,17 @@ TURMIT_OP(mem_sz)
|
10
|
10
|
new_sz = new_sz<2?2:new_sz;
|
11
|
11
|
|
12
|
12
|
new = realloc(turmit->stack, sizeof(turmit_int) * new_sz);
|
13
|
|
- if(!new) { return; }
|
|
13
|
+ if(!new) {
|
|
14
|
+ perror("Unable to reallocate memory for stack");
|
|
15
|
+ return;
|
|
16
|
+ }
|
14
|
17
|
turmit->stack = new;
|
15
|
18
|
turmit->stack_sz = new_sz;
|
16
|
19
|
turmit->stack_cur %= new_sz;
|
17
|
20
|
if(old_sz < new_sz)
|
18
|
21
|
{
|
19
|
|
- bzero(turmit->stack + old_sz, new_sz - old_sz);
|
|
22
|
+ bzero(turmit->stack + old_sz,
|
|
23
|
+ sizeof(turmit_int) * (new_sz - old_sz));
|
20
|
24
|
}
|
21
|
25
|
}
|
22
|
26
|
|
|
@@ -29,7 +33,14 @@ TURMIT_OP(add)
|
29
|
33
|
TURMIT_OP(sub)
|
30
|
34
|
{
|
31
|
35
|
turmit_int a = SPOP(turmit), b = SPOP(turmit);
|
32
|
|
- SPUSH(turmit, b - a);
|
|
36
|
+ if(turmit->flags & TURMIT_SIGNED)
|
|
37
|
+ {
|
|
38
|
+ fprintf(stderr, "Signed int not implemented\n");
|
|
39
|
+ }
|
|
40
|
+ else
|
|
41
|
+ {
|
|
42
|
+ SPUSH(turmit, a>b?(turmit->int_max - a) + b:b - a);
|
|
43
|
+ }
|
33
|
44
|
}
|
34
|
45
|
|
35
|
46
|
TURMIT_OP(bin_and)
|
|
@@ -157,9 +168,9 @@ turmit_t *turmit_init(turmit_t *turmit, ssize_t stack_sz, ssize_t int_max,
|
157
|
168
|
turmit->op_end = 0;
|
158
|
169
|
turmit->stack_sz = stack_sz;
|
159
|
170
|
turmit->stack_cur = turmit->stack_sz - 1;
|
160
|
|
- turmit->stack = malloc(sizeof(turmit_int) * turmit->stack_sz);
|
161
|
171
|
turmit->err = 0;
|
162
|
172
|
turmit->err_str = NULL;
|
|
173
|
+ turmit->stack = malloc(sizeof(turmit_int) * turmit->stack_sz);
|
163
|
174
|
|
164
|
175
|
if(!turmit->stack)
|
165
|
176
|
{
|
|
@@ -211,6 +222,7 @@ turmit_t *turmit_copy(turmit_t *turmit)
|
211
|
222
|
|
212
|
223
|
void turmit_clean(turmit_t *turmit)
|
213
|
224
|
{
|
|
225
|
+ if(turmit->stack) { free(turmit->stack); }
|
214
|
226
|
if(turmit->err_str) { free(turmit->err_str); }
|
215
|
227
|
if(turmit->expr) { free(turmit->expr); }
|
216
|
228
|
if(turmit->op_expr) { free(turmit->op_expr); }
|