enhanced set_syntax_errbmsg() to set_syntax_errbfmt().

collapsed three separate syntax error code to a single code MOO_SYNERR_INHERITBANNED.
added moo_seterrbfmtv() and moo_seterrufmtv() for internal use
This commit is contained in:
hyunghwan.chung 2018-01-07 08:00:23 +00:00
parent e9b33016a4
commit 171b02449e
8 changed files with 181 additions and 106 deletions

View File

@ -234,6 +234,9 @@ class X(Object)
class(#byte(3)) Y(X) class(#byte(3)) Y(X)
{ {
} }
class (#word(2)) Z(Y)
{
}
##class InetSocketAddress(SocketAddress) ##class InetSocketAddress(SocketAddress)
##{ ##{

View File

@ -77,9 +77,8 @@ class MyObject(Object)
'duplicate class' 'duplicate class'
'contradictory class definition' 'contradictory class definition'
'wrong class name' 'wrong class name'
'non-pointer class not allowed to inherit a superclass with trailer size set' 'invalid non-pointer instance size'
'not allowed to inherit a #final class' 'prohibited inheritance'
'invalid class type size'
'variable declaration not allowed' 'variable declaration not allowed'
'modifier expected' 'modifier expected'
'wrong modifier' 'wrong modifier'

View File

@ -413,9 +413,45 @@ static int is_restricted_word (const moo_oocs_t* ucs)
static int begin_include (moo_t* moo); static int begin_include (moo_t* moo);
static int end_include (moo_t* moo); static int end_include (moo_t* moo);
static void set_syntax_errbmsg (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt, const moo_bch_t* msg) static void set_syntax_errbfmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt, const moo_bch_t* msgfmt, ...)
{ {
if (msg) moo_seterrbfmt (moo, MOO_ESYNERR, "%s", msg); if (msgfmt)
{
va_list ap;
va_start (ap, msgfmt);
moo_seterrbfmtv (moo, MOO_ESYNERR, msgfmt, ap);
va_end (ap);
}
else moo_seterrnum (moo, MOO_ESYNERR);
moo->c->synerr.num = num;
/* The SCO compiler complains of this ternary operation saying:
* error: operands have incompatible types: op ":"
* it seems to complain of type mismatch between *loc and
* moo->c->tok.loc due to 'const' prefixed to loc. */
/*moo->c->synerr.loc = loc? *loc: moo->c->tok.loc;*/
if (loc)
moo->c->synerr.loc = *loc;
else
moo->c->synerr.loc = moo->c->tok.loc;
if (tgt) moo->c->synerr.tgt = *tgt;
else
{
moo->c->synerr.tgt.ptr = MOO_NULL;
moo->c->synerr.tgt.len = 0;
}
}
static void set_syntax_errufmt (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt, const moo_uch_t* msgfmt, ...)
{
if (msgfmt)
{
va_list ap;
va_start (ap, msgfmt);
moo_seterrufmtv (moo, MOO_ESYNERR, msgfmt, ap);
va_end (ap);
}
else moo_seterrnum (moo, MOO_ESYNERR); else moo_seterrnum (moo, MOO_ESYNERR);
moo->c->synerr.num = num; moo->c->synerr.num = num;
@ -439,7 +475,7 @@ static void set_syntax_errbmsg (moo_t* moo, moo_synerrnum_t num, const moo_ioloc
static void set_syntax_error (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt) static void set_syntax_error (moo_t* moo, moo_synerrnum_t num, const moo_ioloc_t* loc, const moo_oocs_t* tgt)
{ {
set_syntax_errbmsg (moo, num, loc, tgt, MOO_NULL); set_syntax_errbfmt (moo, num, loc, tgt, MOO_NULL);
} }
static int copy_string_to (moo_t* moo, const moo_oocs_t* src, moo_oocs_t* dst, moo_oow_t* dst_capa, int append, moo_ooch_t delim_char) static int copy_string_to (moo_t* moo, const moo_oocs_t* src, moo_oocs_t* dst, moo_oow_t* dst_capa, int append, moo_ooch_t delim_char)
@ -6931,17 +6967,17 @@ static int make_defined_class (moo_t* moo)
if (moo->c->cls.flags & CLASS_INDEXED) flags |= MOO_CLASS_SPEC_FLAG_INDEXED; if (moo->c->cls.flags & CLASS_INDEXED) flags |= MOO_CLASS_SPEC_FLAG_INDEXED;
if (moo->c->cls.flags & CLASS_IMMUTABLE) flags |= MOO_CLASS_SPEC_FLAG_IMMUTABLE; if (moo->c->cls.flags & CLASS_IMMUTABLE) flags |= MOO_CLASS_SPEC_FLAG_IMMUTABLE;
if (moo->c->cls.type_size > 0) if (moo->c->cls.non_pointer_instsize > 0)
{ {
/* class(#byte(N)), class(#word(N)), etc */ /* class(#byte(N)), class(#word(N)), etc */
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.flags & CLASS_INDEXED); MOO_ASSERT (moo, moo->c->cls.flags & CLASS_INDEXED);
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.non_pointer_instsize, flags, moo->c->cls.indexed_type);
} }
else else
{ {
MOO_ASSERT (moo, moo->c->cls.type_size == 0); MOO_ASSERT (moo, moo->c->cls.non_pointer_instsize == 0);
spec = MOO_CLASS_SPEC_MAKE (moo->c->cls.var[VAR_INSTANCE].total_count, flags, moo->c->cls.indexed_type); spec = MOO_CLASS_SPEC_MAKE (moo->c->cls.var[VAR_INSTANCE].total_count, flags, moo->c->cls.indexed_type);
} }
@ -7133,7 +7169,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
* NOTE: when extending a class, class-module-import and variable-definition are not allowed. * NOTE: when extending a class, class-module-import and variable-definition are not allowed.
*/ */
moo_oop_association_t ass; moo_oop_association_t ass;
moo_ioloc_t type_size_loc; moo_ioloc_t type_loc;
if (!extend && TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) if (!extend && TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN)
@ -7147,35 +7183,35 @@ static int __compile_class_definition (moo_t* moo, int extend)
{ {
do do
{ {
int permit_type_size = 0; int permit_non_pointer_instsize = 0;
if (is_token_symbol(moo, VOCA_BYTE_S)) if (is_token_symbol(moo, VOCA_BYTE_S))
{ {
/* class(#byte) */ /* class(#byte) */
if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_BYTE) <= -1) return -1; if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_BYTE) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
permit_type_size = 1; permit_non_pointer_instsize = 1;
} }
else if (is_token_symbol(moo, VOCA_CHARACTER_S)) else if (is_token_symbol(moo, VOCA_CHARACTER_S))
{ {
/* class(#character) */ /* class(#character) */
if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_CHAR) <= -1) return -1; if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_CHAR) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
permit_type_size = 1; permit_non_pointer_instsize = 1;
} }
else if (is_token_symbol(moo, VOCA_HALFWORD_S)) else if (is_token_symbol(moo, VOCA_HALFWORD_S))
{ {
/* class(#halfword) */ /* class(#halfword) */
if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_HALFWORD) <= -1) return -1; if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_HALFWORD) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
permit_type_size = 1; permit_non_pointer_instsize = 1;
} }
else if (is_token_symbol(moo, VOCA_WORD_S)) else if (is_token_symbol(moo, VOCA_WORD_S))
{ {
/* class(#word) */ /* class(#word) */
if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_WORD) <= -1) return -1; if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_WORD) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
permit_type_size = 1; permit_non_pointer_instsize = 1;
} }
else if (is_token_symbol(moo, VOCA_LIWORD_S)) else if (is_token_symbol(moo, VOCA_LIWORD_S))
{ {
@ -7184,7 +7220,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
* see the definiton of MOO_OBJ_TYPE_LIWORD in moo.h */ * see the definiton of MOO_OBJ_TYPE_LIWORD in moo.h */
if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_LIWORD) <= -1) return -1; if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_LIWORD) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
permit_type_size = 1; permit_non_pointer_instsize = 1;
} }
else if (is_token_symbol(moo, VOCA_POINTER_S)) else if (is_token_symbol(moo, VOCA_POINTER_S))
{ {
@ -7235,11 +7271,13 @@ static int __compile_class_definition (moo_t* moo, int extend)
return -1; return -1;
} }
if (permit_type_size) if (permit_non_pointer_instsize)
{ {
/* class(#byte(20)) /* class(#byte(20))
* class(#word(3)) * class(#word(3))
* ... */ * ... */
type_loc = moo->c->tok.loc;
if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN)
{ {
moo_ooi_t tmp; moo_ooi_t tmp;
@ -7258,11 +7296,10 @@ static int __compile_class_definition (moo_t* moo, int extend)
/* the class type size has nothing to do with the name instance variables /* the class type size has nothing to do with the name instance variables
* in the semantics. but it is stored into the named-instvar bits in the * in the semantics. but it is stored into the named-instvar bits in the
* spec field of a class. so i check it against MOO_MAX_NAMED_INSTVARS. */ * spec field of a class. so i check it against MOO_MAX_NAMED_INSTVARS. */
set_syntax_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); set_syntax_error (moo, MOO_SYNERR_NPINSTSIZEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
type_size_loc = moo->c->tok.loc;
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN)
@ -7272,7 +7309,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
} }
GET_TOKEN (moo); GET_TOKEN (moo);
moo->c->cls.type_size = tmp; moo->c->cls.non_pointer_instsize = tmp;
} }
} }
@ -7363,7 +7400,7 @@ static int __compile_class_definition (moo_t* moo, int extend)
if (TOKEN_TYPE(moo) != MOO_IOTOK_LPAREN) if (TOKEN_TYPE(moo) != MOO_IOTOK_LPAREN)
{ {
set_syntax_errbmsg (moo, MOO_SYNERR_LPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo), "superclass must be specified"); set_syntax_errbfmt (moo, MOO_SYNERR_LPAREN, TOKEN_LOC(moo), TOKEN_NAME(moo), "superclass must be specified");
return -1; return -1;
} }
@ -7447,14 +7484,17 @@ static int __compile_class_definition (moo_t* moo, int extend)
moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP) moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP)
{ {
/* non-pointer object cannot inherit from a superclass with trailer size set */ /* non-pointer object cannot inherit from a superclass with trailer size set */
set_syntax_error (moo, MOO_SYNERR_CLASSTRSIZE, &moo->c->cls.fqn_loc, &moo->c->cls.fqn); set_syntax_errbfmt (moo, MOO_SYNERR_INHERITBANNED, &moo->c->cls.fqn_loc, &moo->c->cls.fqn,
"the non-pointer class %.*js cannot inherit from a class set with trailer size",
moo->c->cls.fqn.len, moo->c->cls.fqn.ptr);
return -1; return -1;
} }
if (MOO_CLASS_SELFSPEC_FLAGS(MOO_OOP_TO_SMOOI(((moo_oop_class_t)moo->c->cls.super_oop)->selfspec)) & MOO_CLASS_SELFSPEC_FLAG_FINAL) if (MOO_CLASS_SELFSPEC_FLAGS(MOO_OOP_TO_SMOOI(((moo_oop_class_t)moo->c->cls.super_oop)->selfspec)) & MOO_CLASS_SELFSPEC_FLAG_FINAL)
{ {
/* cannot inherit a #final class */ /* cannot inherit a #final class */
set_syntax_error (moo, MOO_SYNERR_CLASSFINAL, &moo->c->cls.fqn_loc, &moo->c->cls.fqn); set_syntax_errbfmt (moo, MOO_SYNERR_INHERITBANNED, &moo->c->cls.fqn_loc, &moo->c->cls.fqn,
"the %.*js class cannot inherit from a final class", moo->c->cls.fqn.len, moo->c->cls.fqn.ptr);
return -1; return -1;
} }
} }
@ -7528,26 +7568,28 @@ static int __compile_class_definition (moo_t* moo, int extend)
if (MOO_CLASS_SPEC_INDEXED_TYPE(spec) == MOO_OBJ_TYPE_OOP && MOO_CLASS_SPEC_NAMED_INSTVARS(spec) > 0) if (MOO_CLASS_SPEC_INDEXED_TYPE(spec) == MOO_OBJ_TYPE_OOP && MOO_CLASS_SPEC_NAMED_INSTVARS(spec) > 0)
{ {
/* a non-pointer object cannot inherit from a pointer object with instance variables */ /* a non-pointer object cannot inherit from a pointer object with instance variables */
set_syntax_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, &moo->c->cls.fqn_loc, &moo->c->cls.fqn); /* TODO: enhance error message */ set_syntax_errbfmt (moo, MOO_SYNERR_INHERITBANNED, &moo->c->cls.fqn_loc, &moo->c->cls.fqn,
"the non-pointer class %.*js cannot inherit from a pointer class defined with instance variables",
moo->c->cls.fqn.len, moo->c->cls.fqn.ptr);
return -1; return -1;
} }
/* NOTE: I don't mandate that the parent and the child be of the same type. /* NOTE: I don't mandate that the parent and the child be of the same type.
* Say, for a parent class(#byte(4)), a child can be defined to be * Say, for a parent class(#byte(4)), a child can be defined to be
* class(#word(4)). */ * class(#word(4)). */
if (moo->c->cls.type_size < MOO_CLASS_SPEC_NAMED_INSTVARS(spec)) if (moo->c->cls.non_pointer_instsize < MOO_CLASS_SPEC_NAMED_INSTVARS(spec))
{ {
//set_syntax_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, &type_size_loc, MOO_NULL); /* TODO: enhance error message */ set_syntax_errbfmt (moo, MOO_SYNERR_NPINSTSIZEINVAL, &type_loc, MOO_NULL,
set_syntax_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, MOO_NULL, MOO_NULL); /* TODO: enhance error message */ "the instance size(%zu) for the non-pointer class %.*js must not be less than the size(%zu) defined in the superclass ",
moo->c->cls.non_pointer_instsize, moo->c->cls.fqn.len, moo->c->cls.fqn.ptr, (moo_oow_t)MOO_CLASS_SPEC_NAMED_INSTVARS(spec));
return -1; return -1;
} }
} }
else else
{ {
/* the class defined is a pointer object or a variable-pointer object */ /* the class defined is a pointer object or a variable-pointer object */
MOO_ASSERT (moo, moo->c->cls.type_size == 0); /* no such thing as class(#pointer(N)). so it must be 0 */ MOO_ASSERT (moo, moo->c->cls.non_pointer_instsize == 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_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);
@ -7716,7 +7758,7 @@ static int compile_class_definition (moo_t* moo, int extend)
/* reset the structure to hold information about a class to be compiled */ /* reset the structure to hold information about a class to be compiled */
moo->c->cls.flags = 0; moo->c->cls.flags = 0;
moo->c->cls.indexed_type = MOO_OBJ_TYPE_OOP; /* whether indexed or not, it's the pointer type by default */ moo->c->cls.indexed_type = MOO_OBJ_TYPE_OOP; /* whether indexed or not, it's the pointer type by default */
moo->c->cls.type_size = 0; moo->c->cls.non_pointer_instsize = 0;
moo->c->cls.name.len = 0; moo->c->cls.name.len = 0;
moo->c->cls.fqn.len = 0; moo->c->cls.fqn.len = 0;

View File

@ -104,48 +104,47 @@ static moo_ooch_t synerrstr_27[] = {'u','n','d','e','f','i','n','e','d',' ','c',
static moo_ooch_t synerrstr_28[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'}; static moo_ooch_t synerrstr_28[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'};
static moo_ooch_t synerrstr_29[] = {'c','o','n','t','r','a','d','i','c','t','o','r','y',' ','c','l','a','s','s',' ','d','e','f','i','n','i','t','i','o','n','\0'}; static moo_ooch_t synerrstr_29[] = {'c','o','n','t','r','a','d','i','c','t','o','r','y',' ','c','l','a','s','s',' ','d','e','f','i','n','i','t','i','o','n','\0'};
static moo_ooch_t synerrstr_30[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_30[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_31[] = {'n','o','n','-','p','o','i','n','t','e','r',' ','c','l','a','s','s',' ','n','o','t',' ','a','l','l','o','w','e','d',' ','t','o',' ','i','n','h','e','r','i','t',' ','a',' ','s','u','p','e','r','c','l','a','s','s',' ','w','i','t','h',' ','t','r','a','i','l','e','r',' ','s','i','z','e',' ','s','e','t','\0'}; static moo_ooch_t synerrstr_31[] = {'i','n','v','a','l','i','d',' ','n','o','n','-','p','o','i','n','t','e','r',' ','i','n','s','t','a','n','c','e',' ','s','i','z','e','\0'};
static moo_ooch_t synerrstr_32[] = {'n','o','t',' ','a','l','l','o','w','e','d',' ','t','o',' ','i','n','h','e','r','i','t',' ','a',' ','#','f','i','n','a','l',' ','c','l','a','s','s','\0'}; static moo_ooch_t synerrstr_32[] = {'p','r','o','h','i','b','i','t','e','d',' ','i','n','h','e','r','i','t','a','n','c','e','\0'};
static moo_ooch_t synerrstr_33[] = {'i','n','v','a','l','i','d',' ','c','l','a','s','s',' ','t','y','p','e',' ','s','i','z','e','\0'}; static moo_ooch_t synerrstr_33[] = {'v','a','r','i','a','b','l','e',' ','d','e','c','l','a','r','a','t','i','o','n',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'};
static moo_ooch_t synerrstr_34[] = {'v','a','r','i','a','b','l','e',' ','d','e','c','l','a','r','a','t','i','o','n',' ','n','o','t',' ','a','l','l','o','w','e','d','\0'}; static moo_ooch_t synerrstr_34[] = {'m','o','d','i','f','i','e','r',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_35[] = {'m','o','d','i','f','i','e','r',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_35[] = {'w','r','o','n','g',' ','m','o','d','i','f','i','e','r','\0'};
static moo_ooch_t synerrstr_36[] = {'w','r','o','n','g',' ','m','o','d','i','f','i','e','r','\0'}; static moo_ooch_t synerrstr_36[] = {'d','i','s','a','l','l','o','w','e','d',' ','m','o','d','i','f','i','e','r','\0'};
static moo_ooch_t synerrstr_37[] = {'d','i','s','a','l','l','o','w','e','d',' ','m','o','d','i','f','i','e','r','\0'}; static moo_ooch_t synerrstr_37[] = {'d','u','p','l','i','c','a','t','e',' ','m','o','d','i','f','i','e','r','\0'};
static moo_ooch_t synerrstr_38[] = {'d','u','p','l','i','c','a','t','e',' ','m','o','d','i','f','i','e','r','\0'}; static moo_ooch_t synerrstr_38[] = {'m','e','t','h','o','d',' ','n','a','m','e',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_39[] = {'m','e','t','h','o','d',' ','n','a','m','e',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_39[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_40[] = {'d','u','p','l','i','c','a','t','e',' ','m','e','t','h','o','d',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_40[] = {'i','n','v','a','l','i','d',' ','v','a','r','i','a','d','i','c',' ','m','e','t','h','o','d',' ','d','e','f','i','n','i','t','i','o','n','\0'};
static moo_ooch_t synerrstr_41[] = {'i','n','v','a','l','i','d',' ','v','a','r','i','a','d','i','c',' ','m','e','t','h','o','d',' ','d','e','f','i','n','i','t','i','o','n','\0'}; static moo_ooch_t synerrstr_41[] = {'v','a','r','i','a','b','l','e',' ','n','a','m','e',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_42[] = {'v','a','r','i','a','b','l','e',' ','n','a','m','e',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_42[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_43[] = {'d','u','p','l','i','c','a','t','e',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_43[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_44[] = {'d','u','p','l','i','c','a','t','e',' ','t','e','m','p','o','r','a','r','y',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_44[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_45[] = {'d','u','p','l','i','c','a','t','e',' ','v','a','r','i','a','b','l','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_45[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_46[] = {'d','u','p','l','i','c','a','t','e',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_46[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'};
static moo_ooch_t synerrstr_47[] = {'u','n','d','e','c','l','a','r','e','d',' ','v','a','r','i','a','b','l','e','\0'}; static moo_ooch_t synerrstr_47[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'};
static moo_ooch_t synerrstr_48[] = {'u','n','u','s','a','b','l','e',' ','v','a','r','i','a','b','l','e',' ','i','n',' ','c','o','m','p','i','l','e','d',' ','c','o','d','e','\0'}; static moo_ooch_t synerrstr_48[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'};
static moo_ooch_t synerrstr_49[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','v','a','r','i','a','b','l','e','\0'}; static moo_ooch_t synerrstr_49[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'};
static moo_ooch_t synerrstr_50[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\0'}; static moo_ooch_t synerrstr_50[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','s','e','l','f','\0'};
static moo_ooch_t synerrstr_51[] = {'i','n','a','c','c','e','s','s','i','b','l','e',' ','s','e','l','f','\0'}; static moo_ooch_t synerrstr_51[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'};
static moo_ooch_t synerrstr_52[] = {'w','r','o','n','g',' ','e','x','p','r','e','s','s','i','o','n',' ','p','r','i','m','a','r','y','\0'}; static moo_ooch_t synerrstr_52[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
static moo_ooch_t synerrstr_53[] = {'t','o','o',' ','m','a','n','y',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; static moo_ooch_t synerrstr_53[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'};
static moo_ooch_t synerrstr_54[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','s','\0'}; static moo_ooch_t synerrstr_54[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'};
static moo_ooch_t synerrstr_55[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','t','e','m','p','o','r','a','r','i','e','s','\0'}; static moo_ooch_t synerrstr_55[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'};
static moo_ooch_t synerrstr_56[] = {'t','o','o',' ','m','a','n','y',' ','b','l','o','c','k',' ','a','r','g','u','m','e','n','t','s','\0'}; static moo_ooch_t synerrstr_56[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'};
static moo_ooch_t synerrstr_57[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\0'}; static moo_ooch_t synerrstr_57[] = {'t','o','o',' ','l','a','r','g','e',' ','a','r','r','a','y',' ','e','x','p','r','e','s','s','i','o','n','\0'};
static moo_ooch_t synerrstr_58[] = {'t','o','o',' ','l','a','r','g','e',' ','a','r','r','a','y',' ','e','x','p','r','e','s','s','i','o','n','\0'}; static moo_ooch_t synerrstr_58[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'};
static moo_ooch_t synerrstr_59[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','n','u','m','b','e','r','\0'}; static moo_ooch_t synerrstr_59[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'};
static moo_ooch_t synerrstr_60[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','i','d','e','n','t','i','f','i','e','r','\0'}; static moo_ooch_t synerrstr_60[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','a','r','g','u','m','e','n','t',' ','d','e','f','i','n','i','t','i','o','n','\0'};
static moo_ooch_t synerrstr_61[] = {'w','r','o','n','g',' ','p','r','i','m','i','t','i','v','e',' ','f','u','n','c','t','i','o','n',' ','a','r','g','u','m','e','n','t',' ','d','e','f','i','n','i','t','i','o','n','\0'}; static moo_ooch_t synerrstr_61[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_62[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_62[] = {'f','a','i','l','e','d',' ','t','o',' ','i','m','p','o','r','t',' ','m','o','d','u','l','e','\0'};
static moo_ooch_t synerrstr_63[] = {'f','a','i','l','e','d',' ','t','o',' ','i','m','p','o','r','t',' ','m','o','d','u','l','e','\0'}; static moo_ooch_t synerrstr_63[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t synerrstr_64[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; static moo_ooch_t synerrstr_64[] = {'w','r','o','n','g',' ','p','r','a','g','m','a',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_65[] = {'w','r','o','n','g',' ','p','r','a','g','m','a',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_65[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_66[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_66[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_67[] = {'w','r','o','n','g',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_67[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_68[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l',' ','d','i','c','t','i','o','n','a','r','y',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_68[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_69[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_69[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'};
static moo_ooch_t synerrstr_70[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','n','o','t',' ','w','i','t','h','i','n',' ','a',' ','l','o','o','p','\0'}; static moo_ooch_t synerrstr_70[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'};
static moo_ooch_t synerrstr_71[] = {'b','r','e','a','k',' ','o','r',' ','c','o','n','t','i','n','u','e',' ','w','i','t','h','i','n',' ','a',' ','b','l','o','c','k','\0'}; static moo_ooch_t synerrstr_71[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_72[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t* synerrstr[] = static moo_ooch_t* synerrstr[] =
{ {
synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7, synerrstr_0, synerrstr_1, synerrstr_2, synerrstr_3, synerrstr_4, synerrstr_5, synerrstr_6, synerrstr_7,
@ -156,8 +155,7 @@ static moo_ooch_t* synerrstr[] =
synerrstr_40, synerrstr_41, synerrstr_42, synerrstr_43, synerrstr_44, synerrstr_45, synerrstr_46, synerrstr_47, synerrstr_40, synerrstr_41, synerrstr_42, synerrstr_43, synerrstr_44, synerrstr_45, synerrstr_46, synerrstr_47,
synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55, synerrstr_48, synerrstr_49, synerrstr_50, synerrstr_51, synerrstr_52, synerrstr_53, synerrstr_54, synerrstr_55,
synerrstr_56, synerrstr_57, synerrstr_58, synerrstr_59, synerrstr_60, synerrstr_61, synerrstr_62, synerrstr_63, synerrstr_56, synerrstr_57, synerrstr_58, synerrstr_59, synerrstr_60, synerrstr_61, synerrstr_62, synerrstr_63,
synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70, synerrstr_71, synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70, synerrstr_71
synerrstr_72
}; };
#endif #endif
/* END: GENERATED WITH generr.moo */ /* END: GENERATED WITH generr.moo */

View File

@ -27,7 +27,6 @@
#include "moo-prv.h" #include "moo-prv.h"
/*#include <stdio.h>*/ /* for snrintf(). used for floating-point number formatting */ /*#include <stdio.h>*/ /* for snrintf(). used for floating-point number formatting */
#include <stdarg.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) #if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
# define snprintf _snprintf # define snprintf _snprintf
@ -766,3 +765,32 @@ void moo_seterrufmt (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, ...)
_errufmtv (moo, fmt, &fo, ap); _errufmtv (moo, fmt, &fo, ap);
va_end (ap); va_end (ap);
} }
void moo_seterrbfmtv (moo_t* moo, moo_errnum_t errnum, const moo_bch_t* fmt, va_list ap)
{
moo_fmtout_t fo;
moo->errnum = errnum;
moo->errmsg.len = 0;
fo.mask = 0; /* not used */
fo.putch = put_errch;
fo.putcs = put_errcs;
_errbfmtv (moo, fmt, &fo, ap);
}
void moo_seterrufmtv (moo_t* moo, moo_errnum_t errnum, const moo_uch_t* fmt, va_list ap)
{
moo_fmtout_t fo;
moo->errnum = errnum;
moo->errmsg.len = 0;
fo.mask = 0; /* not used */
fo.putch = put_errch;
fo.putcs = put_errcs;
_errufmtv (moo, fmt, &fo, ap);
}

View File

@ -29,6 +29,7 @@
#include "moo.h" #include "moo.h"
#include "moo-utl.h" #include "moo-utl.h"
#include <stdarg.h>
/* you can define this to either 1 or 2 */ /* you can define this to either 1 or 2 */
#define MOO_BCODE_LONG_PARAM_SIZE 2 #define MOO_BCODE_LONG_PARAM_SIZE 2
@ -513,7 +514,9 @@ struct moo_compiler_t
{ {
int flags; int flags;
int indexed_type; int indexed_type;
moo_oow_t type_size; /* fixed type size */
/* fixed instance size specified for a non-pointer class. class(#byte(N)), etc */
moo_oow_t non_pointer_instsize;
moo_oop_class_t self_oop; moo_oop_class_t self_oop;
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */ moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
@ -971,6 +974,23 @@ enum moo_bcode_t
extern "C" { extern "C" {
#endif #endif
/* ========================================================================= */
/* err.c */
/* ========================================================================= */
void moo_seterrbfmtv (
moo_t* moo,
moo_errnum_t errnum,
const moo_bch_t* fmt,
va_list ap
);
void moo_seterrufmtv (
moo_t* moo,
moo_errnum_t errnum,
const moo_uch_t* fmt,
va_list ap
);
/* ========================================================================= */ /* ========================================================================= */
/* heap.c */ /* heap.c */

View File

@ -903,45 +903,35 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_
{ {
/* the bytes code emitted by the compiler go to the trailer part /* the bytes code emitted by the compiler go to the trailer part
* regardless of the trailer size. you're not allowed to change it */ * regardless of the trailer size. you're not allowed to change it */
MOO_DEBUG3 (moo, "Not allowed to set trailer size to %zu on the %.*js class\n", moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the %.*js class",
size, size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name));
MOO_OBJ_GET_SIZE(_class->name), return -1;
MOO_OBJ_GET_CHAR_SLOT(_class->name));
goto eperm;
} }
spec = MOO_OOP_TO_SMOOI(_class->spec); spec = MOO_OOP_TO_SMOOI(_class->spec);
if (MOO_CLASS_SPEC_IS_INDEXED(spec) && MOO_CLASS_SPEC_INDEXED_TYPE(spec) != MOO_OBJ_TYPE_OOP) if (MOO_CLASS_SPEC_IS_INDEXED(spec) && MOO_CLASS_SPEC_INDEXED_TYPE(spec) != MOO_OBJ_TYPE_OOP)
{ {
MOO_DEBUG3 (moo, "Not allowed to set trailer size to %zu on the %.*js class representing a non-pointer object\n", moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the non-pointer class %.*js",
size, size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name));
MOO_OBJ_GET_SIZE(_class->name), return -1;
MOO_OBJ_GET_CHAR_SLOT(_class->name));
goto eperm;
} }
if (_class->trsize != moo->_nil) if (_class->trsize != moo->_nil)
{ {
MOO_ASSERT (moo, _class->trgc != moo->_nil); MOO_ASSERT (moo, _class->trgc != moo->_nil);
MOO_DEBUG3 (moo, "Not allowed to re-set trailer size to %zu on the %.*js class\n", moo_seterrbfmt (moo, MOO_EPERM, "not allowed to double-set trailer size to %zu on the %.*js class",
size, size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name));
MOO_OBJ_GET_SIZE(_class->name), return -1;
MOO_OBJ_GET_CHAR_SLOT(_class->name));
goto eperm;
} }
MOO_ASSERT (moo, _class->trgc == moo->_nil); MOO_ASSERT (moo, _class->trgc == moo->_nil);
sc = (moo_oop_class_t)_class->superclass; sc = (moo_oop_class_t)_class->superclass;
if (MOO_OOP_IS_SMOOI(sc->trsize) && size < MOO_OOP_TO_SMOOI(sc->trsize)) if (MOO_OOP_IS_SMOOI(sc->trsize) && size < MOO_OOP_TO_SMOOI(sc->trsize))
{ {
MOO_DEBUG6 (moo, "Not allowed to set the trailer size of %.*js to be smaller(%zu) than that(%zu) of the superclass %.*js\n", moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set the trailer size of %.*js to be smaller(%zu) than that(%zu) of the superclass %.*js",
size, size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name),
MOO_OBJ_GET_SIZE(_class->name), MOO_OOP_TO_SMOOI(sc->trsize), MOO_OBJ_GET_SIZE(sc->name), MOO_OBJ_GET_CHAR_SLOT(sc->name));
MOO_OBJ_GET_CHAR_SLOT(_class->name), return -1;
MOO_OOP_TO_SMOOI(sc->trsize),
MOO_OBJ_GET_SIZE(sc->name),
MOO_OBJ_GET_CHAR_SLOT(sc->name));
goto eperm;
} }
/* you can only set the trailer size once when it's not set yet */ /* you can only set the trailer size once when it's not set yet */
@ -954,10 +944,6 @@ int moo_setclasstrsize (moo_t* moo, moo_oop_class_t _class, moo_oow_t size, moo_
MOO_OBJ_GET_CHAR_SLOT(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name),
MOO_SMPTR_TO_OOP(trgc), trgc); MOO_SMPTR_TO_OOP(trgc), trgc);
return 0; return 0;
eperm:
moo_seterrnum (moo, MOO_EPERM);
return -1;
} }
void* moo_getobjtrailer (moo_t* moo, moo_oop_t obj, moo_oow_t* size) void* moo_getobjtrailer (moo_t* moo, moo_oop_t obj, moo_oow_t* size)

View File

@ -1543,9 +1543,8 @@ enum moo_synerrnum_t
MOO_SYNERR_CLASSDUPL, /* duplicate class */ MOO_SYNERR_CLASSDUPL, /* duplicate class */
MOO_SYNERR_CLASSCONTRA, /* contradictory class */ MOO_SYNERR_CLASSCONTRA, /* contradictory class */
MOO_SYNERR_CLASSNAMEINVAL, /* wrong class name */ MOO_SYNERR_CLASSNAMEINVAL, /* wrong class name */
MOO_SYNERR_CLASSTRSIZE, /* non-pointer class now allowed to inherit a superclass with trailer size set */ MOO_SYNERR_NPINSTSIZEINVAL, /* invalid non-pointer instance size */
MOO_SYNERR_CLASSFINAL, /* now allowed to inherit a #final class */ MOO_SYNERR_INHERITBANNED, /* prohibited inheritance */
MOO_SYNERR_CLASSTSIZEINVAL, /* invalid class type size */
MOO_SYNERR_VARDCLBANNED, /* variable declaration not allowed */ MOO_SYNERR_VARDCLBANNED, /* variable declaration not allowed */
MOO_SYNERR_MODIFIER, /* modifier expected */ MOO_SYNERR_MODIFIER, /* modifier expected */
MOO_SYNERR_MODIFIERINVAL, /* wrong modifier */ MOO_SYNERR_MODIFIERINVAL, /* wrong modifier */