debugged handling of class(#type(N)) processing

This commit is contained in:
hyunghwan.chung 2018-01-06 04:18:10 +00:00
parent f4875ba51d
commit de1f8c9551
3 changed files with 44 additions and 16 deletions

View File

@ -204,7 +204,7 @@ class(#byte(16)) IP6Address(IP4Address)
} }
} }
class(#byte) IP4SocketAddress(IP4Address) class(#byte(19)) IP6SocketAddress(IP6Address)
{ {
method(#class) new method(#class) new
{ {

View File

@ -6931,6 +6931,8 @@ static int make_defined_class (moo_t* moo)
if (moo->c->cls.type_size > 0) if (moo->c->cls.type_size > 0)
{ {
/* class(#byte(N)), class(#word(N)), etc */
/* TODO: ensure that this size is equal to greater than the type size of the parent */
MOO_ASSERT (moo, moo->c->cls.var[VAR_INSTANCE].total_count == 0); MOO_ASSERT (moo, moo->c->cls.var[VAR_INSTANCE].total_count == 0);
MOO_ASSERT (moo, moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP); MOO_ASSERT (moo, moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP);
spec = MOO_CLASS_SPEC_MAKE (moo->c->cls.type_size, flags, moo->c->cls.indexed_type); spec = MOO_CLASS_SPEC_MAKE (moo->c->cls.type_size, flags, moo->c->cls.indexed_type);
@ -7227,7 +7229,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
/* invalid modifier */ /* invalid modifier */
set_syntax_error (moo, MOO_SYNERR_MODIFIERINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); set_syntax_error (moo, MOO_SYNERR_MODIFIERINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
}size 16 specified for fixed-sized(4) class IP6Addre }
if (permit_type_size) if (permit_type_size)
{ {
@ -7370,8 +7372,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
{ {
super_is_nil = 1; super_is_nil = 1;
} }
else if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && else if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
{ {
/* superclass name expected */ /* superclass name expected */
set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); set_syntax_error (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo));
@ -7501,6 +7502,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
return -1; return -1;
} }
MOO_ASSERT (moo, moo->c->cls.super_oop != MOO_NULL);
if (moo->c->cls.super_oop != moo->_nil) if (moo->c->cls.super_oop != moo->_nil)
{ {
/* adjust the instance variable count and the class instance variable /* adjust the instance variable count and the class instance variable
@ -7515,7 +7517,21 @@ static int __compile_class_definition (moo_t* moo, int extend)
/* [NOTE] class variables are not inherited. /* [NOTE] class variables are not inherited.
* so no data about them are not transferred over */ * so no data about them are not transferred over */
moo->c->cls.var[VAR_INSTANCE].total_count = MOO_CLASS_SPEC_NAMED_INSTVARS(spec);
if ((moo->c->cls.flags & CLASS_INDEXED) && moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP)
{
/* TODO: do i need to check if the parent class and the current class have the same indexed type? */
if (moo->c->cls.type_size < MOO_CLASS_SPEC_NAMED_INSTVARS(spec))
{
set_syntax_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); /* TODO: change error location... */
return -1;
}
}
else
{
MOO_ASSERT (moo, moo->c->cls.type_size == 0); /* no such thing as class(#pointer(N)). so it must be 0 */
moo->c->cls.var[VAR_INSTANCE].total_count = MOO_CLASS_SPEC_NAMED_INSTVARS(spec);
}
moo->c->cls.var[VAR_CLASSINST].total_count = MOO_CLASS_SELFSPEC_CLASSINSTVARS(self_spec); moo->c->cls.var[VAR_CLASSINST].total_count = MOO_CLASS_SELFSPEC_CLASSINSTVARS(self_spec);
} }

View File

@ -191,6 +191,7 @@ static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t
{ {
indexed_type = MOO_CLASS_SPEC_INDEXED_TYPE(spec); indexed_type = MOO_CLASS_SPEC_INDEXED_TYPE(spec);
#if 0
if (indexed_type == MOO_OBJ_TYPE_OOP) if (indexed_type == MOO_OBJ_TYPE_OOP)
{ {
if (named_instvar > MOO_MAX_NAMED_INSTVARS) if (named_instvar > MOO_MAX_NAMED_INSTVARS)
@ -209,27 +210,38 @@ static MOO_INLINE int decode_spec (moo_t* moo, moo_oop_class_t _class, moo_oow_t
else else
{ {
/* a non-pointer indexed class can't have named instance variables */ /* a non-pointer indexed class can't have named instance variables */
#if 0 if (named_instvar > MOO_)
if (named_instvar > 0)
{ {
moo_seterrbfmt (moo, MOO_EINVAL, "named instance variables in a variable-nonpointer class %O", _class); moo_seterrbfmt (moo, MOO_EINVAL, "named instance variables in a variable-nonpointer class %O", _class);
return -1; return -1;
} }
#else
if (named_instvar > 0 && vlen > 0)
{
/* disallow the user-defined length if the fixed type size is specified
* and it's greater than 0, the user-defined length is not allowed */
moo_seterrbfmt (moo, MOO_EINVAL, "size %zu specified for fixed-sized(%zu) class %O", vlen, named_instvar, _class);
return -1;
}
#endif
if (vlen > MOO_OBJ_SIZE_MAX) if (vlen > MOO_OBJ_SIZE_MAX)
{ {
moo_seterrbfmt (moo, MOO_EINVAL, "too many unnamed instance variables for a variable-nonpointer class %O - %zu/%zu", _class, vlen, (moo_oow_t)MOO_OBJ_SIZE_MAX); moo_seterrbfmt (moo, MOO_EINVAL, "too many unnamed instance variables for a variable-nonpointer class %O - %zu/%zu", _class, vlen, (moo_oow_t)MOO_OBJ_SIZE_MAX);
return -1; return -1;
} }
} }
#else
/* the size of the fixed area for non-pointer objects are supported.
* the fixed area of a pointer object holds named instance variables
* and a non-pointer object is facilitated with the fixed area of the size
* specified in the class description like #byte(5), #word(10).
*
* when it comes to spec decoding, there is no different between a pointer
* object and a non-pointer object */
if (named_instvar > MOO_MAX_NAMED_INSTVARS)
{
moo_seterrbfmt (moo, MOO_EINVAL, "too many fixed fields for a class %O - %zu/%zu", _class, named_instvar, (moo_oow_t)MOO_MAX_NAMED_INSTVARS);
return -1;
}
if (vlen > MOO_MAX_INDEXED_INSTVARS(named_instvar))
{
moo_seterrbfmt (moo, MOO_EINVAL, "too many variable fields for a class %O - %zu/%zu", _class, vlen, (moo_oow_t)MOO_MAX_INDEXED_INSTVARS(named_instvar));
return -1;
}
MOO_ASSERT (moo, named_instvar + vlen <= MOO_OBJ_SIZE_MAX);
#endif
} }
else else
{ {