2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
gbx_exec.h
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01:00
|
|
|
(c) 2000-2012 Benoît Minisini <gambas@users.sourceforge.net>
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +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
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-12-31 03:39:20 +01: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
|
|
|
|
2011-12-31 03:39:20 +01: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_EXEC_H
|
|
|
|
#define __GBX_EXEC_H
|
|
|
|
|
|
|
|
#include "gb_alloc.h"
|
|
|
|
#include "gb_error.h"
|
|
|
|
#include "gbx_class.h"
|
|
|
|
#include "gbx_value.h"
|
|
|
|
#include "gb_pcode.h"
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
|
|
|
|
#include "gbx_string.h"
|
|
|
|
#include "gbx_object.h"
|
|
|
|
#include "gbx_variant.h"
|
|
|
|
|
|
|
|
#include "gbx_c_enum.h"
|
|
|
|
|
2012-01-31 03:33:01 +01:00
|
|
|
enum { GB_LITTLE_ENDIAN, GB_BIG_ENDIAN };
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2011-08-31 04:28:48 +02:00
|
|
|
void (*EXEC_FUNC)();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
typedef
|
2011-08-31 04:28:48 +02:00
|
|
|
void (*EXEC_FUNC_CODE)(ushort);
|
2010-06-05 01:48:53 +02:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
typedef
|
2011-08-31 04:28:48 +02:00
|
|
|
struct {
|
|
|
|
CLASS *class;
|
|
|
|
OBJECT *object;
|
|
|
|
int index;
|
|
|
|
CLASS_DESC_METHOD *desc;
|
|
|
|
char nparam;
|
|
|
|
bool native;
|
|
|
|
bool use_stack;
|
|
|
|
}
|
|
|
|
EXEC_GLOBAL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
typedef
|
2011-08-31 04:28:48 +02:00
|
|
|
struct {
|
|
|
|
void (*main)();
|
|
|
|
void (*loop)();
|
|
|
|
void (*wait)();
|
|
|
|
void (*timer)();
|
|
|
|
void (*lang)();
|
|
|
|
void (*watch)();
|
|
|
|
void (*post)();
|
|
|
|
void (*quit)();
|
|
|
|
void (*error)();
|
2010-08-27 23:09:34 +02:00
|
|
|
double (*timeout)();
|
2011-08-31 04:28:48 +02:00
|
|
|
}
|
|
|
|
EXEC_HOOK;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-07-10 16:35:17 +02:00
|
|
|
enum {
|
|
|
|
OP_NOTHING = 0,
|
|
|
|
OP_OBJECT_FLOAT,
|
|
|
|
OP_FLOAT_OBJECT,
|
2012-07-14 04:49:57 +02:00
|
|
|
OP_OBJECT_OTHER,
|
|
|
|
OP_OTHER_OBJECT,
|
2012-07-10 16:35:17 +02:00
|
|
|
OP_OBJECT_OBJECT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#ifndef __GBX_EXEC_C
|
|
|
|
|
|
|
|
EXTERN STACK_CONTEXT EXEC_current;
|
|
|
|
EXTERN VALUE *SP;
|
|
|
|
EXTERN VALUE TEMP;
|
|
|
|
EXTERN VALUE RET;
|
|
|
|
|
|
|
|
EXTERN VALUE *EXEC_super;
|
2008-03-19 15:32:30 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
EXTERN bool EXEC_debug;
|
2011-07-24 18:55:09 +02:00
|
|
|
EXTERN bool EXEC_profile;
|
2012-06-10 16:58:45 +02:00
|
|
|
EXTERN const char *EXEC_profile_path;
|
2012-05-23 23:35:58 +02:00
|
|
|
EXTERN bool EXEC_profile_instr;
|
2007-12-30 17:41:49 +01:00
|
|
|
EXTERN bool EXEC_arch;
|
|
|
|
EXTERN bool EXEC_fifo;
|
2009-05-22 16:52:36 +02:00
|
|
|
EXTERN const char *EXEC_fifo_name;
|
2008-03-19 15:32:30 +01:00
|
|
|
EXTERN bool EXEC_keep_library;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
EXTERN EXEC_HOOK EXEC_Hook;
|
|
|
|
|
|
|
|
EXTERN CENUM *EXEC_enum;
|
|
|
|
|
|
|
|
EXTERN bool EXEC_big_endian;
|
|
|
|
EXTERN bool EXEC_main_hook_done;
|
2008-01-25 16:01:02 +01:00
|
|
|
EXTERN bool EXEC_got_error;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
EXTERN const char EXEC_should_borrow[];
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
EXTERN const char *EXEC_unknown_name;
|
|
|
|
EXTERN char EXEC_unknown_nparam;
|
|
|
|
|
|
|
|
EXTERN EXEC_GLOBAL EXEC;
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif
|
|
|
|
|
2011-10-28 03:54:10 +02:00
|
|
|
// Local variables base pointer
|
2007-12-30 17:41:49 +01:00
|
|
|
#define BP EXEC_current.bp
|
2011-10-28 03:54:10 +02:00
|
|
|
// Arguments base pointer
|
|
|
|
#define PP EXEC_current.pp
|
|
|
|
// Current class
|
2007-12-30 17:41:49 +01:00
|
|
|
#define CP EXEC_current.cp
|
2011-10-28 03:54:10 +02:00
|
|
|
// Current object
|
2007-12-30 17:41:49 +01:00
|
|
|
#define OP EXEC_current.op
|
2011-10-28 03:54:10 +02:00
|
|
|
// Save stack pointer for a TRY
|
2007-12-30 17:41:49 +01:00
|
|
|
#define EP EXEC_current.ep
|
2011-10-28 03:54:10 +02:00
|
|
|
// Current function
|
2007-12-30 17:41:49 +01:00
|
|
|
#define FP EXEC_current.fp
|
2011-10-28 03:54:10 +02:00
|
|
|
// Program counter
|
2007-12-30 17:41:49 +01:00
|
|
|
#define PC EXEC_current.pc
|
2011-10-28 03:54:10 +02:00
|
|
|
// Where to go if there is an error
|
2007-12-30 17:41:49 +01:00
|
|
|
#define EC EXEC_current.ec
|
2011-10-28 03:54:10 +02:00
|
|
|
// Save register for TRY
|
2007-12-30 17:41:49 +01:00
|
|
|
#define ET EXEC_current.et
|
2011-10-28 03:54:10 +02:00
|
|
|
// Last break in the function
|
2007-12-30 17:41:49 +01:00
|
|
|
#define TC EXEC_current.tc
|
2011-10-28 03:54:10 +02:00
|
|
|
// Stack at the last break in the function
|
2007-12-30 17:41:49 +01:00
|
|
|
#define TP EXEC_current.tp
|
2012-03-04 00:57:36 +01:00
|
|
|
// GoSub stack
|
|
|
|
#define GP EXEC_current.gp
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-10-28 03:54:10 +02:00
|
|
|
// Function return value pointer
|
2007-12-30 17:41:49 +01:00
|
|
|
#define RP (&RET)
|
|
|
|
|
|
|
|
#define HOOK(func) (!EXEC_Hook.func) ? 0 : (*EXEC_Hook.func)
|
|
|
|
#define HOOK_DEFAULT(func, def) (*((!EXEC_Hook.func) ? def : EXEC_Hook.func))
|
|
|
|
|
2010-06-15 08:54:38 +02:00
|
|
|
#define GET_NPARAM(var) short var = code & 0x3F
|
2007-12-30 17:41:49 +01:00
|
|
|
#define GET_PARAM(var, nparam) VALUE *var = &SP[-nparam]
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_init(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_enter_check(bool defined);
|
|
|
|
void EXEC_enter(void);
|
|
|
|
void EXEC_enter_quick(void);
|
2011-09-08 22:08:33 +02:00
|
|
|
void EXEC_leave_keep();
|
|
|
|
void EXEC_leave_drop();
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_loop(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
#define EXEC_object(_val, _pclass, _pobject) \
|
|
|
|
((LIKELY(TYPE_is_pure_object((_val)->type))) ? (*(_pclass) = EXEC_object_real(_val, _pobject)), TRUE : \
|
|
|
|
TYPE_is_variant((_val)->type) ? (*(_pclass) = EXEC_object_variant(_val, _pobject)), FALSE : \
|
|
|
|
EXEC_object_other(_val, _pclass, _pobject))
|
2010-06-18 02:14:53 +02:00
|
|
|
|
|
|
|
#define EXEC_object_fast(_val, _pclass, _pobject) \
|
|
|
|
({ \
|
|
|
|
if ((_val)->type != T_CLASS) \
|
|
|
|
(*(_pclass)) = EXEC_object_real(_val, _pobject); \
|
|
|
|
else \
|
|
|
|
EXEC_object_other(_val, _pclass, _pobject); \
|
|
|
|
})
|
2010-06-13 14:03:29 +02:00
|
|
|
|
|
|
|
CLASS *EXEC_object_real(VALUE *val, OBJECT **pobject);
|
|
|
|
CLASS *EXEC_object_variant(VALUE *val, OBJECT **pobject);
|
|
|
|
bool EXEC_object_other(VALUE *val, CLASS **pclass, OBJECT **pobject);
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *EXEC_auto_create(CLASS *class, bool ref);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
bool EXEC_call_native(void (*exec)(), void *object, TYPE type, VALUE *param);
|
2008-01-27 15:00:04 +01:00
|
|
|
void EXEC_native_check(bool defined);
|
|
|
|
void EXEC_native_quick(void);
|
2010-06-18 02:14:53 +02:00
|
|
|
void EXEC_native(void);
|
|
|
|
void EXEC_function_real(void);
|
2012-05-23 21:26:15 +02:00
|
|
|
void EXEC_jit_function_loop(void);
|
2010-06-18 02:14:53 +02:00
|
|
|
void EXEC_function_loop(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-05-10 17:17:07 +02:00
|
|
|
#define EXEC_function() EXEC_function_real(), EXEC_release_return_value()
|
|
|
|
#define EXEC_function_keep() EXEC_function_real()
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_public(CLASS *class, void *object, const char *name, int nparam);
|
2010-01-01 15:55:13 +01:00
|
|
|
void EXEC_public_desc(CLASS *class, void *object, CLASS_DESC_METHOD *desc, int nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2011-09-09 03:50:57 +02:00
|
|
|
bool EXEC_special(int special, CLASS *class, void *object, int nparam, bool drop);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-07-08 21:57:50 +02:00
|
|
|
void EXEC_special_inheritance(int special, CLASS *class, OBJECT *object, int nparam, bool drop);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_nop(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_push_unknown(ushort code);
|
2008-01-24 02:36:20 +01:00
|
|
|
void EXEC_push_array(ushort code);
|
2008-01-17 22:39:26 +01:00
|
|
|
//void EXEC_push_special(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_pop_unknown(void);
|
2008-01-24 02:36:20 +01:00
|
|
|
void EXEC_pop_array(ushort code);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_enum_first(PCODE code);
|
|
|
|
bool EXEC_enum_next(PCODE code);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void *EXEC_create_object(CLASS *class, int np, char *event);
|
|
|
|
void EXEC_new(void);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
void EXEC_release_return_value(void);
|
|
|
|
void EXEC_quit(void);
|
|
|
|
|
|
|
|
void EXEC_dup(int n);
|
|
|
|
|
|
|
|
void EXEC_borrow(TYPE type, VALUE *val);
|
2008-01-17 22:39:26 +01:00
|
|
|
void UNBORROW(VALUE *val);
|
2008-03-11 14:29:47 +01:00
|
|
|
void EXEC_release(TYPE type, VALUE *val);
|
2008-01-17 22:39:26 +01:00
|
|
|
void RELEASE_many(VALUE *val, int n);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2012-07-09 01:23:24 +02:00
|
|
|
void EXEC_push_complex(void);
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
#define BORROW(_value) \
|
2010-05-19 14:43:57 +02:00
|
|
|
do { \
|
2008-03-11 14:29:47 +01:00
|
|
|
VALUE *_v = (_value); \
|
|
|
|
TYPE type = _v->type; \
|
|
|
|
if (TYPE_is_object(type)) \
|
|
|
|
{ \
|
|
|
|
OBJECT_REF(_v->_object.object, "BORROW"); \
|
|
|
|
} \
|
2010-06-05 01:48:53 +02:00
|
|
|
else if (EXEC_should_borrow[type]) \
|
2010-06-15 08:54:38 +02:00
|
|
|
{ \
|
|
|
|
if (type == T_STRING) \
|
|
|
|
STRING_ref(_v->_string.addr); \
|
|
|
|
else \
|
|
|
|
EXEC_borrow(type, _v); \
|
|
|
|
} \
|
2010-05-19 14:43:57 +02:00
|
|
|
} while (0)
|
2008-03-11 14:29:47 +01:00
|
|
|
|
|
|
|
#define RELEASE(_value) \
|
2008-05-12 18:09:33 +02:00
|
|
|
do { \
|
2008-03-11 14:29:47 +01:00
|
|
|
VALUE *_v = (_value); \
|
|
|
|
TYPE type = _v->type; \
|
|
|
|
if (TYPE_is_object(type)) \
|
|
|
|
{ \
|
2008-08-14 21:42:27 +02:00
|
|
|
OBJECT_UNREF(_v->_object.object, "RELEASE"); \
|
2008-03-11 14:29:47 +01:00
|
|
|
} \
|
2010-06-05 01:48:53 +02:00
|
|
|
else if (EXEC_should_borrow[type]) \
|
2010-06-15 08:54:38 +02:00
|
|
|
{ \
|
|
|
|
if (type == T_STRING) \
|
|
|
|
STRING_unref(&_v->_string.addr); \
|
|
|
|
else \
|
|
|
|
EXEC_release(type, _v); \
|
|
|
|
} \
|
2008-05-12 18:09:33 +02:00
|
|
|
} while (0)
|
2008-03-11 14:29:47 +01:00
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
#define RELEASE_STRING(_value) \
|
|
|
|
do { \
|
2010-06-09 01:08:04 +02:00
|
|
|
if ((_value)->type == T_STRING) STRING_unref(&(_value)->_string.addr); \
|
2010-05-22 20:02:34 +02:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define RELEASE_OBJECT(_value) \
|
|
|
|
do { \
|
|
|
|
VALUE *_v = (_value); \
|
|
|
|
OBJECT_UNREF(_v->_object.object, "RELEASE_OBJECT"); \
|
|
|
|
} while (0)
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#define RELEASE_MANY(_val, _n) \
|
2008-05-12 18:09:33 +02:00
|
|
|
do { \
|
2011-08-31 04:28:48 +02:00
|
|
|
if (_n) \
|
|
|
|
{ \
|
|
|
|
if ((_n) == 1) \
|
|
|
|
{ \
|
|
|
|
_val--; \
|
|
|
|
RELEASE((_val)); \
|
|
|
|
} \
|
|
|
|
else \
|
|
|
|
{ \
|
|
|
|
RELEASE_many((_val), (_n)); \
|
|
|
|
_val -= (_n); \
|
|
|
|
} \
|
|
|
|
} \
|
2008-05-12 18:09:33 +02:00
|
|
|
} while (0)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
#define PUSH() \
|
2008-05-12 18:09:33 +02:00
|
|
|
do { \
|
2008-03-11 14:29:47 +01:00
|
|
|
BORROW(SP); \
|
|
|
|
SP++; \
|
2008-05-12 18:09:33 +02:00
|
|
|
} while (0)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
#define POP() \
|
2008-05-12 18:09:33 +02:00
|
|
|
do { \
|
2011-08-31 04:28:48 +02:00
|
|
|
SP--; \
|
|
|
|
RELEASE(SP); \
|
2008-05-12 18:09:33 +02:00
|
|
|
} while (0)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
#define COPY_VALUE(_dst, _src) VALUE_copy(_dst, _src)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-08-29 22:51:10 +02:00
|
|
|
#define EXEC_set_native_error(_err) (ERROR_current->info.native = (_err))
|
|
|
|
#define EXEC_has_native_error() (ERROR_current->info.native)
|
|
|
|
|
2012-07-14 17:18:22 +02:00
|
|
|
bool EXEC_check_operator_single(VALUE *P1, uchar op);
|
|
|
|
int EXEC_check_operator(VALUE *P1, VALUE *P2, uchar op);
|
2012-07-10 16:35:17 +02:00
|
|
|
void EXEC_operator(uchar what, uchar op, VALUE *P1, VALUE *P2);
|
|
|
|
void EXEC_operator_object_add_quick(VALUE *P1, double val);
|
|
|
|
bool EXEC_comparator(uchar what, uchar op, VALUE *P1, VALUE *P2);
|
|
|
|
void EXEC_operator_object_abs(VALUE *P1);
|
|
|
|
void EXEC_operator_object_single(uchar op, VALUE *P1);
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
#endif /* */
|