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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
/*
\funcref{push}{void push (\params)}
{
{VAR\_} {v} {variable to push}
}
{}
{xrealloc()}
{pop()}
{push.c}
{
This function pushes a variable of the {\em VAR\_} struct type onto
the stack. The stack is relocatable and therefore grows upward. The
reallocation of the stack occurs in blocks of 10 elements.
The stack is pointed to by {\em VAR\_ $*$stack}. The last used
element of the stack is indexed by {\em sp}. Therefore, {\em
stack[sp]} is the pushed value after {\em push()} completes.
Each stack element contains the following fields:
\begin{itemize}
\item the variable type is defined in field {\em type}. The type
may be: {\em e\_int}, {\em e\_str} e\_list}. Other types, which are
used by the {\em icmake} compiler, have no meaning in the execution
phase.
\item the variable value is kept in field {\em vu}. Depending on
the variable type, {\em vu$\rightarrow$ls.str} is a pointer to an
allocated string, {\em vu.intval} is an integer value, {\em
vu$\rightarrow$ls.list} is a list.
A list variable contains a {\em size} field, stating the number of
elements in the list, and an {\em element} field which is a {\em
char $**$}.
\end{itemize}
}
*/
#include "icm-exec.h"
static unsigned
stacksize;
void push (VAR_ v)
{
sp++;
if (stacksize <= sp)
{
stacksize = sp + 10;
stack = xrealloc (stack, stacksize * sizeof (VAR_));
}
stack [sp] = v;
}
|