Lines Matching refs:stack
28 static __inline bool stack_empty(const struct stack *);
29 static void stack_grow(struct stack *);
38 stack_init(struct stack *stack) in stack_init() argument
40 stack->size = 0; in stack_init()
41 stack->sp = -1; in stack_init()
42 stack->stack = NULL; in stack_init()
46 stack_empty(const struct stack *stack) in stack_empty() argument
48 bool empty = stack->sp == -1; in stack_empty()
99 stack_size(const struct stack *stack) in stack_size() argument
101 return stack->sp + 1; in stack_size()
105 stack_dup(struct stack *stack) in stack_dup() argument
110 value = stack_tos(stack); in stack_dup()
115 stack_push(stack, stack_dup_value(value, ©)); in stack_dup()
119 stack_swap(struct stack *stack) in stack_swap() argument
123 if (stack->sp < 1) { in stack_swap()
127 copy = stack->stack[stack->sp]; in stack_swap()
128 stack->stack[stack->sp] = stack->stack[stack->sp-1]; in stack_swap()
129 stack->stack[stack->sp-1] = copy; in stack_swap()
133 stack_grow(struct stack *stack) in stack_grow() argument
137 if (++stack->sp == stack->size) { in stack_grow()
138 new_size = stack->size * 2 + 1; in stack_grow()
139 stack->stack = brealloc(stack->stack, in stack_grow()
140 new_size * sizeof(*stack->stack)); in stack_grow()
141 stack->size = new_size; in stack_grow()
146 stack_pushnumber(struct stack *stack, struct number *b) in stack_pushnumber() argument
148 stack_grow(stack); in stack_pushnumber()
149 stack->stack[stack->sp].type = BCODE_NUMBER; in stack_pushnumber()
150 stack->stack[stack->sp].u.num = b; in stack_pushnumber()
151 stack->stack[stack->sp].array = NULL; in stack_pushnumber()
155 stack_pushstring(struct stack *stack, char *string) in stack_pushstring() argument
157 stack_grow(stack); in stack_pushstring()
158 stack->stack[stack->sp].type = BCODE_STRING; in stack_pushstring()
159 stack->stack[stack->sp].u.string = string; in stack_pushstring()
160 stack->stack[stack->sp].array = NULL; in stack_pushstring()
164 stack_push(struct stack *stack, struct value *v) in stack_push() argument
168 stack_grow(stack); in stack_push()
169 stack->stack[stack->sp].type = BCODE_NONE; in stack_push()
172 stack_pushnumber(stack, v->u.num); in stack_push()
175 stack_pushstring(stack, v->u.string); in stack_push()
178 stack->stack[stack->sp].array = v->array == NULL ? in stack_push()
183 stack_tos(const struct stack *stack) in stack_tos() argument
185 if (stack->sp == -1) in stack_tos()
187 return &stack->stack[stack->sp]; in stack_tos()
191 stack_set_tos(struct stack *stack, struct value *v) in stack_set_tos() argument
193 if (stack->sp == -1) in stack_set_tos()
194 stack_push(stack, v); in stack_set_tos()
196 stack_free_value(&stack->stack[stack->sp]); in stack_set_tos()
197 stack->stack[stack->sp] = *v; in stack_set_tos()
198 stack->stack[stack->sp].array = v->array == NULL ? in stack_set_tos()
204 stack_pop(struct stack *stack) in stack_pop() argument
206 if (stack_empty(stack)) in stack_pop()
208 return &stack->stack[stack->sp--]; in stack_pop()
212 stack_popnumber(struct stack *stack) in stack_popnumber() argument
214 if (stack_empty(stack)) in stack_popnumber()
216 if (stack->stack[stack->sp].array != NULL) { in stack_popnumber()
217 array_free(stack->stack[stack->sp].array); in stack_popnumber()
218 stack->stack[stack->sp].array = NULL; in stack_popnumber()
220 if (stack->stack[stack->sp].type != BCODE_NUMBER) { in stack_popnumber()
224 return stack->stack[stack->sp--].u.num; in stack_popnumber()
228 stack_popstring(struct stack *stack) in stack_popstring() argument
230 if (stack_empty(stack)) in stack_popstring()
232 if (stack->stack[stack->sp].array != NULL) { in stack_popstring()
233 array_free(stack->stack[stack->sp].array); in stack_popstring()
234 stack->stack[stack->sp].array = NULL; in stack_popstring()
236 if (stack->stack[stack->sp].type != BCODE_STRING) { in stack_popstring()
240 return stack->stack[stack->sp--].u.string; in stack_popstring()
244 stack_clear(struct stack *stack) in stack_clear() argument
246 while (stack->sp >= 0) { in stack_clear()
247 stack_free_value(&stack->stack[stack->sp--]); in stack_clear()
249 free(stack->stack); in stack_clear()
250 stack_init(stack); in stack_clear()
254 stack_print(FILE *f, const struct stack *stack, const char *prefix, u_int base) in stack_print() argument
258 for (i = stack->sp; i >= 0; i--) { in stack_print()
259 print_value(f, &stack->stack[i], prefix, base); in stack_print()
335 frame_assign(struct stack *stack, size_t index, const struct value *v) in frame_assign() argument
340 if (stack->sp == -1) { in frame_assign()
343 stack_push(stack, &n); in frame_assign()
346 a = stack->stack[stack->sp].array; in frame_assign()
348 a = stack->stack[stack->sp].array = array_new(); in frame_assign()
353 frame_retrieve(const struct stack *stack, size_t index) in frame_retrieve() argument
357 if (stack->sp == -1) in frame_retrieve()
359 a = stack->stack[stack->sp].array; in frame_retrieve()
361 a = stack->stack[stack->sp].array = array_new(); in frame_retrieve()