diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index f04dc8c..b060261 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -204,7 +204,7 @@ class(#byte(16)) IP6Address(IP4Address) } } -class(#byte) IP4SocketAddress(IP4Address) +class(#byte(19)) IP6SocketAddress(IP6Address) { method(#class) new { diff --git a/moo/lib/comp.c b/moo/lib/comp.c index 52a514a..c0b895b 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -6931,6 +6931,8 @@ static int make_defined_class (moo_t* moo) 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.indexed_type != MOO_OBJ_TYPE_OOP); 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 */ set_syntax_error (moo, MOO_SYNERR_MODIFIERINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); return -1; - }size 16 specified for fixed-sized(4) class IP6Addre + } if (permit_type_size) { @@ -7370,8 +7372,7 @@ static int __compile_class_definition (moo_t* moo, int extend) { super_is_nil = 1; } - else if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && - TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED) + else if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED) { /* superclass name expected */ 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; } + MOO_ASSERT (moo, moo->c->cls.super_oop != MOO_NULL); if (moo->c->cls.super_oop != moo->_nil) { /* 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. * 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); } diff --git a/moo/lib/obj.c b/moo/lib/obj.c index ae164b8..8627271 100644 --- a/moo/lib/obj.c +++ b/moo/lib/obj.c @@ -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); +#if 0 if (indexed_type == MOO_OBJ_TYPE_OOP) { 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 { /* a non-pointer indexed class can't have named instance variables */ -#if 0 - if (named_instvar > 0) + if (named_instvar > MOO_) { moo_seterrbfmt (moo, MOO_EINVAL, "named instance variables in a variable-nonpointer class %O", _class); 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) { 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; } } +#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 {