Debian Codegraph @

terps/alan2/stack.c

raw symbols SCIP
1 /*----------------------------------------------------------------------*\
2
3 STACK.C
4
5 Stack Handling for Alan interpreter
6
7 \*----------------------------------------------------------------------*/
8
9
10 #include "types.h"
11 #include "main.h"
12
13 #include "stack.h"
14
15
16 /* PRIVATE DATA */
17
18 #define STACKSIZE 100
19
20 /* The AMACHINE STACK */
21 static Aptr stack[STACKSIZE];
22 static int stackp = 0;
23
24
25 #ifdef _PROTOTYPES_
26 void push(Aptr i)
27 #else
28 void push(i)
29 Aptr i;
30 #endif
31 {
32 if (stackp == STACKSIZE)
33 syserr("Out of stack space.");
34 stack[stackp++] = i;
35 }
36
37
38 #ifdef _PROTOTYPES_
39 Aptr pop(void)
40 #else
41 Aptr pop()
42 #endif
43 {
44 if (stackp == 0)
45 syserr("Stack underflow.");
46 return(stack[--stackp]);
47 }
48
49
50 #ifdef _PROTOTYPES_
51 Aptr top(void)
52 #else
53 Aptr top()
54 #endif
55 {
56 return(stack[stackp-1]);
57 }