1 /*
2   Stack
3 */
4 
5 #include "stack.h"
6 
7 word stack_space[STACK_SIZE];
8 word *var_ptr;
9 word *stack_ptr;
10 
stk_throw(word off)11 void stk_throw(word off)
12 {
13   var_ptr = stack_base + off;
14 }
15 
stk_link(void)16 void stk_link(void)
17 {
18   stk_push((word)(var_ptr - stack_base));
19   var_ptr = stack_ptr;
20 }
21 
stk_unlink(void)22 void stk_unlink(void)
23 {
24   stack_ptr = var_ptr;
25   var_ptr   = stack_base + (signed_word) stk_pop();
26 }
27 
stk_init(void)28 void stk_init(void)
29 {
30   stack_ptr = var_ptr = stack_base - 1;
31 }
32 
33 
stk_encode_stk(void)34 word stk_encode_stk(void)
35 {
36   return -(int)(stack_ptr - stack_base);
37 }
38 
stk_encode_var(void)39 word stk_encode_var(void)
40 {
41   return -(int)(var_ptr - stack_base);
42 }
43 
stk_decode_stk(word off)44 void stk_decode_stk(word off)
45 {
46   stack_ptr = stack_base - off;
47 }
48 
stk_decode_var(word off)49 void stk_decode_var(word off)
50 {
51   var_ptr = stack_base - off;
52 }
53 
54 
55 
56