2007-12-30 17:41:49 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
gbx_exec_pop.c
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2009-08-17 12:41:51 +02:00
|
|
|
(c) 2000-2009 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.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gb_common.h"
|
|
|
|
#include "gb_limit.h"
|
|
|
|
#include "gbx_exec.h"
|
|
|
|
|
|
|
|
#include "gbx_string.h"
|
|
|
|
#include "gbx_object.h"
|
2008-01-24 02:36:20 +01:00
|
|
|
#include "gbx_c_array.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
#include "gbx_c_collection.h"
|
2008-01-24 11:42:42 +01:00
|
|
|
#include "gbx_api.h"
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
|
2008-01-17 22:39:26 +01:00
|
|
|
void EXEC_pop_unknown(void)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
|
|
|
static void *jump[6] = {
|
|
|
|
/* 0 */ &&_POP_GENERIC,
|
|
|
|
/* 1 */ &&_POP_VARIABLE,
|
|
|
|
/* 2 */ &&_POP_STATIC_VARIABLE,
|
|
|
|
/* 3 */ &&_POP_PROPERTY,
|
|
|
|
/* 4 */ &&_POP_VARIABLE_AUTO,
|
|
|
|
/* 5 */ &&_POP_PROPERTY_AUTO
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *name;
|
2008-01-17 22:39:26 +01:00
|
|
|
int index;
|
2007-12-30 17:41:49 +01:00
|
|
|
CLASS_DESC *desc;
|
|
|
|
CLASS *class;
|
|
|
|
OBJECT *object;
|
|
|
|
char *addr;
|
2009-07-08 21:57:50 +02:00
|
|
|
bool defined;
|
2007-12-30 17:41:49 +01:00
|
|
|
VALUE *val;
|
|
|
|
|
|
|
|
EXEC_object(&SP[-1], &class, &object, &defined);
|
|
|
|
|
|
|
|
/*printf("> exec_pop_unknown: SP = %p -> %p\n", SP, SP->_string.addr);*/
|
|
|
|
|
|
|
|
goto *jump[*PC & 0xF];
|
|
|
|
|
|
|
|
|
|
|
|
_POP_GENERIC:
|
|
|
|
|
|
|
|
name = CP->load->unknown[PC[1]];
|
|
|
|
|
|
|
|
// The first time we access a symbol, we must not be virtual to find it
|
|
|
|
val = &SP[-1];
|
|
|
|
if (defined && object && !VALUE_is_super(val))
|
|
|
|
index = CLASS_find_symbol(val->_object.class, name);
|
|
|
|
else
|
|
|
|
index = CLASS_find_symbol(class, name);
|
|
|
|
|
|
|
|
if (index == NO_SYMBOL)
|
|
|
|
{
|
2009-08-05 18:14:08 +02:00
|
|
|
if (class->special[SPEC_UNKNOWN] == NO_SYMBOL)
|
|
|
|
{
|
|
|
|
if (defined && object && !VALUE_is_super(val))
|
|
|
|
class = val->_object.class;
|
|
|
|
THROW(E_NSYMBOL, name, class->name);
|
|
|
|
}
|
|
|
|
goto _POP_UNKNOWN_PROPERTY;
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
desc = class->table[index].desc;
|
|
|
|
|
|
|
|
switch (CLASS_DESC_get_type(desc))
|
|
|
|
{
|
|
|
|
case CD_CONSTANT:
|
|
|
|
|
|
|
|
THROW(E_NPROPERTY, class->name, name);
|
|
|
|
|
|
|
|
case CD_VARIABLE:
|
|
|
|
|
|
|
|
if (object == NULL)
|
|
|
|
{
|
|
|
|
if (!class->auto_create)
|
|
|
|
THROW(E_DYNAMIC, class->name, name);
|
|
|
|
object = EXEC_auto_create(class, TRUE);
|
|
|
|
*PC |= 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (defined) *PC |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined)
|
|
|
|
PC[1] = index;
|
|
|
|
|
|
|
|
goto _POP_VARIABLE_2;
|
|
|
|
|
|
|
|
case CD_STATIC_VARIABLE:
|
|
|
|
|
|
|
|
if (object != NULL)
|
|
|
|
THROW(E_STATIC, class->name, name);
|
|
|
|
|
|
|
|
if (defined) *PC |= 2;
|
|
|
|
|
|
|
|
if (defined)
|
|
|
|
PC[1] = index;
|
|
|
|
|
|
|
|
goto _POP_STATIC_VARIABLE_2;
|
|
|
|
|
|
|
|
case CD_PROPERTY:
|
|
|
|
|
|
|
|
if (object == NULL)
|
|
|
|
{
|
|
|
|
if (!class->auto_create)
|
|
|
|
THROW(E_DYNAMIC, class->name, name);
|
|
|
|
object = EXEC_auto_create(class, TRUE);
|
|
|
|
*PC |= 5;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (defined) *PC |= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined)
|
|
|
|
PC[1] = index;
|
|
|
|
|
|
|
|
goto _POP_PROPERTY_2;
|
|
|
|
|
|
|
|
case CD_STATIC_PROPERTY:
|
|
|
|
|
|
|
|
if (object != NULL)
|
|
|
|
THROW(E_STATIC, class->name, name);
|
|
|
|
|
|
|
|
if (defined) *PC |= 3;
|
|
|
|
|
|
|
|
if (defined)
|
|
|
|
PC[1] = index;
|
|
|
|
|
|
|
|
goto _POP_PROPERTY_2;
|
|
|
|
|
|
|
|
case CD_PROPERTY_READ:
|
|
|
|
case CD_STATIC_PROPERTY_READ:
|
|
|
|
|
|
|
|
THROW(E_NWRITE, class->name, name);
|
|
|
|
|
|
|
|
case CD_METHOD:
|
|
|
|
case CD_STATIC_METHOD:
|
|
|
|
|
|
|
|
THROW(E_NPROPERTY, class->name, name);
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
THROW(E_NSYMBOL, name, class->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_POP_VARIABLE_AUTO:
|
|
|
|
|
|
|
|
object = EXEC_auto_create(class, TRUE);
|
|
|
|
|
|
|
|
_POP_VARIABLE:
|
|
|
|
|
|
|
|
desc = class->table[PC[1]].desc;
|
|
|
|
|
|
|
|
_POP_VARIABLE_2:
|
|
|
|
|
|
|
|
addr = (char *)object + desc->variable.offset;
|
|
|
|
VALUE_write(&SP[-2], (void *)addr, desc->variable.type);
|
|
|
|
goto _FIN;
|
|
|
|
|
|
|
|
|
|
|
|
_POP_STATIC_VARIABLE:
|
|
|
|
|
|
|
|
desc = class->table[PC[1]].desc;
|
|
|
|
|
|
|
|
_POP_STATIC_VARIABLE_2:
|
|
|
|
|
2009-06-17 16:13:50 +02:00
|
|
|
addr = (char *)desc->variable.class->stat + desc->variable.offset;
|
2007-12-30 17:41:49 +01:00
|
|
|
VALUE_write(&SP[-2], (void *)addr, desc->variable.type);
|
|
|
|
goto _FIN;
|
|
|
|
|
|
|
|
|
|
|
|
_POP_PROPERTY_AUTO:
|
|
|
|
|
|
|
|
object = EXEC_auto_create(class, TRUE);
|
|
|
|
|
|
|
|
_POP_PROPERTY:
|
|
|
|
|
|
|
|
desc = class->table[PC[1]].desc;
|
|
|
|
|
|
|
|
_POP_PROPERTY_2:
|
|
|
|
|
|
|
|
VALUE_conv(&SP[-2], desc->property.type);
|
|
|
|
|
|
|
|
if (desc->property.native)
|
|
|
|
{
|
|
|
|
if (EXEC_call_native(desc->property.write, object, 0, &SP[-2]))
|
|
|
|
PROPAGATE();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*SP = SP[-2];
|
2009-08-05 18:14:08 +02:00
|
|
|
PUSH();
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
EXEC.class = desc->property.class;
|
|
|
|
EXEC.object = object;
|
|
|
|
EXEC.drop = FALSE;
|
|
|
|
EXEC.nparam = 1;
|
|
|
|
EXEC.native = FALSE;
|
2008-01-17 22:39:26 +01:00
|
|
|
EXEC.index = (int)(intptr_t)desc->property.write;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
EXEC_function();
|
|
|
|
}
|
2009-08-05 18:14:08 +02:00
|
|
|
|
|
|
|
goto _FIN;
|
|
|
|
|
|
|
|
_POP_UNKNOWN_PROPERTY:
|
|
|
|
|
|
|
|
EXEC.property = TRUE;
|
|
|
|
EXEC.unknown = CP->load->unknown[PC[1]];
|
|
|
|
|
|
|
|
*SP = SP[-2];
|
|
|
|
PUSH();
|
|
|
|
|
|
|
|
EXEC_special(SPEC_UNKNOWN, class, object, 1, TRUE);
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
_FIN:
|
|
|
|
|
|
|
|
RELEASE(&SP[-2]);
|
2008-08-14 21:42:27 +02:00
|
|
|
OBJECT_UNREF(object, "EXEC_pop_unknown");
|
2007-12-30 17:41:49 +01:00
|
|
|
SP -= 2;
|
|
|
|
PC++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-24 02:36:20 +01:00
|
|
|
void EXEC_pop_array(ushort code)
|
2007-12-30 17:41:49 +01:00
|
|
|
{
|
2010-05-19 17:05:45 +02:00
|
|
|
static const void *jump[] = { &&__POP_GENERIC, &&__POP_QUICK_ARRAY, && __POP_QUICK_COLLECTION, &&__POP_ARRAY };
|
2008-01-24 02:36:20 +01:00
|
|
|
|
2007-12-30 17:41:49 +01:00
|
|
|
CLASS *class;
|
|
|
|
OBJECT *object;
|
|
|
|
GET_NPARAM(np);
|
|
|
|
int i;
|
|
|
|
void *data;
|
2009-07-08 21:57:50 +02:00
|
|
|
bool defined;
|
2007-12-30 17:41:49 +01:00
|
|
|
VALUE *val;
|
|
|
|
VALUE swap;
|
2010-05-19 17:05:45 +02:00
|
|
|
int fast;
|
2007-12-30 17:41:49 +01:00
|
|
|
|
|
|
|
val = &SP[-np];
|
2008-01-24 11:42:42 +01:00
|
|
|
goto *jump[(code >> 6) & 3];
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-24 02:36:20 +01:00
|
|
|
__POP_GENERIC:
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2008-01-24 02:36:20 +01:00
|
|
|
EXEC_object(val, &class, &object, &defined);
|
|
|
|
|
2008-05-10 17:17:07 +02:00
|
|
|
// The first time we access a symbol, we must not be virtual to find it
|
|
|
|
if (defined && object && !VALUE_is_super(val))
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "%s -> %s\n", class->name, val->_object.class->name);
|
|
|
|
class = val->_object.class;
|
|
|
|
}
|
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
fast = 3;
|
2008-01-24 02:36:20 +01:00
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
if (defined)
|
2008-01-24 02:36:20 +01:00
|
|
|
{
|
2010-05-19 17:05:45 +02:00
|
|
|
if (class->quick_array == CQA_ARRAY)
|
|
|
|
fast = 1;
|
|
|
|
else if (class->quick_array == CQA_COLLECTION)
|
|
|
|
fast = 2;
|
2008-01-24 02:36:20 +01:00
|
|
|
}
|
2007-12-30 17:41:49 +01:00
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
*PC |= fast << 6;
|
2008-01-24 02:36:20 +01:00
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
goto __POP_ARRAY_2;
|
|
|
|
|
2008-01-24 02:36:20 +01:00
|
|
|
__POP_QUICK_ARRAY:
|
|
|
|
|
|
|
|
EXEC_object(val, &class, &object, &defined);
|
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
TYPE type = ((CARRAY *)object)->type;
|
|
|
|
|
|
|
|
VALUE_copy(&swap, &val[0]);
|
|
|
|
VALUE_copy(&val[0], &val[-1]);
|
|
|
|
VALUE_copy(&val[-1], &swap);
|
|
|
|
|
|
|
|
VALUE_conv(&val[0], type);
|
|
|
|
|
|
|
|
if (np == 2)
|
2008-01-24 11:42:42 +01:00
|
|
|
{
|
2010-05-19 17:05:45 +02:00
|
|
|
VALUE_conv(&val[1], T_INTEGER);
|
|
|
|
data = CARRAY_get_data((CARRAY *)object, val[1]._integer.value);
|
2008-01-24 11:42:42 +01:00
|
|
|
}
|
2010-05-19 17:05:45 +02:00
|
|
|
else
|
2008-01-24 11:42:42 +01:00
|
|
|
{
|
2010-05-19 17:05:45 +02:00
|
|
|
for (i = 1; i < np; i++)
|
|
|
|
VALUE_conv(&val[i], T_INTEGER);
|
2008-01-24 11:42:42 +01:00
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
data = CARRAY_get_data_multi((CARRAY *)object, (GB_INTEGER *)&val[1], np - 1);
|
2008-01-24 11:42:42 +01:00
|
|
|
}
|
2010-05-19 17:05:45 +02:00
|
|
|
if (!data)
|
|
|
|
PROPAGATE();
|
|
|
|
VALUE_write(val, data, type);
|
|
|
|
|
|
|
|
SP = val + 1;
|
|
|
|
RELEASE_MANY(SP, 2);
|
|
|
|
//OBJECT_UNREF(object, "EXEC_push_array");
|
|
|
|
return;
|
|
|
|
|
|
|
|
__POP_QUICK_COLLECTION:
|
|
|
|
|
|
|
|
EXEC_object(val, &class, &object, &defined);
|
|
|
|
|
|
|
|
VALUE_conv(&val[-1], T_VARIANT);
|
|
|
|
VALUE_conv_string(&val[1]);
|
|
|
|
|
|
|
|
if (GB_CollectionSet((GB_COLLECTION)object, val[1]._string.addr + val[1]._string.start, val[1]._string.len, (GB_VARIANT *)&val[-1]))
|
|
|
|
PROPAGATE();
|
2008-01-24 02:36:20 +01:00
|
|
|
|
2010-05-19 17:05:45 +02:00
|
|
|
RELEASE_MANY(SP, 3);
|
2008-01-24 02:36:20 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
__POP_ARRAY:
|
|
|
|
|
|
|
|
EXEC_object(val, &class, &object, &defined);
|
|
|
|
|
|
|
|
__POP_ARRAY_2:
|
|
|
|
|
2008-01-24 11:42:42 +01:00
|
|
|
/* swap object and value to be inserted */
|
2008-01-24 02:36:20 +01:00
|
|
|
|
2008-03-19 15:32:30 +01:00
|
|
|
//swap = val[0];
|
|
|
|
//val[0] = val[-1];
|
|
|
|
//val[-1] = swap;
|
|
|
|
VALUE_copy(&swap, &val[0]);
|
|
|
|
VALUE_copy(&val[0], &val[-1]);
|
|
|
|
VALUE_copy(&val[-1], &swap);
|
2008-01-24 02:36:20 +01:00
|
|
|
|
|
|
|
if (EXEC_special(SPEC_PUT, class, object, np, TRUE))
|
|
|
|
THROW(E_NARRAY, class->name);
|
|
|
|
|
2008-01-24 11:42:42 +01:00
|
|
|
POP(); /* free the object */
|
2007-12-30 17:41:49 +01:00
|
|
|
}
|