Browse Source

Fixing jmp operations

Yann Weber 6 years ago
parent
commit
545d33cd76
2 changed files with 12 additions and 4 deletions
  1. 8
    4
      libs/turmit.c
  2. 4
    0
      libs/turmit.h

+ 8
- 4
libs/turmit.c View File

101
 
101
 
102
 TURMIT_OP(jmp)
102
 TURMIT_OP(jmp)
103
 {
103
 {
104
-	turmit->op_cur += SPOP(turmit) - 1;
104
+	turmit_int a;
105
+	a = SPOP(turmit);
106
+	TURMIT_JMP(turmit, a);
105
 }
107
 }
106
 
108
 
107
 TURMIT_OP(jz)
109
 TURMIT_OP(jz)
111
 	b = SPOP(turmit);
113
 	b = SPOP(turmit);
112
 	if(b == 0)
114
 	if(b == 0)
113
 	{
115
 	{
114
-		turmit->op_cur += a - 1;
116
+		TURMIT_JMP(turmit, a);
115
 	}
117
 	}
116
 }
118
 }
117
 
119
 
125
 	if(((cnd & 7) == 0 && a != b) || (cnd > 6) || ((cnd & 1) && a == b) ||
127
 	if(((cnd & 7) == 0 && a != b) || (cnd > 6) || ((cnd & 1) && a == b) ||
126
 		((cnd & 7) > 2 && a < b) || ((cnd & 7) > 4 && a > b))
128
 		((cnd & 7) > 2 && a < b) || ((cnd & 7) > 4 && a > b))
127
 	{
129
 	{
128
-		turmit->op_cur += offset - 1;
130
+		TURMIT_JMP(turmit, offset);
129
 	}
131
 	}
130
 }
132
 }
131
 
133
 
152
 	turmit->op_expr = NULL;
154
 	turmit->op_expr = NULL;
153
 	turmit->op_expr_sz = 0;
155
 	turmit->op_expr_sz = 0;
154
 	turmit->op_cur = 0;
156
 	turmit->op_cur = 0;
157
+	turmit->op_end = 0;
155
 	turmit->stack_sz = stack_sz;
158
 	turmit->stack_sz = stack_sz;
156
 	turmit->stack_cur = turmit->stack_sz - 1;
159
 	turmit->stack_cur = turmit->stack_sz - 1;
157
 	turmit->stack = malloc(sizeof(turmit_int) * turmit->stack_sz);
160
 	turmit->stack = malloc(sizeof(turmit_int) * turmit->stack_sz);
225
 	turmit_op_t *op;
228
 	turmit_op_t *op;
226
 
229
 
227
 	turmit->op_cur = 0;
230
 	turmit->op_cur = 0;
228
-	while(turmit->op_cur < turmit->op_expr_sz)
231
+	turmit->op_end = 0;
232
+	while(!turmit->op_end && turmit->op_cur < turmit->op_expr_sz)
229
 	{
233
 	{
230
 		op = &(turmit->op_expr[turmit->op_cur]);
234
 		op = &(turmit->op_expr[turmit->op_cur]);
231
 		switch(op->value)
235
 		switch(op->value)

+ 4
- 0
libs/turmit.h View File

22
 #define SPOP(t) (__SPOP(t))
22
 #define SPOP(t) (__SPOP(t))
23
 #define SPUSH(t, v) (t->stack[SINC(t)] = v % t->int_max)
23
 #define SPUSH(t, v) (t->stack[SINC(t)] = v % t->int_max)
24
 
24
 
25
+#define TURMIT_JMP(t, v) (((t->op_expr_sz - t->op_cur) <= v)?\
26
+	(t->op_end=1):\
27
+	(t->op_cur += (v>0?v-1:0) ))
25
 
28
 
26
 #define TURMIT_EXPR_MAX_SZ	0xFFFFFFFF
29
 #define TURMIT_EXPR_MAX_SZ	0xFFFFFFFF
27
 
30
 
92
 	turmit_op_t *op_expr;
95
 	turmit_op_t *op_expr;
93
 	ssize_t op_expr_sz;
96
 	ssize_t op_expr_sz;
94
 	ssize_t op_cur;
97
 	ssize_t op_cur;
98
+	short op_end;
95
 
99
 
96
 	ssize_t stack_sz;
100
 	ssize_t stack_sz;
97
 	turmit_int *stack;
101
 	turmit_int *stack;

Loading…
Cancel
Save