2007-12-30 17:41:49 +01:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
|
|
gbx_exec.c
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
|
|
#define __GBX_EXEC_C
|
|
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
|
#include "gb_error.h"
|
|
|
|
|
#include "gbx_type.h"
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
|
|
#include "gb_limit.h"
|
|
|
|
|
#include "gbx_subr.h"
|
|
|
|
|
#include "gbx_stack.h"
|
|
|
|
|
#include "gbx_debug.h"
|
2010-12-21 15:05:42 +01:00
|
|
|
|
#include "gbx_event.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#include "gbx_string.h"
|
|
|
|
|
#include "gbx_date.h"
|
|
|
|
|
|
|
|
|
|
#include "gbx_c_collection.h"
|
|
|
|
|
|
|
|
|
|
#include "gbx_api.h"
|
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
//#define DEBUG_STACK 1
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* Current virtual machine state */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
STACK_CONTEXT EXEC_current = { 0 };
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* Stack pointer */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
VALUE *SP = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* Temporary storage or return value of a native function */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
VALUE TEMP;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* Return value of a gambas function */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
VALUE RET;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* SUPER was used for this stack pointer */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
VALUE *EXEC_super = NULL;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* CPU endianness */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
bool EXEC_big_endian;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
/* Current iterator */
|
2008-01-17 22:39:26 +01:00
|
|
|
|
CENUM *EXEC_enum;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
|
bool EXEC_debug = FALSE; // debugging mode
|
|
|
|
|
bool EXEC_arch = FALSE; // executing an archive
|
|
|
|
|
bool EXEC_fifo = FALSE; // debugging through a fifo
|
2009-05-22 16:52:36 +02:00
|
|
|
|
const char *EXEC_fifo_name = NULL; // fifo name
|
2008-03-19 15:32:30 +01:00
|
|
|
|
bool EXEC_keep_library = FALSE; // do not unload libraries
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
EXEC_HOOK EXEC_Hook = { NULL };
|
2010-06-18 02:14:53 +02:00
|
|
|
|
EXEC_GLOBAL EXEC;
|
2008-01-17 22:39:26 +01:00
|
|
|
|
bool EXEC_main_hook_done = FALSE;
|
|
|
|
|
int EXEC_return_value = 0;
|
2008-01-25 16:01:02 +01:00
|
|
|
|
bool EXEC_got_error = FALSE;
|
2008-02-24 17:29:02 +01:00
|
|
|
|
uint64_t EXEC_byref = 0;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-15 08:54:38 +02:00
|
|
|
|
const char EXEC_should_borrow[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, 0, 0 };
|
2010-06-05 01:48:53 +02:00
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
const char *EXEC_unknown_name;
|
|
|
|
|
bool EXEC_unknown_property;
|
|
|
|
|
char EXEC_unknown_nparam;
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_init(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2009-11-28 02:22:00 +01:00
|
|
|
|
union {
|
|
|
|
|
char _string[4];
|
|
|
|
|
uint _int;
|
|
|
|
|
}
|
|
|
|
|
test;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
PC = NULL;
|
|
|
|
|
BP = NULL;
|
|
|
|
|
OP = NULL;
|
|
|
|
|
CP = NULL;
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
|
test._string[0] = 0xAA;
|
|
|
|
|
test._string[1] = 0xBB;
|
|
|
|
|
test._string[2] = 0xCC;
|
|
|
|
|
test._string[3] = 0xDD;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2009-11-28 02:22:00 +01:00
|
|
|
|
EXEC_big_endian = test._int == 0xAABBCCDDL;
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
if (EXEC_big_endian)
|
2010-08-28 14:33:05 +02:00
|
|
|
|
ERROR_warning("CPU is big endian");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
DATE_init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
|
void EXEC_borrow(TYPE type, VALUE *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-03-20 00:50:34 +01:00
|
|
|
|
static const void *jump[16] = {
|
2007-12-30 17:41:49 +01:00
|
|
|
|
&&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE,
|
2010-05-19 14:43:57 +02:00
|
|
|
|
&&__STRING, &&__NONE, &&__NONE, &&__VARIANT, &&__FUNCTION, &&__NONE, &&__NONE
|
2007-12-30 17:41:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
if (value->_variant.vtype == T_STRING)
|
2009-11-28 02:22:00 +01:00
|
|
|
|
STRING_ref(value->_variant.value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
else if (TYPE_is_object(value->_variant.vtype))
|
2009-11-28 02:22:00 +01:00
|
|
|
|
OBJECT_REF(value->_variant.value._object, "BORROW");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
|
|
|
|
OBJECT_REF(value->_function.object, "BORROW");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
STRING_ref(value->_string.addr);
|
|
|
|
|
|
|
|
|
|
__NONE:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void UNBORROW(VALUE *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-03-20 00:50:34 +01:00
|
|
|
|
static const void *jump[16] = {
|
2007-12-30 17:41:49 +01:00
|
|
|
|
&&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE,
|
2010-05-19 14:43:57 +02:00
|
|
|
|
&&__STRING, &&__NONE, &&__NONE, &&__VARIANT, &&__FUNCTION, &&__NONE, &&__NONE
|
2007-12-30 17:41:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TYPE type = value->type;
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(TYPE_is_object(type)))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF_KEEP(value->_object.object, "UNBORROW");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
if (value->_variant.vtype == T_STRING)
|
2009-11-28 02:22:00 +01:00
|
|
|
|
STRING_unref_keep(&value->_variant.value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
else if (TYPE_is_object(value->_variant.vtype))
|
2009-11-28 02:22:00 +01:00
|
|
|
|
OBJECT_UNREF_KEEP(value->_variant.value._object, "UNBORROW");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF_KEEP(value->_function.object, "UNBORROW");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
STRING_unref_keep(&value->_string.addr);
|
|
|
|
|
|
|
|
|
|
__NONE:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-03-11 14:29:47 +01:00
|
|
|
|
void EXEC_release(TYPE type, VALUE *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-03-20 00:50:34 +01:00
|
|
|
|
static const void *jump[16] = {
|
2007-12-30 17:41:49 +01:00
|
|
|
|
&&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE,
|
2010-05-19 14:43:57 +02:00
|
|
|
|
&&__STRING, &&__NONE, &&__NONE, &&__VARIANT, &&__FUNCTION, &&__NONE, &&__NONE
|
2007-12-30 17:41:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
if (value->_variant.vtype == T_STRING)
|
2009-11-28 02:22:00 +01:00
|
|
|
|
STRING_unref(&value->_variant.value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
else if (TYPE_is_object(value->_variant.vtype))
|
2009-11-28 02:22:00 +01:00
|
|
|
|
OBJECT_UNREF(value->_variant.value._object, "RELEASE");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(value->_function.object, "RELEASE");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
STRING_unref(&value->_string.addr);
|
|
|
|
|
|
|
|
|
|
__NONE:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void RELEASE_many(VALUE *value, int n)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-03-20 00:50:34 +01:00
|
|
|
|
static const void *jump[16] = {
|
2007-12-30 17:41:49 +01:00
|
|
|
|
&&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE,
|
2010-05-19 14:43:57 +02:00
|
|
|
|
&&__STRING, &&__NONE, &&__NONE, &&__VARIANT, &&__FUNCTION, &&__NONE, &&__NONE
|
2007-12-30 17:41:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TYPE type;
|
|
|
|
|
|
|
|
|
|
while (n)
|
|
|
|
|
{
|
|
|
|
|
n--;
|
|
|
|
|
value--;
|
|
|
|
|
|
|
|
|
|
type = value->type;
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(TYPE_is_object(type)))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(value->_object.object, "RELEASE");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
if (value->_variant.vtype == T_STRING)
|
2009-11-28 02:22:00 +01:00
|
|
|
|
STRING_unref(&value->_variant.value._string);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
else if (TYPE_is_object(value->_variant.vtype))
|
2009-11-28 02:22:00 +01:00
|
|
|
|
OBJECT_UNREF(value->_variant.value._object, "RELEASE");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(value->_function.object, "RELEASE");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
STRING_unref(&value->_string.addr);
|
|
|
|
|
|
|
|
|
|
__NONE:
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void DUMP(VALUE *value)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
static void *jump[16] = {
|
|
|
|
|
&&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE, &&__NONE,
|
|
|
|
|
&&__STRING, &&__NONE, &&__VARIANT, &&__ARRAY, &&__NONE, &&__FUNCTION, &&__NONE, &&__NONE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TYPE type = value->type;
|
|
|
|
|
|
|
|
|
|
printf("type = %p / ", (void *)type);
|
|
|
|
|
|
|
|
|
|
if (TYPE_is_object(type))
|
|
|
|
|
goto __OBJECT;
|
|
|
|
|
else
|
|
|
|
|
goto *jump[type];
|
|
|
|
|
|
|
|
|
|
__STRING:
|
|
|
|
|
printf("STRING %p\n", value->_string.addr);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
if (value->_object.object)
|
|
|
|
|
{
|
|
|
|
|
printf("OBJECT (%p)\n", value->_object.object);
|
|
|
|
|
printf("-> %s\n", OBJECT_class(value->_object.object)->name);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
printf("OBJECT (NULL)\n");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__VARIANT:
|
|
|
|
|
if (value->_variant.vtype == T_STRING)
|
|
|
|
|
printf("STRING %p\n", *((char **)value->_variant.value));
|
|
|
|
|
else if (TYPE_is_object(value->_variant.vtype))
|
|
|
|
|
printf("OBJECT (%s %p)\n", OBJECT_class(*((void **)value->_variant.value))->name, *((void **)value->_variant.value));
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
|
|
|
|
printf("FUNCTION %s (%s %p)\n", value->_function.class->name, OBJECT_class(value->_function.object)->name, value->_function.object);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__ARRAY:
|
|
|
|
|
printf("ARRAY\n");
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
__NONE:
|
|
|
|
|
printf("\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_release_return_value(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
RELEASE(RP);
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define print_register() \
|
|
|
|
|
printf("| SP = %d BP = %d FP = %p PC = %p EC = %p\n", SP - (VALUE *)STACK_base, BP - (VALUE *)STACK_base, FP, PC, EC)
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
static ushort exec_enter_can_quick(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FUNCTION *func;
|
|
|
|
|
int nparam = EXEC.nparam;
|
|
|
|
|
|
|
|
|
|
func = &EXEC.class->load->func[EXEC.index];
|
|
|
|
|
|
|
|
|
|
/* check number of arguments */
|
|
|
|
|
|
|
|
|
|
if (func->npmin < func->n_param || nparam != func->n_param || func->vararg)
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_SLOW;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* check arguments type */
|
2010-06-18 02:14:53 +02:00
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
for (i = 0; i < nparam; i++)
|
|
|
|
|
{
|
|
|
|
|
if (SP[i - nparam].type != func->param[i].type)
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_SLOW;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_QUICK;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
static void init_local_var(CLASS *class, FUNCTION *func)
|
2008-03-20 00:50:34 +01:00
|
|
|
|
{
|
2010-06-06 22:43:13 +02:00
|
|
|
|
static const void *jump[] = {
|
|
|
|
|
&&__VOID, &&__BOOLEAN, &&__BYTE, &&__SHORT, &&__INTEGER, &&__LONG, &&__SINGLE, &&__FLOAT,
|
|
|
|
|
&&__DATE, &&__STRING, &&__STRING, &&__POINTER, &&__VARIANT, &&__FUNCTION, &&__CLASS, &&__NULL,
|
|
|
|
|
&&__OBJECT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CLASS_LOCAL *local;
|
|
|
|
|
int n;
|
|
|
|
|
CTYPE ctype;
|
|
|
|
|
VALUE *value;
|
|
|
|
|
|
|
|
|
|
local = func->local;
|
|
|
|
|
value = SP;
|
|
|
|
|
|
|
|
|
|
for (n = func->n_local; n; n--, value++, local++)
|
|
|
|
|
{
|
|
|
|
|
ctype = local->type;
|
|
|
|
|
|
|
|
|
|
value->type = ctype.id;
|
|
|
|
|
goto *jump[ctype.id];
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__BOOLEAN:
|
|
|
|
|
__BYTE:
|
|
|
|
|
__SHORT:
|
|
|
|
|
__INTEGER:
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
value->_integer.value = 0;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__LONG:
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
value->_long.value = 0;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__SINGLE:
|
2010-11-16 02:49:18 +01:00
|
|
|
|
value->_single.value = 0;
|
|
|
|
|
continue;
|
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__FLOAT:
|
|
|
|
|
value->_float.value = 0;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__STRING:
|
|
|
|
|
value->_string.addr = NULL;
|
|
|
|
|
value->_string.start = 0;
|
|
|
|
|
value->_string.len = 0;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__VARIANT:
|
|
|
|
|
value->_variant.vtype = T_NULL;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__POINTER:
|
|
|
|
|
value->_pointer.value = NULL;
|
|
|
|
|
continue;
|
2010-05-19 14:43:57 +02:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__DATE:
|
|
|
|
|
value->_date.date = 0;
|
|
|
|
|
value->_date.time = 0;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__VOID:
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__OBJECT:
|
|
|
|
|
if (ctype.value >= 0)
|
|
|
|
|
value->type = (TYPE)class->load->class_ref[ctype.value];
|
|
|
|
|
value->_object.object = NULL;
|
|
|
|
|
continue;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2010-06-06 22:43:13 +02:00
|
|
|
|
__FUNCTION:
|
|
|
|
|
__CLASS:
|
|
|
|
|
__NULL:
|
|
|
|
|
ERROR_panic("VALUE_default: Unknown default type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP = value;
|
2008-03-20 00:50:34 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
// EXEC.nparam must be set to the amount of stack that must be freed if an exception is raised during EXEC_enter()
|
2008-03-20 00:50:34 +01:00
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_enter(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FUNCTION *func; // = EXEC.func;
|
|
|
|
|
int nparam = EXEC.nparam;
|
|
|
|
|
void *object = EXEC.object;
|
|
|
|
|
CLASS *class = EXEC.class;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("\n| >> EXEC_enter(%s, %ld, %d)\n", EXEC.class->name, EXEC.index, nparam);
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
func_id = value->index;
|
|
|
|
|
|
|
|
|
|
if (value->kind & FUNCTION_PUBLIC)
|
|
|
|
|
func_id = (int)(class->table[func_id].desc.method->exec;
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
func = &class->load->func[EXEC.index];
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
if (func->debug)
|
|
|
|
|
printf(" | >> %s\n", func->debug->name);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* check number of arguments */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(nparam < func->npmin))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
THROW(E_NEPARAM);
|
2010-05-19 22:18:23 +02:00
|
|
|
|
else if (UNLIKELY(nparam > func->n_param && !func->vararg))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
THROW(E_TMPARAM);
|
|
|
|
|
|
|
|
|
|
/* mandatory arguments */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < func->npmin; i++)
|
|
|
|
|
{
|
|
|
|
|
VALUE_conv(SP - nparam + i, func->param[i].type);
|
|
|
|
|
/*BORROW(SP - nparam + i);*/
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(func->npmin < func->n_param))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
/* optional arguments */
|
|
|
|
|
|
|
|
|
|
for (i = func->npmin; i < nparam; i++)
|
|
|
|
|
{
|
|
|
|
|
if (SP[- nparam + i].type == T_VOID)
|
|
|
|
|
SP[- nparam + i]._void.ptype = func->param[i].type;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VALUE_conv(SP - nparam + i, func->param[i].type);
|
|
|
|
|
/*BORROW(SP - nparam + i);*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* missing optional arguments */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(nparam < func->n_param))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
STACK_check(func->n_param - nparam);
|
|
|
|
|
|
|
|
|
|
for (i = nparam; i < func->n_param; i++)
|
|
|
|
|
{
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP->_void.ptype = func->param[i].type;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
2010-01-01 15:55:13 +01:00
|
|
|
|
|
|
|
|
|
EXEC.nparam = func->n_param;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-31 00:32:38 +01:00
|
|
|
|
/* save context & check stack*/
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-10-31 00:32:38 +01:00
|
|
|
|
STACK_push_frame(&EXEC_current, func->stack_usage);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* enter function */
|
|
|
|
|
|
|
|
|
|
BP = SP;
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(func->vararg))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
PP = SP - (nparam - func->n_param);
|
|
|
|
|
else
|
|
|
|
|
PP = SP;
|
|
|
|
|
FP = func;
|
|
|
|
|
PC = func->code;
|
|
|
|
|
OP = object;
|
|
|
|
|
CP = class;
|
|
|
|
|
//AP = ARCH_from_class(CP);
|
|
|
|
|
EP = NULL;
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(func->error))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
|
|
|
|
printf("EXEC_enter: EC = PC + %d\n", func->error);
|
|
|
|
|
#endif
|
|
|
|
|
EC = PC + func->error;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
EC = NULL;
|
|
|
|
|
|
|
|
|
|
/* reference the object so that it is not destroyed during the function call */
|
|
|
|
|
OBJECT_REF(OP, "EXEC_enter");
|
|
|
|
|
|
|
|
|
|
/*printf("PC = %p nparam = %d\n", PC, FP->n_param);*/
|
|
|
|
|
|
|
|
|
|
/* local variables initialization */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(func->n_local > 0))
|
2010-06-06 22:43:13 +02:00
|
|
|
|
init_local_var(class, func);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* control variables initialization */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(func->n_ctrl > 0))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < func->n_ctrl; i++)
|
|
|
|
|
{
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*printf("EXEC_enter: nparam = %d nlocal = %d nctrl = %d\n", func->n_param, func->n_local, func->n_ctrl);*/
|
|
|
|
|
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_enter()\n");
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_enter_check(bool defined)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
ushort mode = defined ? exec_enter_can_quick() : C_CALL_SLOW;
|
|
|
|
|
|
|
|
|
|
*PC = (*PC & 0xFF) | mode;
|
|
|
|
|
|
|
|
|
|
switch(mode)
|
2008-01-27 15:00:04 +01:00
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
case C_CALL_QUICK: EXEC_enter_quick(); break;
|
|
|
|
|
//case C_CALL_EASY: EXEC_enter_easy(); break;
|
|
|
|
|
default: EXEC_enter(); break;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_enter_quick(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FUNCTION *func;;
|
|
|
|
|
void *object = EXEC.object;
|
|
|
|
|
CLASS *class = EXEC.class;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
2009-05-18 14:00:48 +02:00
|
|
|
|
printf("\n| >> EXEC_enter_quick(%s, %ld, %d)\n", EXEC.class->name, EXEC.index, EXEC.nparam);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
func = &class->load->func[EXEC.index];
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
if (func->debug)
|
|
|
|
|
printf(" | >> %s\n", func->debug->name);
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-10-31 00:32:38 +01:00
|
|
|
|
/* save context & check stack */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-10-31 00:32:38 +01:00
|
|
|
|
STACK_push_frame(&EXEC_current, func->stack_usage);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* enter function */
|
|
|
|
|
|
|
|
|
|
BP = SP;
|
|
|
|
|
PP = SP;
|
|
|
|
|
FP = func;
|
|
|
|
|
PC = func->code;
|
|
|
|
|
OP = object;
|
|
|
|
|
CP = class;
|
|
|
|
|
EP = NULL;
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(func->error))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
EC = PC + func->error;
|
|
|
|
|
else
|
|
|
|
|
EC = NULL;
|
|
|
|
|
|
|
|
|
|
/* reference the object so that it is not destroyed during the function call */
|
2009-05-18 14:00:48 +02:00
|
|
|
|
OBJECT_REF(OP, "EXEC_enter_quick");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* local variables initialization */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(func->n_local != 0))
|
2010-06-06 22:43:13 +02:00
|
|
|
|
init_local_var(class, func);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
/* control variables initialization */
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(func->n_ctrl != 0))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < func->n_ctrl; i++)
|
|
|
|
|
{
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_enter()\n");
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
#if 0
|
|
|
|
|
void EXEC_enter_easy(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
FUNCTION *func;;
|
|
|
|
|
int nparam = EXEC.nparam;
|
|
|
|
|
void *object = EXEC.object;
|
|
|
|
|
CLASS *class = EXEC.class;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("\n| >> EXEC_enter_quick(%s, %ld, %d)\n", EXEC.class->name, EXEC.index, EXEC.nparam);
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
func = &class->load->func[EXEC.index];
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
if (func->debug)
|
|
|
|
|
printf(" | >> %s\n", func->debug->name);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < func->npmin; i++)
|
|
|
|
|
{
|
|
|
|
|
VALUE_conv(SP - nparam + i, func->param[i].type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* save context & check stack */
|
|
|
|
|
|
|
|
|
|
STACK_push_frame(&EXEC_current, func->stack_usage);
|
|
|
|
|
|
|
|
|
|
/* enter function */
|
|
|
|
|
|
|
|
|
|
BP = SP;
|
|
|
|
|
PP = SP;
|
|
|
|
|
FP = func;
|
|
|
|
|
PC = func->code;
|
|
|
|
|
OP = object;
|
|
|
|
|
CP = class;
|
|
|
|
|
EP = NULL;
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(func->error))
|
|
|
|
|
EC = PC + func->error;
|
|
|
|
|
else
|
|
|
|
|
EC = NULL;
|
|
|
|
|
|
|
|
|
|
/* reference the object so that it is not destroyed during the function call */
|
|
|
|
|
OBJECT_REF(OP, "EXEC_enter_quick");
|
|
|
|
|
|
|
|
|
|
/* local variables initialization */
|
|
|
|
|
|
|
|
|
|
if (LIKELY(func->n_local != 0))
|
|
|
|
|
init_local_var(class, func);
|
|
|
|
|
|
|
|
|
|
/* control variables initialization */
|
|
|
|
|
|
|
|
|
|
if (LIKELY(func->n_ctrl != 0))
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; i < func->n_ctrl; i++)
|
|
|
|
|
{
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_enter()\n");
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
void EXEC_leave(bool drop)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-01-19 18:52:05 +01:00
|
|
|
|
int n, nb, i, nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
bool keep_ret_value = FALSE;
|
|
|
|
|
VALUE ret;
|
2008-01-19 18:52:05 +01:00
|
|
|
|
ushort *pc;
|
2008-02-24 17:29:02 +01:00
|
|
|
|
VALUE *xp, *pp;
|
|
|
|
|
int bit, nbyref;
|
|
|
|
|
ushort *pc_func;
|
|
|
|
|
int nbyref_func;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| >> EXEC_leave\n");
|
|
|
|
|
print_register();
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
/* Save the return value. It can be erased by OBJECT_UNREF() */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
|
//ret = *RP;
|
|
|
|
|
VALUE_copy(&ret, RP);
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
pc = STACK_get_previous_pc();
|
|
|
|
|
nb = 0;
|
|
|
|
|
nparam = FP->n_param;
|
|
|
|
|
|
|
|
|
|
/* ByRef arguments management */
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(!(pc && PCODE_is(pc[1], C_BYREF))))
|
2008-02-24 17:29:02 +01:00
|
|
|
|
goto __LEAVE_NORMAL;
|
2008-01-19 18:52:05 +01:00
|
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
|
pc++;
|
|
|
|
|
nbyref = 1 + (*pc & 0xF);
|
|
|
|
|
pc_func = FP->code;
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(!PCODE_is(*pc_func, C_BYREF)))
|
2008-02-24 17:29:02 +01:00
|
|
|
|
goto __LEAVE_NORMAL;
|
|
|
|
|
|
|
|
|
|
nbyref_func = 1 + (*pc_func & 0xF);
|
|
|
|
|
if (nbyref_func < nbyref)
|
|
|
|
|
goto __LEAVE_NORMAL;
|
2008-01-19 18:52:05 +01:00
|
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
|
for (i = 1; i <= nbyref; i++)
|
|
|
|
|
{
|
|
|
|
|
if (pc[i] & ~pc_func[i])
|
|
|
|
|
goto __LEAVE_NORMAL;
|
2008-01-19 18:52:05 +01:00
|
|
|
|
}
|
2008-02-24 17:29:02 +01:00
|
|
|
|
|
|
|
|
|
xp = PP - nparam;
|
|
|
|
|
pp = xp;
|
|
|
|
|
|
|
|
|
|
for (i = 0, n = 0; i < nparam; i++)
|
2008-01-19 18:52:05 +01:00
|
|
|
|
{
|
2008-02-24 17:29:02 +01:00
|
|
|
|
bit = i & 15;
|
|
|
|
|
if (bit == 0)
|
|
|
|
|
n++;
|
|
|
|
|
|
|
|
|
|
if (n <= nbyref && (pc[n] & (1 << bit)))
|
|
|
|
|
{
|
|
|
|
|
//printf("pp[%d] -> pp[%d]\n", i, nb);
|
|
|
|
|
xp[nb] = *pp;
|
|
|
|
|
nb++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//printf("pp[%d] release (%d)\n", i, pp->type);
|
|
|
|
|
RELEASE(pp);
|
|
|
|
|
}
|
|
|
|
|
pp++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pc--;
|
|
|
|
|
n = SP - PP;
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("release = %d, nparam = %d, byref = %d\n", n, FP->n_param, nb);
|
|
|
|
|
#endif
|
|
|
|
|
RELEASE_MANY(SP, n);
|
|
|
|
|
SP -= nparam;
|
|
|
|
|
SP += nb;
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(OP, "EXEC_leave");
|
2008-02-24 17:29:02 +01:00
|
|
|
|
SP -= nb;
|
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
|
PC += nbyref + 1;
|
|
|
|
|
goto __RETURN_VALUE;
|
|
|
|
|
|
|
|
|
|
__LEAVE_NORMAL:
|
2008-01-19 18:52:05 +01:00
|
|
|
|
|
2008-02-24 17:29:02 +01:00
|
|
|
|
n = nparam + (SP - PP);
|
|
|
|
|
RELEASE_MANY(SP, n);
|
|
|
|
|
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(OP, "EXEC_leave");
|
2008-02-24 17:29:02 +01:00
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
|
|
|
|
|
|
__RETURN_VALUE:
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
if (pc && !drop)
|
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
//drop = PCODE_is_void(*pc);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
if (SP[-1].type == T_FUNCTION)
|
|
|
|
|
{
|
|
|
|
|
SP--;
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_leave");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
drop = TRUE;
|
|
|
|
|
keep_ret_value = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!drop)
|
|
|
|
|
{
|
|
|
|
|
//*SP = ret;
|
|
|
|
|
COPY_VALUE(SP, &ret);
|
|
|
|
|
RP->type = T_VOID;
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (PCODE_is_variant(*PC) && SP->type != T_VOID)
|
2010-06-05 01:48:53 +02:00
|
|
|
|
VALUE_conv_variant(SP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
else if (!keep_ret_value)
|
|
|
|
|
EXEC_release_return_value();
|
|
|
|
|
|
2008-01-19 18:52:05 +01:00
|
|
|
|
SP += nb;
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_leave()\n");
|
|
|
|
|
print_register();
|
|
|
|
|
printf("\n");
|
|
|
|
|
#endif
|
2008-02-24 17:29:02 +01:00
|
|
|
|
return;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
static void error_EXEC_function_real(void)
|
|
|
|
|
{
|
|
|
|
|
RELEASE_MANY(SP, EXEC.nparam);
|
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-05-10 17:17:07 +02:00
|
|
|
|
void EXEC_function_real()
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
// We need to push a void frame, because EXEC_leave looks at *PC to know if a return value is expected
|
2008-10-31 00:32:38 +01:00
|
|
|
|
STACK_push_frame(&EXEC_current, 0);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
PC = NULL;
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
ON_ERROR(error_EXEC_function_real)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
EXEC_enter();
|
|
|
|
|
}
|
2010-06-18 02:14:53 +02:00
|
|
|
|
END_ERROR
|
2008-05-10 17:17:07 +02:00
|
|
|
|
|
|
|
|
|
EXEC_function_loop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EXEC_function_loop()
|
|
|
|
|
{
|
|
|
|
|
bool retry = FALSE;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(PC != NULL))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
TRY
|
|
|
|
|
{
|
|
|
|
|
EXEC_loop();
|
|
|
|
|
retry = FALSE;
|
|
|
|
|
}
|
|
|
|
|
CATCH
|
|
|
|
|
{
|
|
|
|
|
// QUIT was called
|
2008-01-25 16:01:02 +01:00
|
|
|
|
if (ERROR->info.code == E_ABORT)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "#0 QUIT\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
|
|
|
|
ERROR_lock();
|
|
|
|
|
while (PC != NULL)
|
|
|
|
|
EXEC_leave(TRUE);
|
|
|
|
|
ERROR_unlock();
|
|
|
|
|
|
|
|
|
|
//STACK_pop_frame(&EXEC_current);
|
|
|
|
|
PROPAGATE();
|
|
|
|
|
}
|
|
|
|
|
// We are in a TRY
|
|
|
|
|
else if (EP != NULL)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "#1 EP = %d SP = %d\n", EP - (VALUE *)STACK_base, SP - (VALUE *)STACK_base);
|
|
|
|
|
fprintf(stderr, "TRY\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
2008-04-08 00:31:35 +02:00
|
|
|
|
ERROR_set_last();
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
while (SP > EP)
|
|
|
|
|
POP();
|
|
|
|
|
|
|
|
|
|
PC = EC;
|
|
|
|
|
EP = NULL;
|
|
|
|
|
retry = TRUE;
|
|
|
|
|
/* On va directement sur le END TRY */
|
|
|
|
|
}
|
|
|
|
|
// There is a CATCH in the function
|
|
|
|
|
else if (EC != NULL)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "#2 EC = %p\n", EC);
|
|
|
|
|
fprintf(stderr, "CATCH\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
|
ERROR_set_last();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
PC = EC;
|
|
|
|
|
EC = NULL;
|
|
|
|
|
retry = TRUE;
|
|
|
|
|
}
|
|
|
|
|
// There is no event handler in the function
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "#3\n");
|
|
|
|
|
fprintf(stderr, "NOTHING\n");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
2010-01-27 04:28:06 +01:00
|
|
|
|
//ERROR_INFO save = { 0 };
|
|
|
|
|
//ERROR_save(&save);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
|
ERROR_set_last();
|
2010-01-27 04:28:06 +01:00
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
if (EXEC_debug && !STACK_has_error_handler())
|
|
|
|
|
{
|
|
|
|
|
if (TP && TC)
|
|
|
|
|
{
|
|
|
|
|
ERROR_lock();
|
|
|
|
|
while (BP > TP)
|
|
|
|
|
{
|
|
|
|
|
EXEC_leave(TRUE);
|
|
|
|
|
if (!PC)
|
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
|
}
|
|
|
|
|
while (SP > TP)
|
|
|
|
|
POP();
|
|
|
|
|
PC = TC;
|
|
|
|
|
ERROR_unlock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DEBUG.Main(TRUE);
|
|
|
|
|
retry = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ERROR_lock();
|
|
|
|
|
while (PC != NULL && EC == NULL)
|
|
|
|
|
EXEC_leave(TRUE);
|
|
|
|
|
ERROR_unlock();
|
|
|
|
|
|
|
|
|
|
if (PC == NULL)
|
|
|
|
|
{
|
|
|
|
|
/*printf("try to propagate\n");*/
|
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
2010-01-27 04:28:06 +01:00
|
|
|
|
|
|
|
|
|
//ERROR_restore(&save);
|
|
|
|
|
//ERROR_set_last();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
PROPAGATE();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EP != NULL)
|
|
|
|
|
{
|
|
|
|
|
#if DEBUG_ERROR
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "#4 EP = %d SP = %d\n", EP - (VALUE *)STACK_base, SP - (VALUE *)STACK_base);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
ERROR_lock();
|
|
|
|
|
while (SP > EP)
|
|
|
|
|
POP();
|
|
|
|
|
ERROR_unlock();
|
|
|
|
|
|
|
|
|
|
EP = NULL;
|
|
|
|
|
/* On va directement sur le END TRY */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PC = EC;
|
|
|
|
|
EC = NULL;
|
|
|
|
|
|
|
|
|
|
retry = TRUE;
|
|
|
|
|
}
|
2010-01-27 04:28:06 +01:00
|
|
|
|
|
|
|
|
|
//ERROR_restore(&save);
|
|
|
|
|
//ERROR_set_last();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (SP < EXEC_super)
|
|
|
|
|
EXEC_super = ((VALUE *)EXEC_super)->_object.super;
|
|
|
|
|
}
|
|
|
|
|
END_TRY
|
|
|
|
|
|
|
|
|
|
#if DEBUG_ERROR
|
|
|
|
|
if (retry)
|
2009-02-04 23:51:20 +01:00
|
|
|
|
fprintf(stderr, "RETRY %p\n", PC);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
while (retry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STACK_pop_frame(&EXEC_current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
static ushort exec_native_can_quick(void)
|
2008-01-27 15:00:04 +01:00
|
|
|
|
{
|
|
|
|
|
CLASS_DESC_METHOD *desc = EXEC.desc;
|
|
|
|
|
int i;
|
|
|
|
|
int nparam = EXEC.nparam;
|
|
|
|
|
|
|
|
|
|
/* check number of arguments */
|
|
|
|
|
|
|
|
|
|
//fprintf(stderr, "exec_native_can_quick: %s.%s(%d) npmin:%d npmax:%d npvar:%d\n", desc->class->name, desc->name, nparam, desc->npmin, desc->npmax, desc->npvar);
|
|
|
|
|
|
|
|
|
|
if (desc->npmin < desc->npmax || nparam != desc->npmin || desc->npvar)
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_SLOW;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
|
|
|
|
|
/* check arguments type */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < nparam; i++)
|
|
|
|
|
{
|
|
|
|
|
if (SP[i - nparam].type != desc->signature[i])
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_SLOW;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
return C_CALL_QUICK;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void EXEC_native_check(bool defined)
|
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
ushort mode = defined ? exec_native_can_quick() : C_CALL_SLOW;
|
|
|
|
|
|
|
|
|
|
*PC = (*PC & 0xFF) | mode;
|
|
|
|
|
|
|
|
|
|
switch(mode)
|
2008-01-27 15:00:04 +01:00
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
case C_CALL_QUICK: EXEC_native_quick(); break;
|
|
|
|
|
//case C_CALL_EASY: EXEC_native_easy(); break;
|
|
|
|
|
default: EXEC_native(); break;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
#define EXEC_call_native_inline(_exec, _object, _type, _param) \
|
|
|
|
|
({ \
|
2010-08-29 23:35:34 +02:00
|
|
|
|
EXEC_set_native_error(FALSE); \
|
2010-06-05 01:48:53 +02:00
|
|
|
|
(*(_exec))((_object), (void *)(_param)); \
|
|
|
|
|
\
|
2010-08-29 22:51:10 +02:00
|
|
|
|
if (UNLIKELY(EXEC_has_native_error())) \
|
2010-06-05 01:48:53 +02:00
|
|
|
|
{ \
|
2010-08-29 22:51:10 +02:00
|
|
|
|
EXEC_set_native_error(FALSE); \
|
2010-06-05 01:48:53 +02:00
|
|
|
|
error = TRUE; \
|
|
|
|
|
} \
|
|
|
|
|
else \
|
|
|
|
|
{ \
|
|
|
|
|
TYPE __type = (_type); \
|
|
|
|
|
if (UNLIKELY(TYPE_is_pure_object(_type) && TEMP.type != T_NULL && TEMP.type != T_VOID)) \
|
|
|
|
|
{ \
|
|
|
|
|
if (UNLIKELY(((CLASS *)__type)->override != NULL)) \
|
|
|
|
|
__type = (TYPE)(((CLASS *)__type)->override); \
|
|
|
|
|
\
|
|
|
|
|
if (TEMP.type == T_CLASS) \
|
|
|
|
|
TEMP._class.class = (CLASS *)__type; \
|
|
|
|
|
else \
|
|
|
|
|
TEMP.type = __type; \
|
|
|
|
|
\
|
|
|
|
|
error = FALSE; \
|
|
|
|
|
} \
|
|
|
|
|
else \
|
|
|
|
|
error = FALSE; \
|
|
|
|
|
} \
|
|
|
|
|
})
|
2008-01-27 15:00:04 +01:00
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
bool EXEC_call_native(void (*exec)(), void *object, TYPE type, VALUE *param)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
bool error;
|
2010-04-26 11:36:47 +02:00
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
EXEC_call_native_inline(exec, object, type, param);
|
|
|
|
|
return error;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
|
void EXEC_native_quick(void)
|
|
|
|
|
{
|
|
|
|
|
CLASS_DESC_METHOD *desc = EXEC.desc;
|
|
|
|
|
int nparam = EXEC.nparam;
|
|
|
|
|
|
|
|
|
|
bool error;
|
2010-07-21 13:45:28 +02:00
|
|
|
|
//void *free_later;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
VALUE ret;
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
EXEC_call_native_inline(desc->exec, EXEC.object, desc->type, &SP[-nparam]);
|
2008-01-27 15:00:04 +01:00
|
|
|
|
COPY_VALUE(&ret, &TEMP);
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(error))
|
2008-01-27 15:00:04 +01:00
|
|
|
|
{
|
2010-07-21 13:45:28 +02:00
|
|
|
|
RELEASE_MANY(SP, nparam);
|
2008-01-27 15:00:04 +01:00
|
|
|
|
POP();
|
|
|
|
|
PROPAGATE();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (desc->type == T_VOID)
|
2010-06-18 02:14:53 +02:00
|
|
|
|
{
|
|
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
|
2010-07-21 13:45:28 +02:00
|
|
|
|
SP--;
|
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_native (FUNCTION)");
|
2010-06-18 02:14:53 +02:00
|
|
|
|
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP->_void.ptype = T_NULL;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BORROW(&ret);
|
2010-07-21 13:45:28 +02:00
|
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
|
|
|
|
|
SP--;
|
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_native (FUNCTION)");
|
2010-06-18 02:14:53 +02:00
|
|
|
|
COPY_VALUE(SP, &ret);
|
|
|
|
|
SP++;
|
2008-01-27 15:00:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_native: %s (%p)\n", desc->name, &desc);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2010-07-21 13:45:28 +02:00
|
|
|
|
|
2008-01-27 15:00:04 +01:00
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
static void error_EXEC_native(void)
|
|
|
|
|
{
|
|
|
|
|
RELEASE_MANY(SP, EXEC.nparam);
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_native(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
CLASS_DESC_METHOD *desc = EXEC.desc;
|
|
|
|
|
int nparam = EXEC.nparam;
|
2010-07-19 14:33:57 +02:00
|
|
|
|
void *object = EXEC.object;
|
|
|
|
|
bool use_stack = EXEC.use_stack;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
int i, n, nm;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
VALUE *value;
|
|
|
|
|
TYPE *sign;
|
|
|
|
|
bool error;
|
|
|
|
|
VALUE ret;
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| >> EXEC_native: %s.%s (%p)\n", EXEC.class->name, desc->name, &desc);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//printf("EXEC_native: nparam = %d desc->npvar = %d\n", nparam, desc->npvar);
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
ON_ERROR(error_EXEC_native)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
n = desc->npmin;
|
|
|
|
|
nm = desc->npmax;
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(nparam < n))
|
2010-01-01 15:55:13 +01:00
|
|
|
|
THROW(E_NEPARAM);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(!desc->npvar))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
if (UNLIKELY(nparam > nm))
|
2010-01-01 15:55:13 +01:00
|
|
|
|
THROW(E_TMPARAM);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
value = &SP[-nparam];
|
|
|
|
|
sign = desc->signature;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
for (i = 0; i < n; i++, value++, sign++)
|
2010-01-01 15:55:13 +01:00
|
|
|
|
VALUE_conv(value, *sign);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
if (UNLIKELY(n < nm))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
for (; i < nparam; i++, value++, sign++)
|
|
|
|
|
{
|
|
|
|
|
if (value->type != T_VOID)
|
|
|
|
|
VALUE_conv(value, *sign);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
n = nm - nparam;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(STACK_check(n)))
|
2009-05-27 20:42:48 +02:00
|
|
|
|
{
|
|
|
|
|
STACK_RELOCATE(value);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
SP += n;
|
2010-06-05 01:48:53 +02:00
|
|
|
|
nparam = nm;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
for (; i < nparam; i++, value++)
|
|
|
|
|
value->type = T_VOID;
|
|
|
|
|
}
|
2010-01-01 15:55:13 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
value = &SP[-nparam];
|
|
|
|
|
sign = desc->signature;
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
for (i = 0; i < n; i++, value++, sign++)
|
2010-01-01 15:55:13 +01:00
|
|
|
|
VALUE_conv(value, *sign);
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
nm = desc->npmax;
|
|
|
|
|
if (UNLIKELY(n < nm))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
if (UNLIKELY(nparam < nm))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-01-01 15:55:13 +01:00
|
|
|
|
for (; i < nparam; i++, value++, sign++)
|
|
|
|
|
{
|
|
|
|
|
if (value->type != T_VOID)
|
|
|
|
|
VALUE_conv(value, *sign);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
n = nm - nparam;
|
2010-01-01 15:55:13 +01:00
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(STACK_check(n)))
|
2010-01-01 15:55:13 +01:00
|
|
|
|
{
|
|
|
|
|
STACK_RELOCATE(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP += n;
|
2010-06-05 01:48:53 +02:00
|
|
|
|
nparam = nm;
|
2010-01-01 15:55:13 +01:00
|
|
|
|
|
|
|
|
|
for (; i < nparam; i++, value++)
|
|
|
|
|
value->type = T_VOID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
n = desc->npmax;
|
|
|
|
|
for (; i < n; i++, value++, sign++)
|
2010-01-01 15:55:13 +01:00
|
|
|
|
{
|
|
|
|
|
if (value->type != T_VOID)
|
|
|
|
|
VALUE_conv(value, *sign);
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
EXEC_unknown_nparam = nparam <= nm ? 0 : nparam - nm;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
for (; i < nparam; i++, value++)
|
|
|
|
|
VARIANT_undo(value);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
//printf("EXEC_native: nparvar = %d\n", EXEC.nparvar);
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
2010-06-18 02:14:53 +02:00
|
|
|
|
END_ERROR
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-07-19 14:33:57 +02:00
|
|
|
|
EXEC_call_native_inline(desc->exec, object, desc->type, &SP[-nparam]);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
COPY_VALUE(&ret, &TEMP);
|
|
|
|
|
/* Lib<69>ation des arguments */
|
|
|
|
|
|
|
|
|
|
/*while (nparam > 0)
|
|
|
|
|
{
|
|
|
|
|
nparam--;
|
|
|
|
|
POP();
|
|
|
|
|
}*/
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (UNLIKELY(error))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-07-21 13:45:28 +02:00
|
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (use_stack)
|
|
|
|
|
{
|
|
|
|
|
SP--;
|
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_native (FUNCTION)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PROPAGATE();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
2010-06-18 02:14:53 +02:00
|
|
|
|
|
|
|
|
|
// If the function description is on the stack
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (desc->type == T_VOID)
|
|
|
|
|
{
|
2010-07-21 13:45:28 +02:00
|
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (use_stack)
|
|
|
|
|
{
|
|
|
|
|
SP--;
|
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_native (FUNCTION)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
SP->_void.ptype = T_NULL;
|
|
|
|
|
SP++;
|
2010-07-21 13:45:28 +02:00
|
|
|
|
//UNBORROW(&ret);
|
2010-06-18 02:14:53 +02:00
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2010-07-21 13:45:28 +02:00
|
|
|
|
BORROW(&ret);
|
|
|
|
|
RELEASE_MANY(SP, nparam);
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (use_stack)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
SP--;
|
2010-07-21 13:45:28 +02:00
|
|
|
|
OBJECT_UNREF(SP->_function.object, "EXEC_native (FUNCTION)");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
2010-07-21 13:45:28 +02:00
|
|
|
|
|
|
|
|
|
COPY_VALUE(SP, &ret);
|
|
|
|
|
SP++;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if DEBUG_STACK
|
|
|
|
|
printf("| << EXEC_native: %s (%p)\n", desc->name, &desc);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
|
CLASS *EXEC_object_real(VALUE *val, OBJECT **pobject)
|
|
|
|
|
{
|
|
|
|
|
CLASS *class;
|
|
|
|
|
OBJECT *object;
|
|
|
|
|
|
|
|
|
|
object = val->_object.object;
|
|
|
|
|
class = val->_object.class;
|
|
|
|
|
|
|
|
|
|
if (!object)
|
|
|
|
|
{
|
|
|
|
|
/* A null object and a virtual class means that we want to pass a static class */
|
|
|
|
|
if (!class->is_virtual)
|
|
|
|
|
THROW(E_NULL);
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
goto __RETURN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(val == EXEC_super))
|
|
|
|
|
{
|
|
|
|
|
EXEC_super = val->_object.super;
|
|
|
|
|
//*class = (*class)->parent;
|
|
|
|
|
if (UNLIKELY(class == NULL))
|
|
|
|
|
THROW(E_PARENT);
|
|
|
|
|
}
|
|
|
|
|
else if (!class->is_virtual)
|
|
|
|
|
class = object->class;
|
|
|
|
|
|
|
|
|
|
//CLASS_load(class); If we have an object, the class is necessarily loaded.
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(class->must_check && (*(class->check))(object)))
|
|
|
|
|
THROW(E_IOBJECT);
|
|
|
|
|
|
|
|
|
|
__RETURN:
|
|
|
|
|
|
|
|
|
|
*pobject = object;
|
|
|
|
|
|
|
|
|
|
return class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CLASS *EXEC_object_variant(VALUE *val, OBJECT **pobject)
|
|
|
|
|
{
|
|
|
|
|
CLASS *class;
|
|
|
|
|
OBJECT *object;
|
|
|
|
|
|
|
|
|
|
if (TYPE_is_pure_object(val->_variant.vtype))
|
|
|
|
|
{
|
|
|
|
|
object = val->_variant.value._object;
|
|
|
|
|
if (!object)
|
|
|
|
|
goto __NULL;
|
|
|
|
|
class = (CLASS *)val->_variant.vtype;
|
|
|
|
|
if (!class->is_virtual)
|
|
|
|
|
class = object->class; /* Virtual dispatching */
|
|
|
|
|
goto __CHECK;
|
|
|
|
|
}
|
|
|
|
|
else if (val->_variant.vtype == T_OBJECT)
|
|
|
|
|
{
|
|
|
|
|
object = val->_variant.value._object;
|
|
|
|
|
if (!object)
|
|
|
|
|
goto __NULL;
|
|
|
|
|
class = object->class;
|
|
|
|
|
goto __CHECK;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
goto __ERROR;
|
|
|
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
|
|
|
|
|
|
THROW(E_NOBJECT);
|
|
|
|
|
|
|
|
|
|
__NULL:
|
|
|
|
|
|
|
|
|
|
THROW(E_NULL);
|
|
|
|
|
|
|
|
|
|
__CHECK:
|
|
|
|
|
|
|
|
|
|
//CLASS_load(class); If we have an object, the class is necessarily loaded.
|
|
|
|
|
|
|
|
|
|
if (UNLIKELY(class->must_check && (*(class->check))(object)))
|
|
|
|
|
THROW(E_IOBJECT);
|
|
|
|
|
|
|
|
|
|
*pobject = object;
|
|
|
|
|
|
|
|
|
|
return class;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool EXEC_object_other(VALUE *val, CLASS **pclass, OBJECT **pobject)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2008-03-20 00:50:34 +01:00
|
|
|
|
static const void *jump[] = {
|
2007-12-30 17:41:49 +01:00
|
|
|
|
&&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR,
|
2010-06-13 14:03:29 +02:00
|
|
|
|
&&__ERROR, &&__ERROR, &&__ERROR, &&__ERROR, &&__FUNCTION, &&__CLASS, &&__NULL,
|
2010-06-09 01:08:04 +02:00
|
|
|
|
&&__OBJECT,
|
2007-12-30 17:41:49 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CLASS *class;
|
|
|
|
|
OBJECT *object;
|
|
|
|
|
bool defined;
|
|
|
|
|
|
2010-06-13 14:03:29 +02:00
|
|
|
|
goto *jump[val->type];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
__FUNCTION:
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (LIKELY(val->_function.kind == FUNCTION_UNKNOWN))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
EXEC_unknown_property = TRUE;
|
|
|
|
|
EXEC_unknown_name = CP->load->unknown[val->_function.index];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
EXEC_special(SPEC_UNKNOWN, val->_function.class, val->_function.object, 0, FALSE);
|
|
|
|
|
|
|
|
|
|
object = val->_function.object;
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(object, "EXEC_object (FUNCTION)");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
SP--;
|
|
|
|
|
//*val = *SP;
|
|
|
|
|
COPY_VALUE(val, SP);
|
2010-06-18 02:14:53 +02:00
|
|
|
|
EXEC_object(val, pclass, pobject);
|
|
|
|
|
return FALSE; // Could be TRUE, but always returning FALSE allows optimizations in quick array management
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
goto __ERROR;
|
|
|
|
|
|
|
|
|
|
__CLASS:
|
|
|
|
|
|
|
|
|
|
class = val->_class.class;
|
|
|
|
|
object = NULL;
|
|
|
|
|
defined = TRUE;
|
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
|
if (val == EXEC_super)
|
2008-12-28 20:01:39 +01:00
|
|
|
|
{
|
|
|
|
|
EXEC_super = val->_class.super;
|
|
|
|
|
//*class = (*class)->parent;
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(class == NULL))
|
2008-12-28 20:01:39 +01:00
|
|
|
|
THROW(E_PARENT);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
CLASS_load(class);
|
|
|
|
|
goto __RETURN;
|
|
|
|
|
|
|
|
|
|
__OBJECT:
|
|
|
|
|
|
|
|
|
|
object = val->_object.object;
|
2010-06-05 01:48:53 +02:00
|
|
|
|
if (!object)
|
|
|
|
|
goto __NULL;
|
|
|
|
|
class = object->class;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
defined = FALSE;
|
|
|
|
|
|
|
|
|
|
goto __CHECK;
|
|
|
|
|
|
|
|
|
|
__ERROR:
|
|
|
|
|
|
|
|
|
|
THROW(E_NOBJECT);
|
|
|
|
|
|
|
|
|
|
__NULL:
|
|
|
|
|
|
|
|
|
|
THROW(E_NULL);
|
|
|
|
|
|
|
|
|
|
__CHECK:
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
//CLASS_load(class); If we have an object, the class is necessarily loaded.
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
if (UNLIKELY(class->must_check && (*(class->check))(object)))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
THROW(E_IOBJECT);
|
|
|
|
|
|
|
|
|
|
__RETURN:
|
|
|
|
|
|
|
|
|
|
*pclass = class;
|
|
|
|
|
*pobject = object;
|
2010-05-28 08:24:14 +02:00
|
|
|
|
|
|
|
|
|
return defined;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
void EXEC_public_desc(CLASS *class, void *object, CLASS_DESC_METHOD *desc, int nparam)
|
|
|
|
|
{
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.nparam = nparam; /*desc->npmin;*/
|
|
|
|
|
|
|
|
|
|
if (FUNCTION_is_native(desc))
|
|
|
|
|
{
|
2010-03-18 16:40:34 +01:00
|
|
|
|
EXEC.class = class; // EXEC_native() does not need the real class, except the GB.GetClass(NULL) API used by Form.Main.
|
2010-01-01 15:55:13 +01:00
|
|
|
|
EXEC.native = TRUE;
|
|
|
|
|
EXEC.use_stack = FALSE;
|
|
|
|
|
EXEC.desc = desc;
|
|
|
|
|
EXEC_native();
|
|
|
|
|
SP--;
|
|
|
|
|
*RP = *SP;
|
|
|
|
|
SP->type = T_VOID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-03-18 16:40:34 +01:00
|
|
|
|
EXEC.class = desc->class; // EXEC_function_real() needs the effective class, because the method can be an inherited one!
|
2010-01-01 15:55:13 +01:00
|
|
|
|
EXEC.native = FALSE;
|
|
|
|
|
EXEC.index = (int)(intptr_t)desc->exec;
|
|
|
|
|
EXEC_function_keep();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_public(CLASS *class, void *object, const char *name, int nparam)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
|
|
|
|
|
|
desc = CLASS_get_symbol_desc_kind(class, name, (object != NULL) ? CD_METHOD : CD_STATIC_METHOD, 0);
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(desc == NULL))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return;
|
2010-01-01 15:55:13 +01:00
|
|
|
|
|
|
|
|
|
EXEC_public_desc(class, object, &desc->method, nparam);
|
|
|
|
|
EXEC_release_return_value();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-01 15:55:13 +01:00
|
|
|
|
bool EXEC_special(int special, CLASS *class, void *object, int nparam, bool drop)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
|
short index = class->special[special];
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(index == NO_SYMBOL))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
desc = CLASS_get_desc(class, index);
|
|
|
|
|
|
|
|
|
|
if (CLASS_DESC_get_type(desc) == CD_STATIC_METHOD)
|
|
|
|
|
{
|
|
|
|
|
if (object != NULL)
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (object == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (class->auto_create)
|
|
|
|
|
object = EXEC_auto_create(class, FALSE);
|
|
|
|
|
|
|
|
|
|
if (object == NULL)
|
|
|
|
|
THROW(E_NOBJECT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EXEC.class = desc->method.class;
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.nparam = nparam;
|
|
|
|
|
|
|
|
|
|
/*printf("<< EXEC_spec: SP = %d\n", SP - (VALUE *)STACK_base);
|
|
|
|
|
save_SP = SP;*/
|
|
|
|
|
|
|
|
|
|
if (FUNCTION_is_native(&desc->method))
|
|
|
|
|
{
|
|
|
|
|
EXEC.desc = &desc->method;
|
|
|
|
|
EXEC.use_stack = FALSE;
|
|
|
|
|
EXEC.native = TRUE;
|
|
|
|
|
EXEC_native();
|
2010-06-18 02:14:53 +02:00
|
|
|
|
if (drop)
|
|
|
|
|
POP();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//EXEC.func = &class->load->func[(long)desc->method.exec]
|
2008-01-17 22:39:26 +01:00
|
|
|
|
EXEC.index = (int)(intptr_t)desc->method.exec;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
EXEC.native = FALSE;
|
2009-07-12 23:49:13 +02:00
|
|
|
|
if (drop)
|
|
|
|
|
EXEC_function();
|
|
|
|
|
else
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
2009-07-12 23:49:13 +02:00
|
|
|
|
EXEC_function_keep();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
//*SP++ = *RP;
|
|
|
|
|
COPY_VALUE(SP, RP);
|
|
|
|
|
SP++;
|
|
|
|
|
RP->type = T_VOID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*printf(">> EXEC_spec: SP = %d\n", SP - (VALUE *)STACK_base);
|
|
|
|
|
if (SP != save_SP)
|
|
|
|
|
printf("**** SP should be %d\n", save_SP - (VALUE *)STACK_base);*/
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* static void dump(int np) */
|
|
|
|
|
/* { */
|
|
|
|
|
/* int i; */
|
|
|
|
|
/* */
|
|
|
|
|
/* for (i = 1; i <= np; i++) */
|
|
|
|
|
/* printf("SP[%d] = %d ", -i, SP[-i].type); */
|
|
|
|
|
/* */
|
|
|
|
|
/* printf("\n"); */
|
|
|
|
|
/* } */
|
|
|
|
|
/* */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
The highest parent method is called first, but get only the parameters
|
|
|
|
|
not consumed by the child methods.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-11-30 05:25:48 +01:00
|
|
|
|
#if 0
|
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
|
|
|
|
{
|
|
|
|
|
CLASS *her[MAX_INHERITANCE];
|
|
|
|
|
int npher[MAX_INHERITANCE];
|
|
|
|
|
int nher;
|
|
|
|
|
int i, np;
|
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
|
short index;
|
|
|
|
|
|
2009-11-30 05:25:48 +01:00
|
|
|
|
if (!class->parent)
|
|
|
|
|
{
|
|
|
|
|
if (special == SPEC_NEW && !CLASS_is_native(class))
|
|
|
|
|
{
|
|
|
|
|
EXEC.class = class;
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.index = FUNC_INIT_DYNAMIC;
|
|
|
|
|
EXEC.native = FALSE;
|
|
|
|
|
EXEC.nparam = 0;
|
|
|
|
|
EXEC_function();
|
|
|
|
|
}
|
|
|
|
|
EXEC_special(special, class, object, nparam, drop);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
nher = CLASS_get_inheritance(class, her);
|
|
|
|
|
|
|
|
|
|
for(i = 0, np = 0; i < nher; i++)
|
|
|
|
|
{
|
|
|
|
|
class = her[i];
|
|
|
|
|
npher[i] = np;
|
|
|
|
|
|
|
|
|
|
index = class->special[special];
|
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
|
continue;
|
|
|
|
|
desc = CLASS_get_desc(class, index); //class->special[special];
|
|
|
|
|
|
|
|
|
|
np += desc->method.npmax;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
nher--;
|
|
|
|
|
if (nher < 0)
|
|
|
|
|
break;
|
|
|
|
|
class = her[nher];
|
|
|
|
|
|
|
|
|
|
if (special == SPEC_NEW)
|
|
|
|
|
{
|
|
|
|
|
if (!CLASS_is_native(class))
|
|
|
|
|
{
|
|
|
|
|
EXEC.class = class;
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.index = FUNC_INIT_DYNAMIC;
|
|
|
|
|
//EXEC.func = &class->load->func[FUNC_INIT_DYNAMIC];
|
|
|
|
|
EXEC.native = FALSE;
|
|
|
|
|
EXEC.nparam = 0;
|
|
|
|
|
|
|
|
|
|
EXEC_function();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index = class->special[special];
|
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
desc = CLASS_get_desc(class, index); // class->special[special];
|
|
|
|
|
|
|
|
|
|
/*np = Min(nparam, desc->method.npmax);*/
|
|
|
|
|
|
|
|
|
|
np = Max(0, nparam - npher[nher]);
|
|
|
|
|
|
|
|
|
|
EXEC_special(special, class, object, np, drop);
|
|
|
|
|
nparam -= np;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-11-30 05:25:48 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void EXEC_special_inheritance(int special, CLASS *class, OBJECT *object, int nparam, bool drop)
|
|
|
|
|
{
|
|
|
|
|
CLASS *her[MAX_INHERITANCE];
|
|
|
|
|
int nher;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
int i, np, npopt, nparam_opt;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
CLASS_DESC *desc;
|
|
|
|
|
short index;
|
2009-12-07 18:14:32 +01:00
|
|
|
|
int arg, opt;
|
|
|
|
|
VALUE *base;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
|
|
|
|
|
if (!class->parent)
|
|
|
|
|
{
|
2010-05-23 13:07:14 +02:00
|
|
|
|
if (special == SPEC_NEW && class->init_dynamic)
|
2009-11-30 05:25:48 +01:00
|
|
|
|
{
|
|
|
|
|
EXEC.class = class;
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.index = FUNC_INIT_DYNAMIC;
|
|
|
|
|
EXEC.native = FALSE;
|
|
|
|
|
EXEC.nparam = 0;
|
|
|
|
|
EXEC_function();
|
|
|
|
|
}
|
|
|
|
|
EXEC_special(special, class, object, nparam, drop);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nher = CLASS_get_inheritance(class, her);
|
|
|
|
|
|
2009-12-01 05:06:21 +01:00
|
|
|
|
for(i = 0, np = 0; i < nher; i++)
|
|
|
|
|
{
|
|
|
|
|
class = her[i];
|
|
|
|
|
|
|
|
|
|
index = class->special[special];
|
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
|
continue;
|
|
|
|
|
desc = CLASS_get_desc(class, index); //class->special[special];
|
|
|
|
|
np += desc->method.npmin;
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(np > nparam))
|
2009-12-01 05:06:21 +01:00
|
|
|
|
THROW(E_NEPARAM);
|
|
|
|
|
|
2009-12-07 18:14:32 +01:00
|
|
|
|
arg = - nparam;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
opt = arg + np;
|
|
|
|
|
nparam_opt = nparam - np;
|
|
|
|
|
nparam = np;
|
|
|
|
|
|
|
|
|
|
// nparam is now the number of mandatory arguments
|
|
|
|
|
// naram_opt is the number of optional arguments
|
|
|
|
|
|
2009-11-30 05:25:48 +01:00
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
nher--;
|
|
|
|
|
if (nher < 0)
|
|
|
|
|
break;
|
|
|
|
|
class = her[nher];
|
|
|
|
|
|
|
|
|
|
if (special == SPEC_NEW)
|
|
|
|
|
{
|
2010-05-23 13:07:14 +02:00
|
|
|
|
if (class->init_dynamic)
|
2009-11-30 05:25:48 +01:00
|
|
|
|
{
|
|
|
|
|
EXEC.class = class;
|
|
|
|
|
EXEC.object = object;
|
|
|
|
|
EXEC.index = FUNC_INIT_DYNAMIC;
|
|
|
|
|
//EXEC.func = &class->load->func[FUNC_INIT_DYNAMIC];
|
|
|
|
|
EXEC.native = FALSE;
|
|
|
|
|
EXEC.nparam = 0;
|
|
|
|
|
|
|
|
|
|
EXEC_function();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
index = class->special[special];
|
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
desc = CLASS_get_desc(class, index); // class->special[special];
|
2009-12-01 05:06:21 +01:00
|
|
|
|
|
2009-11-30 05:25:48 +01:00
|
|
|
|
if (nher)
|
|
|
|
|
{
|
2009-12-01 05:06:21 +01:00
|
|
|
|
np = desc->method.npmin;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
if (np > nparam) np = nparam;
|
|
|
|
|
nparam -= np;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
|
|
|
|
|
npopt = desc->method.npmax - desc->method.npmin;
|
|
|
|
|
if (npopt > nparam_opt) npopt = nparam_opt;
|
|
|
|
|
nparam_opt -= npopt;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
2009-12-01 05:06:21 +01:00
|
|
|
|
{
|
2009-11-30 05:25:48 +01:00
|
|
|
|
np = nparam;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
npopt = nparam_opt;
|
|
|
|
|
}
|
2009-11-30 05:25:48 +01:00
|
|
|
|
|
2009-12-01 05:06:21 +01:00
|
|
|
|
if (np > 0 || npopt > 0)
|
2009-11-30 05:25:48 +01:00
|
|
|
|
{
|
2009-12-01 05:06:21 +01:00
|
|
|
|
STACK_check(np + npopt);
|
|
|
|
|
|
2009-12-07 18:14:32 +01:00
|
|
|
|
base = SP;
|
|
|
|
|
|
2009-11-30 05:25:48 +01:00
|
|
|
|
for (i = 0; i < np; i++)
|
|
|
|
|
{
|
2009-12-07 18:14:32 +01:00
|
|
|
|
*SP++ = base[arg];
|
|
|
|
|
base[arg].type = T_NULL;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
arg++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < npopt; i++)
|
|
|
|
|
{
|
2009-12-07 18:14:32 +01:00
|
|
|
|
*SP++ = base[opt];
|
|
|
|
|
base[opt].type = T_NULL;
|
2009-12-01 05:06:21 +01:00
|
|
|
|
opt++;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 05:06:21 +01:00
|
|
|
|
EXEC_special(special, class, object, np + npopt, drop);
|
2009-11-30 05:25:48 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-01 05:06:21 +01:00
|
|
|
|
SP -= nparam + nparam_opt;
|
2009-11-30 05:25:48 +01:00
|
|
|
|
}
|
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)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
void *object;
|
|
|
|
|
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(class->no_create))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
THROW(E_CSTATIC, class->name);
|
|
|
|
|
|
2010-06-18 02:14:53 +02:00
|
|
|
|
object = OBJECT_new(class, event, ((OP == NULL) ? (OBJECT *)CP : (OBJECT *)OP));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
TRY
|
|
|
|
|
{
|
|
|
|
|
OBJECT_lock(object, TRUE);
|
|
|
|
|
EXEC_special_inheritance(SPEC_NEW, class, object, np, TRUE);
|
|
|
|
|
OBJECT_lock(object, FALSE);
|
|
|
|
|
|
|
|
|
|
// SP--; /* class */
|
|
|
|
|
//
|
|
|
|
|
// SP->_object.class = class;
|
|
|
|
|
// SP->_object.object = object;
|
|
|
|
|
// SP++;
|
|
|
|
|
}
|
|
|
|
|
CATCH
|
|
|
|
|
{
|
|
|
|
|
// _free() methods should not be called, but we must
|
2010-11-22 11:10:56 +01:00
|
|
|
|
OBJECT_UNREF(object, "EXEC_create_object");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
PROPAGATE();
|
|
|
|
|
// SP--; /* class */
|
|
|
|
|
// SP->type = T_NULL;
|
|
|
|
|
// SP++;
|
|
|
|
|
// PROPAGATE();
|
|
|
|
|
}
|
|
|
|
|
END_TRY
|
|
|
|
|
|
|
|
|
|
return object;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_new(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
CLASS *class;
|
|
|
|
|
int np;
|
2009-07-08 21:57:50 +02:00
|
|
|
|
bool event;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
void *object;
|
|
|
|
|
char *name = NULL;
|
|
|
|
|
char *cname = NULL;
|
2010-12-21 15:05:42 +01:00
|
|
|
|
char *save;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
np = *PC & 0xFF;
|
|
|
|
|
event = np & CODE_NEW_EVENT;
|
|
|
|
|
np &= 0x3F;
|
|
|
|
|
|
|
|
|
|
/* Instanciation */
|
|
|
|
|
|
|
|
|
|
SP -= np;
|
|
|
|
|
|
|
|
|
|
if (SP->type == T_CLASS)
|
|
|
|
|
{
|
|
|
|
|
class = SP->_class.class;
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(class->override != NULL))
|
2010-04-26 11:36:47 +02:00
|
|
|
|
class = class->override;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
else if (TYPE_is_string(SP->type))
|
|
|
|
|
{
|
2010-06-05 01:48:53 +02:00
|
|
|
|
cname = STRING_copy_from_value_temp(SP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
class = CLASS_find(cname);
|
2010-05-22 20:02:34 +02:00
|
|
|
|
RELEASE_STRING(SP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
SP->type = T_NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
THROW(E_TYPE, "String", TYPE_get_name(SP->type));
|
|
|
|
|
|
|
|
|
|
SP += np;
|
|
|
|
|
|
|
|
|
|
//printf("**** NEW %s\n", class->name);
|
|
|
|
|
CLASS_load(class);
|
|
|
|
|
|
2010-05-19 22:18:23 +02:00
|
|
|
|
if (UNLIKELY(class->no_create))
|
2007-12-30 17:41:49 +01:00
|
|
|
|
THROW(E_CSTATIC, class->name);
|
|
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
|
{
|
|
|
|
|
SP--;
|
|
|
|
|
|
|
|
|
|
if (!TYPE_is_string(SP->type))
|
|
|
|
|
THROW(E_TYPE, "String", TYPE_get_name(SP->type));
|
|
|
|
|
|
2010-06-05 01:48:53 +02:00
|
|
|
|
name = STRING_copy_from_value_temp(SP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
//printf("**** name %s\n", class->name);
|
|
|
|
|
|
|
|
|
|
STRING_ref(name);
|
2009-07-12 23:49:13 +02:00
|
|
|
|
SP++;
|
2010-06-18 02:14:53 +02:00
|
|
|
|
object = OBJECT_new(class, name, ((OP == NULL) ? (OBJECT *)CP : (OBJECT *)OP));
|
2009-07-12 23:49:13 +02:00
|
|
|
|
SP--;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
STRING_unref(&name);
|
|
|
|
|
|
2010-05-22 20:02:34 +02:00
|
|
|
|
RELEASE_STRING(SP);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
np -= 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-06-18 02:14:53 +02:00
|
|
|
|
object = OBJECT_new(class, name, ((OP == NULL) ? (OBJECT *)CP : (OBJECT *)OP));
|
2007-12-30 17:41:49 +01:00
|
|
|
|
np--;
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-21 15:05:42 +01:00
|
|
|
|
save = EVENT_enter_name(name);
|
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
TRY
|
|
|
|
|
{
|
|
|
|
|
OBJECT_lock(object, TRUE);
|
|
|
|
|
EXEC_special_inheritance(SPEC_NEW, class, object, np, TRUE);
|
|
|
|
|
OBJECT_lock(object, FALSE);
|
2010-12-21 15:05:42 +01:00
|
|
|
|
EVENT_leave_name(save);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
|
SP--; /* class */
|
|
|
|
|
|
|
|
|
|
SP->_object.class = class;
|
|
|
|
|
SP->_object.object = object;
|
|
|
|
|
SP++;
|
|
|
|
|
}
|
|
|
|
|
CATCH
|
|
|
|
|
{
|
2010-12-21 15:05:42 +01:00
|
|
|
|
EVENT_leave_name(save);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
// _free() methods should not be called, but we must
|
2008-08-14 21:42:27 +02:00
|
|
|
|
OBJECT_UNREF(object, "EXEC_new");
|
2007-12-30 17:41:49 +01:00
|
|
|
|
//(*class->free)(class, object);
|
|
|
|
|
SP--; /* class */
|
|
|
|
|
SP->type = T_NULL;
|
|
|
|
|
SP++;
|
|
|
|
|
PROPAGATE();
|
|
|
|
|
}
|
|
|
|
|
END_TRY
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_quit(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
GAMBAS_DoNotRaiseEvent = TRUE;
|
|
|
|
|
|
|
|
|
|
HOOK(quit)();
|
|
|
|
|
|
|
|
|
|
THROW(E_ABORT);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void *EXEC_auto_create(CLASS *class, bool ref)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
void *object;
|
|
|
|
|
|
|
|
|
|
object = CLASS_auto_create(class, 0); /* object is checked by CLASS_auto_create */
|
2010-09-14 15:01:47 +02:00
|
|
|
|
|
2010-09-16 13:27:51 +02:00
|
|
|
|
/*if (UNLIKELY(class->must_check && (*(class->check))(object)))
|
|
|
|
|
THROW(E_IOBJECT);*/
|
2010-09-14 15:01:47 +02:00
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
if (ref)
|
|
|
|
|
OBJECT_REF(object, "EXEC_auto_create");
|
2010-09-14 15:01:47 +02:00
|
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
|
return object;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
|
void EXEC_dup(int n)
|
2007-12-30 17:41:49 +01:00
|
|
|
|
{
|
|
|
|
|
VALUE *src;
|
|
|
|
|
|
|
|
|
|
STACK_check(n);
|
|
|
|
|
|
|
|
|
|
src = SP - n;
|
|
|
|
|
while (n > 0)
|
|
|
|
|
{
|
|
|
|
|
BORROW(src);
|
|
|
|
|
*SP++ = *src++;
|
|
|
|
|
n--;
|
|
|
|
|
}
|
|
|
|
|
}
|