From 171b02449e40827f507cc46cb1c77b85e64b7b22 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 7 Jan 2018 08:00:23 +0000 Subject: [PATCH] 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 --- moo/kernel/Socket.moo | 3 ++ moo/kernel/generr.moo | 5 +-- moo/lib/comp.c | 96 +++++++++++++++++++++++++++++++------------ moo/lib/err.c | 86 +++++++++++++++++++------------------- moo/lib/logfmt.c | 30 +++++++++++++- moo/lib/moo-prv.h | 22 +++++++++- moo/lib/moo.c | 40 ++++++------------ moo/lib/moo.h | 5 +-- 8 files changed, 181 insertions(+), 106 deletions(-) diff --git a/moo/kernel/Socket.moo b/moo/kernel/Socket.moo index 82b9290..1b61752 100644 --- a/moo/kernel/Socket.moo +++ b/moo/kernel/Socket.moo @@ -234,6 +234,9 @@ class X(Object) class(#byte(3)) Y(X) { } +class (#word(2)) Z(Y) +{ +} ##class InetSocketAddress(SocketAddress) ##{ diff --git a/moo/kernel/generr.moo b/moo/kernel/generr.moo index e68286b..3d63522 100644 --- a/moo/kernel/generr.moo +++ b/moo/kernel/generr.moo @@ -77,9 +77,8 @@ class MyObject(Object) 'duplicate class' 'contradictory class definition' 'wrong class name' - 'non-pointer class not allowed to inherit a superclass with trailer size set' - 'not allowed to inherit a #final class' - 'invalid class type size' + 'invalid non-pointer instance size' + 'prohibited inheritance' 'variable declaration not allowed' 'modifier expected' 'wrong modifier' diff --git a/moo/lib/comp.c b/moo/lib/comp.c index a5a0f1d..bdf73ed 100644 --- a/moo/lib/comp.c +++ b/moo/lib/comp.c @@ -413,9 +413,45 @@ static int is_restricted_word (const moo_oocs_t* ucs) static int begin_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); 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) { - 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) @@ -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_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 */ 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.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 { - 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); } @@ -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. */ moo_oop_association_t ass; - moo_ioloc_t type_size_loc; + moo_ioloc_t type_loc; if (!extend && TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) @@ -7147,35 +7183,35 @@ static int __compile_class_definition (moo_t* moo, int extend) { do { - int permit_type_size = 0; + int permit_non_pointer_instsize = 0; if (is_token_symbol(moo, VOCA_BYTE_S)) { /* class(#byte) */ if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_BYTE) <= -1) return -1; GET_TOKEN (moo); - permit_type_size = 1; + permit_non_pointer_instsize = 1; } else if (is_token_symbol(moo, VOCA_CHARACTER_S)) { /* class(#character) */ if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_CHAR) <= -1) return -1; GET_TOKEN (moo); - permit_type_size = 1; + permit_non_pointer_instsize = 1; } else if (is_token_symbol(moo, VOCA_HALFWORD_S)) { /* class(#halfword) */ if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_HALFWORD) <= -1) return -1; GET_TOKEN (moo); - permit_type_size = 1; + permit_non_pointer_instsize = 1; } else if (is_token_symbol(moo, VOCA_WORD_S)) { /* class(#word) */ if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_WORD) <= -1) return -1; GET_TOKEN (moo); - permit_type_size = 1; + permit_non_pointer_instsize = 1; } 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 */ if (_set_class_indexed_type(moo, MOO_OBJ_TYPE_LIWORD) <= -1) return -1; GET_TOKEN (moo); - permit_type_size = 1; + permit_non_pointer_instsize = 1; } 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; } - if (permit_type_size) + if (permit_non_pointer_instsize) { /* class(#byte(20)) * class(#word(3)) * ... */ + type_loc = moo->c->tok.loc; + if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) { 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 * 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. */ - 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; } - type_size_loc = moo->c->tok.loc; GET_TOKEN (moo); if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) @@ -7272,7 +7309,7 @@ static int __compile_class_definition (moo_t* moo, int extend) } 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) { - 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; } @@ -7447,14 +7484,17 @@ static int __compile_class_definition (moo_t* moo, int extend) moo->c->cls.indexed_type != MOO_OBJ_TYPE_OOP) { /* 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; } 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 */ - 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; } } @@ -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) { /* 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; - } /* 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 * 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_error (moo, MOO_SYNERR_CLASSTSIZEINVAL, MOO_NULL, MOO_NULL); /* TODO: enhance error message */ + set_syntax_errbfmt (moo, MOO_SYNERR_NPINSTSIZEINVAL, &type_loc, MOO_NULL, + "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; } } else { /* 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_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 */ 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.type_size = 0; + moo->c->cls.non_pointer_instsize = 0; moo->c->cls.name.len = 0; moo->c->cls.fqn.len = 0; diff --git a/moo/lib/err.c b/moo/lib/err.c index 19d6da0..0ca00f4 100644 --- a/moo/lib/err.c +++ b/moo/lib/err.c @@ -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_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_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_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_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_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_35[] = {'m','o','d','i','f','i','e','r',' ','e','x','p','e','c','t','e','d','\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_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_38[] = {'d','u','p','l','i','c','a','t','e',' ','m','o','d','i','f','i','e','r','\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_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_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_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_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_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_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_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_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_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_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_50[] = {'a','m','b','i','g','u','o','u','s',' ','v','a','r','i','a','b','l','e','\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_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_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_54[] = {'t','o','o',' ','m','a','n','y',' ','a','r','g','u','m','e','n','t','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_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_57[] = {'t','o','o',' ','l','a','r','g','e',' ','b','l','o','c','k','\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_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_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_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_62[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','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_64[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\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_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_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_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_69[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\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_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_72[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\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[] = {'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[] = {'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[] = {'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','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[] = {'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[] = {'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',' ','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',' ','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','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[] = {'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[] = {'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',' ','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',' ','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',' ','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',' ','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',' ','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[] = {'#','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',' ','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[] = {'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[] = {'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[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t* synerrstr[] = { 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_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_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70, synerrstr_71, - synerrstr_72 + synerrstr_64, synerrstr_65, synerrstr_66, synerrstr_67, synerrstr_68, synerrstr_69, synerrstr_70, synerrstr_71 }; #endif /* END: GENERATED WITH generr.moo */ diff --git a/moo/lib/logfmt.c b/moo/lib/logfmt.c index aa25fe2..05b9d9b 100644 --- a/moo/lib/logfmt.c +++ b/moo/lib/logfmt.c @@ -27,7 +27,6 @@ #include "moo-prv.h" /*#include */ /* for snrintf(). used for floating-point number formatting */ -#include #if defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) # 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); 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); +} diff --git a/moo/lib/moo-prv.h b/moo/lib/moo-prv.h index 66b6300..6bb7a3d 100644 --- a/moo/lib/moo-prv.h +++ b/moo/lib/moo-prv.h @@ -29,6 +29,7 @@ #include "moo.h" #include "moo-utl.h" +#include /* you can define this to either 1 or 2 */ #define MOO_BCODE_LONG_PARAM_SIZE 2 @@ -513,7 +514,9 @@ struct moo_compiler_t { int flags; 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_t super_oop; /* this may be nil. so the type is moo_oop_t */ @@ -971,6 +974,23 @@ enum moo_bcode_t extern "C" { #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 */ diff --git a/moo/lib/moo.c b/moo/lib/moo.c index c266909..bc23516 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -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 * 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", - size, - MOO_OBJ_GET_SIZE(_class->name), - MOO_OBJ_GET_CHAR_SLOT(_class->name)); - goto eperm; + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the %.*js class", + size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); + return -1; } spec = MOO_OOP_TO_SMOOI(_class->spec); 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", - size, - MOO_OBJ_GET_SIZE(_class->name), - MOO_OBJ_GET_CHAR_SLOT(_class->name)); - goto eperm; + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to set trailer size to %zu on the non-pointer class %.*js", + size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); + return -1; } if (_class->trsize != 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", - size, - MOO_OBJ_GET_SIZE(_class->name), - MOO_OBJ_GET_CHAR_SLOT(_class->name)); - goto eperm; + moo_seterrbfmt (moo, MOO_EPERM, "not allowed to double-set trailer size to %zu on the %.*js class", + size, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name)); + return -1; } MOO_ASSERT (moo, _class->trgc == moo->_nil); sc = (moo_oop_class_t)_class->superclass; 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", - size, - MOO_OBJ_GET_SIZE(_class->name), - MOO_OBJ_GET_CHAR_SLOT(_class->name), - MOO_OOP_TO_SMOOI(sc->trsize), - MOO_OBJ_GET_SIZE(sc->name), - MOO_OBJ_GET_CHAR_SLOT(sc->name)); - goto eperm; + 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, MOO_OBJ_GET_SIZE(_class->name), MOO_OBJ_GET_CHAR_SLOT(_class->name), + MOO_OOP_TO_SMOOI(sc->trsize), MOO_OBJ_GET_SIZE(sc->name), MOO_OBJ_GET_CHAR_SLOT(sc->name)); + return -1; } /* 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_SMPTR_TO_OOP(trgc), trgc); return 0; - -eperm: - moo_seterrnum (moo, MOO_EPERM); - return -1; } void* moo_getobjtrailer (moo_t* moo, moo_oop_t obj, moo_oow_t* size) diff --git a/moo/lib/moo.h b/moo/lib/moo.h index 031c809..1245735 100644 --- a/moo/lib/moo.h +++ b/moo/lib/moo.h @@ -1543,9 +1543,8 @@ enum moo_synerrnum_t MOO_SYNERR_CLASSDUPL, /* duplicate class */ MOO_SYNERR_CLASSCONTRA, /* contradictory class */ MOO_SYNERR_CLASSNAMEINVAL, /* wrong class name */ - MOO_SYNERR_CLASSTRSIZE, /* non-pointer class now allowed to inherit a superclass with trailer size set */ - MOO_SYNERR_CLASSFINAL, /* now allowed to inherit a #final class */ - MOO_SYNERR_CLASSTSIZEINVAL, /* invalid class type size */ + MOO_SYNERR_NPINSTSIZEINVAL, /* invalid non-pointer instance size */ + MOO_SYNERR_INHERITBANNED, /* prohibited inheritance */ MOO_SYNERR_VARDCLBANNED, /* variable declaration not allowed */ MOO_SYNERR_MODIFIER, /* modifier expected */ MOO_SYNERR_MODIFIERINVAL, /* wrong modifier */