fixed a compiler to handle imported pool dictionaries properly when extending a class

This commit is contained in:
hyunghwan.chung 2016-08-29 06:10:02 +00:00
parent ff00284426
commit 64395d8815
3 changed files with 141 additions and 57 deletions

View File

@ -54,7 +54,10 @@
#KKK := 20. #KKK := 20.
} }
#pooldic SRX.ABC
{
#JJJ := 1000.
}
#class MyConsole(Console) #class MyConsole(Console)
{ {
#method box: origin corner: corner #method box: origin corner: corner
@ -62,7 +65,7 @@
| tmp | | tmp |
self setCursor: origin. self setCursor: origin.
self write: '+'. self write: '+'.
(corner x - origin x - 2) timesRepeat: [self write: '-']. (corner x - origin x - 1) timesRepeat: [self write: '-'].
self write: '+'. self write: '+'.
tmp := Point new. tmp := Point new.
@ -80,13 +83,15 @@
tmp x: origin x y: corner y. tmp x: origin x y: corner y.
self setCursor: tmp. self setCursor: tmp.
self write: '+'. self write: '+'.
(corner x - origin x - 2) timesRepeat: [self write: '-']. (corner x - origin x - 1) timesRepeat: [self write: '-'].
self write: '+'. self write: '+'.
} }
} }
#class MyObject(TestObject) #class MyObject(TestObject)
{ {
#dcl(#pooldic) ABC SRX.ABC.
#method(#class) main #method(#class) main
{ {
| v1 v2 | | v1 v2 |
@ -99,8 +104,18 @@
v1 write: S'하하하하하하하하 (^o^) ほのかちゃん \n'. v1 write: S'하하하하하하하하 (^o^) ほのかちゃん \n'.
v1 close. v1 close.
self main2.
System logNl: S'\0\0\0END OF MAIN\0AB\0\0\0C\0\0\0'. System logNl: S'\0\0\0END OF MAIN\0AB\0\0\0C\0\0\0'.
} }
} }
#extend MyObject
{
#method(#class) main2
{
System logNl: KKK.
System logNl: SRX.ABC.JJJ.
System logNl: JJJ.
}
}

View File

@ -2313,6 +2313,38 @@ static int resolve_pooldic (stix_t* stix, int dotted, const stix_oocs_t* name)
return 0; return 0;
} }
static int import_pool_dictionary (stix_t* stix, stix_oop_set_t ns_oop, const stix_oocs_t* tok_lastseg, const stix_oocs_t* tok_name, const stix_ioloc_t* tok_loc)
{
stix_oop_association_t ass;
stix_oow_t i;
/* check if the name refers to a pool dictionary */
ass = stix_lookupdic (stix, ns_oop, tok_lastseg);
if (!ass || STIX_CLASSOF(stix, ass->value) != stix->_pool_dictionary)
{
set_syntax_error (stix, STIX_SYNERR_POOLDIC, tok_loc, tok_name);
return -1;
}
/* check if the same dictionary pool has been declared for import */
for (i = 0; i < stix->c->cls.pooldic_count; i++)
{
if ((stix_oop_set_t)ass->value == stix->c->cls.pooldic_oops[i])
{
set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, tok_loc, tok_name);
return -1;
}
}
if (add_pool_dictionary(stix, tok_name, (stix_oop_set_t)ass->value) <= -1) return -1;
if (copy_string_to (stix, tok_name, &stix->c->cls.pooldic, &stix->c->cls.pooldic_capa, 1, ' ') <= -1)
{
stix->c->cls.pooldic_count--; /* roll back add_pool_dictionary() */
return -1;
}
return 0;
}
static int compile_class_level_variables (stix_t* stix) static int compile_class_level_variables (stix_t* stix)
{ {
@ -2357,8 +2389,6 @@ static int compile_class_level_variables (stix_t* stix)
* #dcl(#pooldic) ... */ * #dcl(#pooldic) ... */
stix_oocs_t last; stix_oocs_t last;
stix_oop_set_t ns_oop; stix_oop_set_t ns_oop;
stix_oop_association_t ass;
stix_oow_t i;
do do
{ {
@ -2374,31 +2404,7 @@ static int compile_class_level_variables (stix_t* stix)
} }
else break; else break;
/* check if the name refers to a pool dictionary */ if (import_pool_dictionary(stix, ns_oop, &last, &stix->c->tok.name, &stix->c->tok.loc) <= -1) return -1;
ass = stix_lookupdic (stix, ns_oop, &last);
if (!ass || STIX_CLASSOF(stix, ass->value) != stix->_pool_dictionary)
{
set_syntax_error (stix, STIX_SYNERR_POOLDIC, &stix->c->tok.loc, &stix->c->tok.name);
return -1;
}
/* check if the same dictionary pool has been declared for import */
for (i = 0; i < stix->c->cls.pooldic_count; i++)
{
if ((stix_oop_set_t)ass->value == stix->c->cls.pooldic_oops[i])
{
set_syntax_error (stix, STIX_SYNERR_POOLDICDUP, &stix->c->tok.loc, &stix->c->tok.name);
return -1;
}
}
if (add_pool_dictionary(stix, &stix->c->tok.name, (stix_oop_set_t)ass->value) <= -1) return -1;
if (copy_string_to (stix, &stix->c->tok.name, &stix->c->cls.pooldic, &stix->c->cls.pooldic_capa, 1, ' ') <= -1)
{
stix->c->cls.pooldic_count--;
return -1;
}
GET_TOKEN (stix); GET_TOKEN (stix);
} }
while (1); while (1);
@ -4428,15 +4434,15 @@ static int make_defined_class (stix_t* stix)
if (!tmp) return -1; if (!tmp) return -1;
stix->c->cls.self_oop->name = (stix_oop_char_t)tmp; stix->c->cls.self_oop->name = (stix_oop_char_t)tmp;
tmp = stix_makestring (stix, stix->c->cls.vars[0].ptr, stix->c->cls.vars[0].len); tmp = stix_makestring (stix, stix->c->cls.vars[VAR_INSTANCE].ptr, stix->c->cls.vars[VAR_INSTANCE].len);
if (!tmp) return -1; if (!tmp) return -1;
stix->c->cls.self_oop->instvars = (stix_oop_char_t)tmp; stix->c->cls.self_oop->instvars = (stix_oop_char_t)tmp;
tmp = stix_makestring (stix, stix->c->cls.vars[1].ptr, stix->c->cls.vars[1].len); tmp = stix_makestring (stix, stix->c->cls.vars[VAR_CLASS].ptr, stix->c->cls.vars[VAR_CLASS].len);
if (!tmp) return -1; if (!tmp) return -1;
stix->c->cls.self_oop->classvars = (stix_oop_char_t)tmp; stix->c->cls.self_oop->classvars = (stix_oop_char_t)tmp;
tmp = stix_makestring (stix, stix->c->cls.vars[2].ptr, stix->c->cls.vars[2].len); tmp = stix_makestring (stix, stix->c->cls.vars[VAR_CLASSINST].ptr, stix->c->cls.vars[VAR_CLASSINST].len);
if (!tmp) return -1; if (!tmp) return -1;
stix->c->cls.self_oop->classinstvars = (stix_oop_char_t)tmp; stix->c->cls.self_oop->classinstvars = (stix_oop_char_t)tmp;
@ -4728,6 +4734,8 @@ static int __compile_class_definition (stix_t* stix, int extend)
if (extend) if (extend)
{ {
stix_oop_char_t pds;
/* when a class is extended, a new variable cannot be added */ /* when a class is extended, a new variable cannot be added */
if (is_token_symbol(stix, VOCA_DCL) || is_token_symbol(stix, VOCA_DECLARE)) if (is_token_symbol(stix, VOCA_DCL) || is_token_symbol(stix, VOCA_DECLARE))
{ {
@ -4738,6 +4746,57 @@ static int __compile_class_definition (stix_t* stix, int extend)
/* use the method dictionary of an existing class object */ /* use the method dictionary of an existing class object */
stix->c->cls.mthdic_oop[MTH_INSTANCE] = stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_INSTANCE]; stix->c->cls.mthdic_oop[MTH_INSTANCE] = stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_INSTANCE];
stix->c->cls.mthdic_oop[MTH_CLASS] = stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_CLASS]; stix->c->cls.mthdic_oop[MTH_CLASS] = stix->c->cls.self_oop->mthdic[STIX_CLASS_MTHDIC_CLASS];
/* load the pooldic definition from the existing class object */
pds = stix->c->cls.self_oop->pooldics;
if ((stix_oop_t)pds != stix->_nil)
{
stix_ooch_t* ptr, * end;
STIX_ASSERT (STIX_CLASSOF(stix, pds) == stix->_string);
ptr = pds->slot;
end = pds->slot + STIX_OBJ_GET_SIZE(pds);
/* this loop handles the pooldics string as if it's a pooldic import.
* see compile_class_level_variables() for mostly identical code except token handling */
do
{
stix_oocs_t last, tok;
stix_ioloc_t loc;
int dotted = 0;
stix_oop_set_t ns_oop;
while (ptr < end && is_spacechar(*ptr)) ptr++;
if (ptr >= end) break;
STIX_MEMSET (&loc, 0, STIX_SIZEOF(loc)); /* fake location */
tok.ptr = ptr;
while (ptr < end && !is_spacechar(*ptr))
{
if (*ptr == '.') dotted = 1;
ptr++;
}
tok.len = ptr - tok.ptr;
STIX_ASSERT (tok.len > 0);
if (dotted)
{
if (preprocess_dotted_name(stix, 0, 0, &tok, &loc, &last, &ns_oop) <= -1) return -1;
}
else
{
last = tok;
/* it falls back to the name space of the class */
ns_oop = stix->c->cls.ns_oop;
}
if (import_pool_dictionary(stix, ns_oop, &last, &tok, &loc) <= -1) return -1;
}
while (1);
}
} }
else else
{ {

View File

@ -291,21 +291,29 @@ typedef enum stix_obj_type_t stix_obj_type_t;
#define STIX_OBJ_FLAGS_NGC_BITS 1 #define STIX_OBJ_FLAGS_NGC_BITS 1
#define STIX_OBJ_FLAGS_TRAILER_BITS 1 #define STIX_OBJ_FLAGS_TRAILER_BITS 1
#define STIX_OBJ_GET_FLAGS_TYPE(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_TYPE_BITS) #define STIX_OBJ_FLAGS_TYPE_SHIFT (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_UNIT_SHIFT)
#define STIX_OBJ_GET_FLAGS_UNIT(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_UNIT_BITS) #define STIX_OBJ_FLAGS_UNIT_SHIFT (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_EXTRA_SHIFT)
#define STIX_OBJ_GET_FLAGS_EXTRA(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_EXTRA_BITS) #define STIX_OBJ_FLAGS_EXTRA_SHIFT (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_KERNEL_SHIFT)
#define STIX_OBJ_GET_FLAGS_KERNEL(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_KERNEL_BITS) #define STIX_OBJ_FLAGS_KERNEL_SHIFT (STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_MOVED_SHIFT)
#define STIX_OBJ_GET_FLAGS_MOVED(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_MOVED_BITS) #define STIX_OBJ_FLAGS_MOVED_SHIFT (STIX_OBJ_FLAGS_NGC_BITS + STIX_OBJ_FLAGS_NGC_SHIFT)
#define STIX_OBJ_GET_FLAGS_NGC(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_TRAILER_BITS), STIX_OBJ_FLAGS_MOVED_BITS) #define STIX_OBJ_FLAGS_NGC_SHIFT (STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_TRAILER_SHIFT)
#define STIX_OBJ_GET_FLAGS_TRAILER(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, 0, STIX_OBJ_FLAGS_TRAILER_BITS) #define STIX_OBJ_FLAGS_TRAILER_SHIFT (0)
#define STIX_OBJ_SET_FLAGS_TYPE(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_TYPE_BITS, v) #define STIX_OBJ_GET_FLAGS_TYPE(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TYPE_SHIFT, STIX_OBJ_FLAGS_TYPE_BITS)
#define STIX_OBJ_SET_FLAGS_UNIT(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_UNIT_BITS, v) #define STIX_OBJ_GET_FLAGS_UNIT(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_UNIT_SHIFT, STIX_OBJ_FLAGS_UNIT_BITS)
#define STIX_OBJ_SET_FLAGS_EXTRA(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_EXTRA_BITS, v) #define STIX_OBJ_GET_FLAGS_EXTRA(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_EXTRA_SHIFT, STIX_OBJ_FLAGS_EXTRA_BITS)
#define STIX_OBJ_SET_FLAGS_KERNEL(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_KERNEL_BITS, v) #define STIX_OBJ_GET_FLAGS_KERNEL(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_KERNEL_SHIFT, STIX_OBJ_FLAGS_KERNEL_BITS)
#define STIX_OBJ_SET_FLAGS_MOVED(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS), STIX_OBJ_FLAGS_MOVED_BITS, v) #define STIX_OBJ_GET_FLAGS_MOVED(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_MOVED_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS)
#define STIX_OBJ_SET_FLAGS_NGC(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, (STIX_OBJ_FLAGS_TRAILER_BITS), STIX_OBJ_FLAGS_MOVED_BITS, v) #define STIX_OBJ_GET_FLAGS_NGC(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TRAILER_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS)
#define STIX_OBJ_SET_FLAGS_TRAILER(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, 0, STIX_OBJ_FLAGS_TRAILER_BITS, v) #define STIX_OBJ_GET_FLAGS_TRAILER(oop) STIX_GETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TRAILER_SHIFT, STIX_OBJ_FLAGS_TRAILER_BITS)
#define STIX_OBJ_SET_FLAGS_TYPE(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TYPE_SHIFT, STIX_OBJ_FLAGS_TYPE_BITS, v)
#define STIX_OBJ_SET_FLAGS_UNIT(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_UNIT_SHIFT, STIX_OBJ_FLAGS_UNIT_BITS, v)
#define STIX_OBJ_SET_FLAGS_EXTRA(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_EXTRA_SHIFT, STIX_OBJ_FLAGS_EXTRA_BITS, v)
#define STIX_OBJ_SET_FLAGS_KERNEL(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_KERNEL_SHIFT, STIX_OBJ_FLAGS_KERNEL_BITS, v)
#define STIX_OBJ_SET_FLAGS_MOVED(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_MOVED_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS, v)
#define STIX_OBJ_SET_FLAGS_NGC(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_NGC_SHIFT, STIX_OBJ_FLAGS_MOVED_BITS, v)
#define STIX_OBJ_SET_FLAGS_TRAILER(oop,v) STIX_SETBITS(stix_oow_t, (oop)->_flags, STIX_OBJ_FLAGS_TRAILER_SHIFT, STIX_OBJ_FLAGS_TRAILER_BITS, v)
#define STIX_OBJ_GET_SIZE(oop) ((oop)->_size) #define STIX_OBJ_GET_SIZE(oop) ((oop)->_size)
#define STIX_OBJ_GET_CLASS(oop) ((oop)->_class) #define STIX_OBJ_GET_CLASS(oop) ((oop)->_class)
@ -320,13 +328,13 @@ typedef enum stix_obj_type_t stix_obj_type_t;
* make sure that the value of each bit fields given falls within the * make sure that the value of each bit fields given falls within the
* possible range of the defined bits */ * possible range of the defined bits */
#define STIX_OBJ_MAKE_FLAGS(t,u,e,k,m,g,r) ( \ #define STIX_OBJ_MAKE_FLAGS(t,u,e,k,m,g,r) ( \
(((stix_oow_t)(t)) << (STIX_OBJ_FLAGS_UNIT_BITS + STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS)) | \ (((stix_oow_t)(t)) << STIX_OBJ_FLAGS_TYPE_SHIFT) | \
(((stix_oow_t)(u)) << (STIX_OBJ_FLAGS_EXTRA_BITS + STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS)) | \ (((stix_oow_t)(u)) << STIX_OBJ_FLAGS_UNIT_SHIFT) | \
(((stix_oow_t)(e)) << (STIX_OBJ_FLAGS_KERNEL_BITS + STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS)) | \ (((stix_oow_t)(e)) << STIX_OBJ_FLAGS_EXTRA_SHIFT) | \
(((stix_oow_t)(k)) << (STIX_OBJ_FLAGS_MOVED_BITS + STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS)) | \ (((stix_oow_t)(k)) << STIX_OBJ_FLAGS_KERNEL_SHIFT) | \
(((stix_oow_t)(m)) << (STIX_OBJ_FLAGS_TRAILER_BITS + STIX_OBJ_FLAGS_NGC_BITS)) | \ (((stix_oow_t)(m)) << STIX_OBJ_FLAGS_MOVED_SHIFT) | \
(((stix_oow_t)(g)) << (STIX_OBJ_FLAGS_TRAILER_BITS)) | \ (((stix_oow_t)(g)) << STIX_OBJ_FLAGS_NGC_SHIFT) | \
(((stix_oow_t)(r)) << 0) \ (((stix_oow_t)(r)) << STIX_OBJ_FLAGS_TRAILER_SHIFT) \
) )
#define STIX_OBJ_HEADER \ #define STIX_OBJ_HEADER \
@ -909,6 +917,8 @@ struct stix_t
* also you must not call this macro more than once */ * also you must not call this macro more than once */
#define STIX_STACK_SETRET(stix,nargs,retv) (STIX_STACK_POPS(stix, nargs), STIX_STACK_SETTOP(stix, retv)) #define STIX_STACK_SETRET(stix,nargs,retv) (STIX_STACK_POPS(stix, nargs), STIX_STACK_SETTOP(stix, retv))
#define STIX_STACK_SETRETTORCV(stix,nargs) (STIX_STACK_POPS(stix, nargs)) #define STIX_STACK_SETRETTORCV(stix,nargs) (STIX_STACK_POPS(stix, nargs))
/* ========================================================================= /* =========================================================================
* STIX VM LOGGING * STIX VM LOGGING
* ========================================================================= */ * ========================================================================= */