[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How does runtime stack work?
From: |
Peng Yu |
Subject: |
How does runtime stack work? |
Date: |
Thu, 20 May 2021 18:04:05 -0500 |
Hi,
I see a stack is used in gawk. I don't understand what this is used
for. Could anybody help explain? Thanks.
http://git.savannah.gnu.org/cgit/gawk.git/tree/awk.h#n1230
/* ------------------------- Runtime stack -------------------------------- */
typedef union stack_item {
NODE *rptr; /* variable etc. */
NODE **lptr; /* address of a variable etc. */
} STACK_ITEM;
extern STACK_ITEM *stack_ptr;
extern NODE *frame_ptr;
extern STACK_ITEM *stack_bottom;
extern STACK_ITEM *stack_top;
#define decr_sp() (stack_ptr--)
#define incr_sp() ((stack_ptr < stack_top) ? ++stack_ptr : grow_stack())
#define stack_adj(n) (stack_ptr += (n))
#define stack_empty() (stack_ptr < stack_bottom)
#define POP() (decr_sp()->rptr)
#define POP_ADDRESS() (decr_sp()->lptr)
#define PEEK(n) ((stack_ptr - (n))->rptr)
#define TOP() (stack_ptr->rptr) /* same as PEEK(0) */
#define TOP_ADDRESS() (stack_ptr->lptr)
#define PUSH(r) (void) (incr_sp()->rptr = (r))
#define PUSH_ADDRESS(l) (void) (incr_sp()->lptr = (l))
#define REPLACE(r) (void) (stack_ptr->rptr = (r))
#define REPLACE_ADDRESS(l) (void) (stack_ptr->lptr = (l))
/* function param */
#define GET_PARAM(n) frame_ptr->stack[n]
/*
* UPREF --- simplified versions of dupnode, does not handle FIELD node.
* Most appropriate use is for elements on the runtime stack.
* When in doubt, use dupnode.
*/
#define UPREF(r) (void) ((r)->valref++)
extern void r_unref(NODE *tmp);
static inline void
DEREF(NODE *r)
{
assert(r->valref > 0);
#ifndef GAWKDEBUG
if (--r->valref > 0)
return;
#endif
r_unref(r);
}
#define POP_NUMBER() force_number(POP_SCALAR())
#define TOP_NUMBER() force_number(TOP_SCALAR())
--
Regards,
Peng
- How does runtime stack work?,
Peng Yu <=
- Re: How does runtime stack work?, arnold, 2021/05/21
- Re: How does runtime stack work?, Peng Yu, 2021/05/21
- Re: How does runtime stack work?, david kerns, 2021/05/21
- Re: How does runtime stack work?, arnold, 2021/05/23
- Re: How does runtime stack work?, Wolfgang Laun, 2021/05/23
- Re: How does runtime stack work?, Peng Yu, 2021/05/23
- Re: How does runtime stack work?, arnold, 2021/05/23