2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbx_stack.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-03-21 01:04:10 +01:00
|
|
|
(c) 2000-2011 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2009-08-17 12:41:51 +02:00
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
2007-12-30 17:41:49 +01:00
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __GBX_STACK_H
|
|
|
|
#define __GBX_STACK_H
|
|
|
|
|
|
|
|
#include "gbx_value.h"
|
|
|
|
#include "gb_pcode.h"
|
2009-05-18 14:00:48 +02:00
|
|
|
#include "gbx_debug.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
|
|
|
struct _stack_context {
|
|
|
|
struct _stack_context *next;
|
|
|
|
VALUE *bp; /* local variables */
|
|
|
|
VALUE *pp; /* local parameters */
|
|
|
|
CLASS *cp; /* current class */
|
|
|
|
char *op; /* current object */
|
|
|
|
VALUE *ep; /* error pointer */
|
|
|
|
FUNCTION *fp; /* current function */
|
|
|
|
PCODE *pc; /* instruction */
|
|
|
|
PCODE *ec; /* instruction if error */
|
|
|
|
PCODE *et; /* TRY save */
|
|
|
|
PCODE *tc; /* Last break in the function */
|
|
|
|
VALUE *tp; /* Stack at the last break in the function */
|
|
|
|
}
|
|
|
|
PACKED STACK_CONTEXT;
|
|
|
|
|
|
|
|
#ifndef __GBX_STACK_C
|
|
|
|
|
|
|
|
EXTERN char *STACK_base;
|
2008-01-17 22:39:26 +01:00
|
|
|
EXTERN size_t STACK_size;
|
2007-12-30 17:41:49 +01:00
|
|
|
EXTERN char *STACK_limit;
|
2009-05-27 20:42:48 +02:00
|
|
|
EXTERN size_t STACK_relocate;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
EXTERN int STACK_frame_count;
|
|
|
|
EXTERN STACK_CONTEXT *STACK_frame;
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
EXTERN uintptr_t STACK_process_stack_limit;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void STACK_init(void);
|
|
|
|
void STACK_exit(void);
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
|
|
#if DEBUG_STACK
|
2009-05-27 20:42:48 +02:00
|
|
|
bool STACK_check(int need);
|
2008-03-20 00:50:34 +01:00
|
|
|
#else
|
2009-05-27 20:42:48 +02:00
|
|
|
#define STACK_check(_need) (((char *)(SP + (_need) + 8) >= STACK_limit) ? STACK_grow(), 1 : 0)
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-10-31 00:32:38 +01:00
|
|
|
void STACK_push_frame(STACK_CONTEXT *context, int check);
|
2008-01-17 22:39:26 +01:00
|
|
|
void STACK_pop_frame(STACK_CONTEXT *context);
|
|
|
|
bool STACK_has_error_handler(void);
|
|
|
|
STACK_CONTEXT *STACK_get_frame(int frame);
|
2009-05-27 20:42:48 +02:00
|
|
|
void STACK_grow(void);
|
2008-03-19 15:32:30 +01:00
|
|
|
|
|
|
|
#define STACK_get_previous_pc() ((STACK_frame_count <= 0) ? NULL : STACK_frame->pc)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#define STACK_get_current() ((STACK_frame_count > 0) ? STACK_frame : NULL)
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
/*#define STACK_copy(_dst, _src) \
|
2008-03-19 15:32:30 +01:00
|
|
|
(_dst)->next = (_src)->next; \
|
|
|
|
(_dst)->bp = (_src)->bp; \
|
|
|
|
(_dst)->pp = (_src)->pp; \
|
|
|
|
(_dst)->cp = (_src)->cp; \
|
|
|
|
(_dst)->op = (_src)->op; \
|
|
|
|
(_dst)->ep = (_src)->ep; \
|
|
|
|
(_dst)->fp = (_src)->fp; \
|
|
|
|
(_dst)->pc = (_src)->pc; \
|
|
|
|
(_dst)->ec = (_src)->ec; \
|
|
|
|
(_dst)->et = (_src)->et; \
|
|
|
|
(_dst)->tc = (_src)->tc; \
|
2010-06-06 22:43:13 +02:00
|
|
|
(_dst)->tp = (_src)->tp;*/
|
|
|
|
|
|
|
|
#define STACK_copy(_dst, _src) *(_dst) = *(_src)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-05-27 20:42:48 +02:00
|
|
|
#define STACK_RELOCATE(_ptr) if (_ptr) _ptr = (void *)((char *)_ptr + STACK_relocate)
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define STACK_push_frame(_context, _need) \
|
|
|
|
({ \
|
|
|
|
int stack; \
|
|
|
|
\
|
|
|
|
if ((uintptr_t)&stack < STACK_process_stack_limit) \
|
|
|
|
THROW(E_STACK); \
|
|
|
|
\
|
|
|
|
if ((char *)(SP + (_need) + 8 + sizeof(STACK_CONTEXT)) >= STACK_limit) \
|
|
|
|
STACK_grow(); \
|
|
|
|
\
|
|
|
|
STACK_frame--; \
|
|
|
|
\
|
|
|
|
STACK_copy(STACK_frame, _context); \
|
|
|
|
\
|
|
|
|
STACK_frame_count++; \
|
|
|
|
STACK_limit = (char *)STACK_frame; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define STACK_pop_frame(_context) \
|
|
|
|
({ \
|
|
|
|
STACK_copy(_context, STACK_frame); \
|
|
|
|
STACK_frame++; \
|
|
|
|
STACK_frame_count--; \
|
|
|
|
STACK_limit = (char *)STACK_frame; \
|
|
|
|
})
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
#endif
|