2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2012-07-22 02:04:56 +02:00
|
|
|
gbx_stack.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2020-11-27 02:24:33 +01:00
|
|
|
(c) Benoît Minisini <g4mba5@gmail.com>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-07-22 02:04:56 +02: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
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-07-22 02:04:56 +02:00
|
|
|
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.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-07-22 02:04:56 +02:00
|
|
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __GBX_STACK_H
|
|
|
|
#define __GBX_STACK_H
|
|
|
|
|
|
|
|
#include "gbx_value.h"
|
|
|
|
#include "gb_pcode.h"
|
2011-08-31 04:28:48 +02:00
|
|
|
|
2013-01-01 12:55:40 +01:00
|
|
|
//#define DEBUG_STACK 1
|
|
|
|
|
2011-08-31 04:28:48 +02:00
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
void *cp;
|
|
|
|
void *fp;
|
|
|
|
void *pc;
|
|
|
|
}
|
|
|
|
STACK_BACKTRACE;
|
|
|
|
|
2012-03-04 00:57:36 +01:00
|
|
|
typedef
|
2012-07-22 02:04:56 +02:00
|
|
|
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
|
|
|
|
VALUE *gp; // GOSUB stack pointer
|
|
|
|
}
|
2013-09-29 18:56:12 +02:00
|
|
|
STACK_CONTEXT;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
#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;
|
2012-03-06 02:50:41 +01:00
|
|
|
//EXTERN size_t STACK_relocate;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2020-11-27 02:24:33 +01:00
|
|
|
EXTERN uint STACK_frame_count;
|
2007-12-30 17:41:49 +01:00
|
|
|
EXTERN STACK_CONTEXT *STACK_frame;
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
EXTERN uintptr_t STACK_process_stack_limit;
|
|
|
|
|
2020-11-27 02:24:33 +01:00
|
|
|
EXTERN uint STACK_frame_barrier;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2014-05-18 23:39:52 +02:00
|
|
|
#define STACK_FOR_EVAL 16
|
|
|
|
|
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
|
2012-03-06 02:50:41 +01:00
|
|
|
|
|
|
|
#define STACK_check(_need) \
|
|
|
|
do { \
|
2013-01-01 12:55:40 +01:00
|
|
|
if (((char *)(SP + (_need)) + sizeof(STACK_CONTEXT)) >= STACK_limit) \
|
2012-03-06 02:50:41 +01:00
|
|
|
THROW_STACK(); \
|
|
|
|
} \
|
|
|
|
while (0);
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
|
|
#endif
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool STACK_has_error_handler(void);
|
2011-08-31 04:28:48 +02:00
|
|
|
|
|
|
|
STACK_BACKTRACE *STACK_get_backtrace(void);
|
2020-01-04 22:11:29 +01:00
|
|
|
STACK_BACKTRACE *STACK_copy_backtrace(STACK_BACKTRACE *bt);
|
2013-03-30 00:33:01 +01:00
|
|
|
#define STACK_free_backtrace(_backtrace) FREE(_backtrace)
|
2011-08-31 04:28:48 +02:00
|
|
|
#define STACK_backtrace_is_end(_bt) ((((intptr_t)((_bt)->cp)) & 1) != 0)
|
2011-09-09 00:04:52 +02:00
|
|
|
#define STACK_backtrace_set_end(_bt) ((_bt)->cp = (void *)(((intptr_t)((_bt)->cp)) | 1))
|
|
|
|
#define STACK_backtrace_clear_end(_bt) ((_bt)->cp = (void *)(((intptr_t)((_bt)->cp)) & ~1))
|
2011-08-31 04:28:48 +02:00
|
|
|
|
|
|
|
|
2020-11-27 02:24:33 +01:00
|
|
|
STACK_CONTEXT *STACK_get_frame(uint frame);
|
2008-03-19 15:32:30 +01:00
|
|
|
|
2020-11-27 02:24:33 +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) *(_dst) = *(_src)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define STACK_push_frame(_context, _need) \
|
|
|
|
({ \
|
|
|
|
int stack; \
|
|
|
|
if ((uintptr_t)&stack < STACK_process_stack_limit) \
|
2012-03-06 02:50:41 +01:00
|
|
|
THROW_STACK(); \
|
2010-06-13 14:03:29 +02:00
|
|
|
\
|
2013-01-01 12:55:40 +01:00
|
|
|
STACK_check(_need); \
|
2010-06-13 14:03:29 +02:00
|
|
|
\
|
2012-05-19 04:55:05 +02:00
|
|
|
STACK_frame--; \
|
|
|
|
\
|
|
|
|
STACK_copy(STACK_frame, _context); \
|
|
|
|
\
|
|
|
|
STACK_frame_count++; \
|
2014-05-18 23:39:52 +02:00
|
|
|
STACK_limit -= sizeof(STACK_CONTEXT); \
|
2010-06-13 14:03:29 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define STACK_pop_frame(_context) \
|
|
|
|
({ \
|
2012-07-22 02:04:56 +02:00
|
|
|
STACK_copy(_context, STACK_frame); \
|
|
|
|
STACK_frame++; \
|
|
|
|
STACK_frame_count--; \
|
2014-05-18 23:39:52 +02:00
|
|
|
STACK_limit += sizeof(STACK_CONTEXT); \
|
2010-06-13 14:03:29 +02:00
|
|
|
})
|
|
|
|
|
2014-05-18 23:39:52 +02:00
|
|
|
#define STACK_enable_for_eval() STACK_limit += STACK_FOR_EVAL * sizeof(VALUE)
|
|
|
|
#define STACK_disable_for_eval() STACK_limit -= STACK_FOR_EVAL * sizeof(VALUE)
|
|
|
|
|
2020-11-27 02:24:33 +01:00
|
|
|
#define STACK_push_barrier() \
|
|
|
|
({ \
|
|
|
|
int old = STACK_frame_barrier; \
|
|
|
|
STACK_frame_barrier = STACK_frame_count + 1; \
|
|
|
|
old; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define STACK_pop_barrier(_old) (STACK_frame_barrier = (_old))
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
#endif
|