-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstack.c
34 lines (26 loc) · 870 Bytes
/
stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "abclang.h"
void abc_stack_push_value(ABC_Value *value) {
ABC_Interpreter *inter;
inter = abc_get_interpreter();
if (inter->stack.pos == inter->stack.alloc_size) {
inter->stack.alloc_size += STACK_ALLOC_SIZE;
inter->stack.top = (ABC_Value*)MEM_realloc(inter->stack.top,
inter->stack.alloc_size * sizeof(ABC_Value));
}
inter->stack.top[inter->stack.pos++] = *value;
}
ABC_Value abc_stack_pop_value() {
ABC_Value value;
ABC_Interpreter *inter;
inter = abc_get_interpreter();
value = inter->stack.top[--inter->stack.pos];
return value;
}
void abc_stack_shrink(int num) {
abc_get_interpreter()->stack.pos -= num;
}
ABC_Value *abc_stack_peek(int idx) {
ABC_Interpreter *inter;
inter = abc_get_interpreter();
return &(inter->stack.top[inter->stack.pos-idx-1]);
}