1#include "cotton.h"
2#include <stdio.h>
3
4void cotton_init
5(Cotton *c)
6{
7 c->stack_p = 0;
8 c->jmp_stack_p = 0;
9 c->instruct_p = 0;
10 c->mem_len = 0;
11
12 for (int i = 0; i < VARS_SIZE; i++) {
13
14 c->vars[i] = 0;
15 }
16}
17
18void push
19(Cotton *c, int v)
20{
21 if (c->stack_p >= STACK_SIZE) {
22
23 fprintf(stderr, "cotton: stack overflow,., like the website,.., :<\n");
24 return;
25 }
26
27 c->stack[c->stack_p++] = v;
28}
29
30int pop
31(Cotton *c)
32{
33 if (c->stack_p <= 0) {
34
35 fprintf(stderr, "cotton: stack underflow :<\n");
36 return 0;
37 }
38
39 return c->stack[--c->stack_p];
40}