added much more code to implement interface. still work in progress

This commit is contained in:
hyunghwan.chung 2018-10-09 15:21:58 +00:00
parent 90ed6d91e3
commit 4ae2ae6f88
8 changed files with 250 additions and 241 deletions

View File

@ -38,8 +38,8 @@ class(#pointer,#limited) Class(Apex)
method nsdic { ^self.nsdic } method nsdic { ^self.nsdic }
} }
class(#pointer,#limited) Interface(Apex)
class(#pointer,#limited) Interface(Class)
{ {
### TODO: fill this class with methods var name.
var instmthdic, classmthdic, nsup.
} }

View File

@ -1,5 +1,11 @@
#include 'Moo.moo'. #include 'Moo.moo'.
interface X11able
{
method(#dual) abc.
method(#dual) def.
}
class X11(Object) from 'x11' class X11(Object) from 'x11'
{ {
## ===================================================================== ## =====================================================================
@ -47,6 +53,21 @@ class X11(Object) from 'x11'
} }
} }
(*
TODO: TODO: compiler enhancement
class X11(Object)
{
class Rectangl(Object)
{
}
}
class XRect(X11.X11.Rectangl) -> X11 in X11.Rectangl is not the inner X11. as long as a period is found, the search begins at top.
{
}
----> should i support soemthign like ::X11.Rectangle and X11.Rectangle? ::X11.Rectangle alwasy from the top???
-----> or .X11.Rectangle -> to start search from the current name space???
*)
method(#primitive,#liberal) _open_display(name). method(#primitive,#liberal) _open_display(name).
method(#primitive) _close_display. method(#primitive) _close_display.
method(#primitive) _get_fd. method(#primitive) _get_fd.

View File

@ -76,10 +76,10 @@ class MyObject(Object)
'integer expected' 'integer expected'
'primitive: expected' 'primitive: expected'
'wrong directive' 'wrong directive'
'wrong name'
'duplicate name'
'undefined class' 'undefined class'
'duplicate class'
'contradictory class definition' 'contradictory class definition'
'wrong class name'
'invalid non-pointer instance size' 'invalid non-pointer instance size'
'prohibited inheritance' 'prohibited inheritance'
'variable declaration not allowed' 'variable declaration not allowed'
@ -111,13 +111,12 @@ class MyObject(Object)
'wrong primitive function number' 'wrong primitive function number'
'wrong primitive function identifier' 'wrong primitive function identifier'
'wrong primitive function argument definition' 'wrong primitive function argument definition'
'wrong module name'
'failed to import module' 'failed to import module'
'#include error' '#include error'
'wrong pragma name' 'wrong pragma name'
'wrong namespace name' 'wrong namespace name'
'wrong pool dictionary name' 'wrong pooldicimport name'
'duplicate pool dictionary name' 'duplicate pooldicimport name'
'literal expected' 'literal expected'
'break or continue not within a loop' 'break or continue not within a loop'
'break or continue within a block' 'break or continue within a block'

View File

@ -3085,40 +3085,60 @@ static int clone_keyword (moo_t* moo, const moo_oocs_t* name, moo_oow_t* offset)
return 0; return 0;
} }
static int add_method_name_fragment (moo_t* moo, const moo_oocs_t* name) static int add_method_name_fragment (moo_t* moo, moo_method_data_t* mth, const moo_oocs_t* name)
{ {
/* method name fragments are concatenated without any delimiters */ /* method name fragments are concatenated without any delimiters */
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; return copy_string_to (moo, name, &mth->name, &mth->name_capa, 1, '\0');
return copy_string_to (moo, name, &cc->mth.name, &cc->mth.name_capa, 1, '\0');
} }
static int method_exists (moo_t* moo, const moo_oocs_t* name) static int method_exists (moo_t* moo, const moo_oocs_t* name)
{ {
/* check if the current class contains a method of the given name */ if (moo->c->cunit->cunit_type == MOO_CUNIT_INTERFACE)
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
if (cc->mth.type == MOO_METHOD_DUAL)
{ {
return moo_lookupdic(moo, cc->self_oop->mthdic[0], name) != MOO_NULL || /* TODO: remove duplicate code */
moo_lookupdic(moo, cc->self_oop->mthdic[1], name) != MOO_NULL; moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
if (ifce->mth.type == MOO_METHOD_DUAL)
{
return moo_lookupdic(moo, ifce->self_oop->mthdic[0], name) != MOO_NULL ||
moo_lookupdic(moo, ifce->self_oop->mthdic[1], name) != MOO_NULL;
}
else
{
MOO_ASSERT (moo, ifce->mth.type < MOO_COUNTOF(ifce->self_oop->mthdic));
return moo_lookupdic(moo, ifce->self_oop->mthdic[ifce->mth.type], name) != MOO_NULL;
}
} }
else else
{ {
MOO_ASSERT (moo, cc->mth.type < MOO_COUNTOF(cc->self_oop->mthdic)); /* this function must be called from the inteface or the class context only */
return moo_lookupdic(moo, cc->self_oop->mthdic[cc->mth.type], name) != MOO_NULL; MOO_ASSERT (moo, moo->c->cunit->cunit_type == MOO_CUNIT_CLASS);
/* check if the current class contains a method of the given name */
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
if (cc->mth.type == MOO_METHOD_DUAL)
{
return moo_lookupdic(moo, cc->self_oop->mthdic[0], name) != MOO_NULL ||
moo_lookupdic(moo, cc->self_oop->mthdic[1], name) != MOO_NULL;
}
else
{
MOO_ASSERT (moo, cc->mth.type < MOO_COUNTOF(cc->self_oop->mthdic));
return moo_lookupdic(moo, cc->self_oop->mthdic[cc->mth.type], name) != MOO_NULL;
}
} }
} }
static int add_temporary_variable (moo_t* moo, const moo_oocs_t* name) static int add_temporary_variable (moo_t* moo, moo_method_data_t* mth, const moo_oocs_t* name)
{ {
/* temporary variable names are added to the string with leading /* temporary variable names are added to the string with leading
* space if it's not the first variable */ * space if it's not the first variable */
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; return copy_string_to(moo, name, &mth->tmprs, &mth->tmprs_capa, 1, ' ');
return copy_string_to(moo, name, &cc->mth.tmprs, &cc->mth.tmprs_capa, 1, ' ');
} }
static MOO_INLINE int find_temporary_variable (moo_t* moo, const moo_oocs_t* name, moo_oow_t* xindex) static MOO_INLINE int find_temporary_variable (moo_t* moo, moo_method_data_t* mth, const moo_oocs_t* name, moo_oow_t* xindex)
{ {
return find_word_in_string(&((moo_cunit_class_t*)moo->c->cunit)->mth.tmprs, name, xindex); return find_word_in_string(&mth->tmprs, name, xindex);
} }
static moo_oop_nsdic_t add_namespace (moo_t* moo, moo_oop_nsdic_t dic, const moo_oocs_t* name) static moo_oop_nsdic_t add_namespace (moo_t* moo, moo_oop_nsdic_t dic, const moo_oocs_t* name)
@ -3306,7 +3326,7 @@ static int import_pool_dictionary (moo_t* moo, moo_oop_nsdic_t ns_oop, const moo
ass = moo_lookupdic(moo, (moo_oop_dic_t)ns_oop, tok_lastseg); ass = moo_lookupdic(moo, (moo_oop_dic_t)ns_oop, tok_lastseg);
if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_pool_dictionary) if (!ass || MOO_CLASSOF(moo, ass->value) != moo->_pool_dictionary)
{ {
moo_setsynerr (moo, MOO_SYNERR_POOLDICINVAL, tok_loc, tok_name); moo_setsynerr (moo, MOO_SYNERR_PDIMPINVAL, tok_loc, tok_name);
return -1; return -1;
} }
@ -3315,7 +3335,7 @@ static int import_pool_dictionary (moo_t* moo, moo_oop_nsdic_t ns_oop, const moo
{ {
if ((moo_oop_dic_t)ass->value == cc->pdimp.oops[i]) if ((moo_oop_dic_t)ass->value == cc->pdimp.oops[i])
{ {
moo_setsynerr (moo, MOO_SYNERR_POOLDICDUPL, tok_loc, tok_name); moo_setsynerr (moo, MOO_SYNERR_PDIMPDUPL, tok_loc, tok_name);
return -1; return -1;
} }
} }
@ -3685,20 +3705,18 @@ static int compile_class_level_imports (moo_t* moo)
return 0; return 0;
} }
static int compile_unary_method_name (moo_t* moo) static int compile_unary_method_name (moo_t* moo, moo_method_data_t* mth)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; MOO_ASSERT (moo, mth->name.len == 0);
MOO_ASSERT (moo, mth->tmpr_nargs == 0);
MOO_ASSERT (moo, cc->mth.name.len == 0); if (add_method_name_fragment(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 0);
if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN)
{ {
/* this is a procedural style method */ /* this is a procedural style method */
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 0); MOO_ASSERT (moo, mth->tmpr_nargs == 0);
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN)
@ -3712,14 +3730,14 @@ static int compile_unary_method_name (moo_t* moo)
return -1; return -1;
} }
if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) if (find_temporary_variable(moo, mth, TOKEN_NAME(moo), MOO_NULL) >= 0)
{ {
moo_setsynerr (moo, MOO_SYNERR_ARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_ARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_nargs++; mth->tmpr_nargs++;
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break; if (TOKEN_TYPE(moo) == MOO_IOTOK_RPAREN) break;
@ -3742,14 +3760,12 @@ static int compile_unary_method_name (moo_t* moo)
return 0; return 0;
} }
static int compile_binary_method_name (moo_t* moo) static int compile_binary_method_name (moo_t* moo, moo_method_data_t* mth)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; MOO_ASSERT (moo, mth->name.len == 0);
MOO_ASSERT (moo, mth->tmpr_nargs == 0);
MOO_ASSERT (moo, cc->mth.name.len == 0); if (add_method_name_fragment(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 0);
if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
/* collect the argument name */ /* collect the argument name */
@ -3760,16 +3776,16 @@ static int compile_binary_method_name (moo_t* moo)
return -1; return -1;
} }
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 0); MOO_ASSERT (moo, mth->tmpr_nargs == 0);
/* no duplication check is performed against class-level variable names. /* no duplication check is performed against class-level variable names.
* a duplcate name will shade a previsouly defined variable. */ * a duplcate name will shade a previsouly defined variable. */
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_nargs++; mth->tmpr_nargs++;
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 1); MOO_ASSERT (moo, mth->tmpr_nargs == 1);
/* this check should not be not necessary /* this check should not be not necessary
if (cc->mth.tmpr_nargs > MAX_CODE_NARGS) if (mth->tmpr_nargs > MAX_CODE_NARGS)
{ {
moo_setsynerr (moo, MOO_SYNERR_ARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_ARGFLOOD, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
@ -3780,16 +3796,14 @@ static int compile_binary_method_name (moo_t* moo)
return 0; return 0;
} }
static int compile_keyword_method_name (moo_t* moo) static int compile_keyword_method_name (moo_t* moo, moo_method_data_t* mth)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; MOO_ASSERT (moo, mth->name.len == 0);
MOO_ASSERT (moo, mth->tmpr_nargs == 0);
MOO_ASSERT (moo, cc->mth.name.len == 0);
MOO_ASSERT (moo, cc->mth.tmpr_nargs == 0);
do do
{ {
if (add_method_name_fragment(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_method_name_fragment(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT) if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT)
@ -3799,14 +3813,14 @@ static int compile_keyword_method_name (moo_t* moo)
return -1; return -1;
} }
if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) if (find_temporary_variable(moo, mth, TOKEN_NAME(moo), MOO_NULL) >= 0)
{ {
moo_setsynerr (moo, MOO_SYNERR_ARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_ARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_nargs++; mth->tmpr_nargs++;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
@ -3815,7 +3829,7 @@ static int compile_keyword_method_name (moo_t* moo)
return 0; return 0;
} }
static int compile_method_name (moo_t* moo) static int compile_method_name (moo_t* moo, moo_method_data_t* mth)
{ {
/* /*
* method-name := unary-method-name | binary-method-name | keyword-method-name * method-name := unary-method-name | binary-method-name | keyword-method-name
@ -3825,24 +3839,23 @@ static int compile_method_name (moo_t* moo)
* selector-argument := identifier * selector-argument := identifier
* unary-selector := identifier * unary-selector := identifier
*/ */
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
int n; int n;
MOO_ASSERT (moo, cc->mth.tmpr_count == 0); MOO_ASSERT (moo, mth->tmpr_count == 0);
cc->mth.name_loc = moo->c->tok.loc; mth->name_loc = moo->c->tok.loc;
switch (TOKEN_TYPE(moo)) switch (TOKEN_TYPE(moo))
{ {
case MOO_IOTOK_IDENT: case MOO_IOTOK_IDENT:
n = compile_unary_method_name(moo); n = compile_unary_method_name(moo, mth);
break; break;
case MOO_IOTOK_BINSEL: case MOO_IOTOK_BINSEL:
n = compile_binary_method_name(moo); n = compile_binary_method_name(moo, mth);
break; break;
case MOO_IOTOK_KEYWORD: case MOO_IOTOK_KEYWORD:
n = compile_keyword_method_name(moo); n = compile_keyword_method_name(moo, mth);
break; break;
default: default:
@ -3853,25 +3866,25 @@ static int compile_method_name (moo_t* moo)
if (n >= 0) if (n >= 0)
{ {
if (method_exists(moo, &cc->mth.name)) if (method_exists(moo, &mth->name))
{ {
moo_setsynerr (moo, MOO_SYNERR_MTHNAMEDUPL, &cc->mth.name_loc, &cc->mth.name); moo_setsynerr (moo, MOO_SYNERR_MTHNAMEDUPL, &mth->name_loc, &mth->name);
return -1; return -1;
} }
/* compile_unary_method_name() returns 9999 if the name is followed by () */ /* compile_unary_method_name() returns 9999 if the name is followed by () */
if (cc->mth.variadic && n != 9999) if (mth->variadic && n != 9999)
{ {
moo_setsynerr (moo, MOO_SYNERR_VARIADMTHINVAL, &cc->mth.name_loc, &cc->mth.name); moo_setsynerr (moo, MOO_SYNERR_VARIADMTHINVAL, &mth->name_loc, &mth->name);
return -1; return -1;
} }
} }
MOO_ASSERT (moo, cc->mth.tmpr_nargs < MAX_CODE_NARGS); MOO_ASSERT (moo, mth->tmpr_nargs < MAX_CODE_NARGS);
/* the total number of temporaries is equal to the number of /* the total number of temporaries is equal to the number of
* arguments after having processed the message pattern. it's because * arguments after having processed the message pattern. it's because
* moo treats arguments the same as temporaries */ * moo treats arguments the same as temporaries */
cc->mth.tmpr_count = cc->mth.tmpr_nargs; mth->tmpr_count = mth->tmpr_nargs;
return n; return n;
} }
@ -3897,13 +3910,13 @@ static int compile_method_temporaries (moo_t* moo)
* or even a class name in such as case, it shadows the class level variable * or even a class name in such as case, it shadows the class level variable
* name or the class name. however, it can't be the same as another temporary * name or the class name. however, it can't be the same as another temporary
* variable */ * variable */
if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) if (find_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo), MOO_NULL) >= 0)
{ {
moo_setsynerr (moo, MOO_SYNERR_TMPRNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_TMPRNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_count++; cc->mth.tmpr_count++;
if (cc->mth.tmpr_count > MAX_CODE_NARGS) if (cc->mth.tmpr_count > MAX_CODE_NARGS)
@ -4313,7 +4326,7 @@ static MOO_INLINE int find_undotted_ident (moo_t* moo, const moo_oocs_t* name, c
{ {
/* the current class being compiled has been instantiated. /* the current class being compiled has been instantiated.
* look up in the temporary variable list if compiling in a method */ * look up in the temporary variable list if compiling in a method */
if (cc->mth.active && find_temporary_variable(moo, name, &index) >= 0) if (cc->mth.active && find_temporary_variable(moo, &cc->mth, name, &index) >= 0)
{ {
var->type = (index < cc->mth.tmpr_nargs)? VAR_ARGUMENT: VAR_TEMPORARY; var->type = (index < cc->mth.tmpr_nargs)? VAR_ARGUMENT: VAR_TEMPORARY;
var->pos = index; var->pos = index;
@ -4426,13 +4439,13 @@ static int compile_block_temporaries (moo_t* moo)
GET_TOKEN (moo); GET_TOKEN (moo);
while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT) while (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT)
{ {
if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) if (find_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo), MOO_NULL) >= 0)
{ {
moo_setsynerr (moo, MOO_SYNERR_TMPRNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_TMPRNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_count++; cc->mth.tmpr_count++;
if (cc->mth.tmpr_count > MAX_CODE_NTMPRS) if (cc->mth.tmpr_count > MAX_CODE_NTMPRS)
{ {
@ -4524,13 +4537,13 @@ static int compile_block_expression (moo_t* moo)
} }
/* TODO: check conflicting names as well */ /* TODO: check conflicting names as well */
if (find_temporary_variable(moo, TOKEN_NAME(moo), MOO_NULL) >= 0) if (find_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo), MOO_NULL) >= 0)
{ {
moo_setsynerr (moo, MOO_SYNERR_BLKARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_BLKARGNAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
if (add_temporary_variable(moo, TOKEN_NAME(moo)) <= -1) return -1; if (add_temporary_variable(moo, &cc->mth, TOKEN_NAME(moo)) <= -1) return -1;
cc->mth.tmpr_count++; cc->mth.tmpr_count++;
if (cc->mth.tmpr_count > MAX_CODE_NARGS) if (cc->mth.tmpr_count > MAX_CODE_NARGS)
{ {
@ -6692,10 +6705,8 @@ static void reset_method_data (moo_t* moo, moo_method_data_t* mth)
mth->code.len = 0; mth->code.len = 0;
} }
static int process_method_modifiers (moo_t* moo) static int process_method_modifiers (moo_t* moo, moo_method_data_t* mth)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
GET_TOKEN (moo); GET_TOKEN (moo);
if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN) if (TOKEN_TYPE(moo) != MOO_IOTOK_RPAREN)
@ -6705,56 +6716,56 @@ static int process_method_modifiers (moo_t* moo)
if (is_token_symbol(moo, VOCA_CLASS_S)) if (is_token_symbol(moo, VOCA_CLASS_S))
{ {
/* method(#class) */ /* method(#class) */
if (cc->mth.type == MOO_METHOD_CLASS || cc->mth.type == MOO_METHOD_DUAL) if (mth->type == MOO_METHOD_CLASS || mth->type == MOO_METHOD_DUAL)
{ {
moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
cc->mth.type = MOO_METHOD_CLASS; mth->type = MOO_METHOD_CLASS;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
else if (is_token_symbol(moo, VOCA_DUAL_S)) else if (is_token_symbol(moo, VOCA_DUAL_S))
{ {
/* method(#dual) */ /* method(#dual) */
if (cc->mth.type == MOO_METHOD_CLASS || cc->mth.type == MOO_METHOD_DUAL) if (mth->type == MOO_METHOD_CLASS || mth->type == MOO_METHOD_DUAL)
{ {
moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
cc->mth.type = MOO_METHOD_DUAL; mth->type = MOO_METHOD_DUAL;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
else if (is_token_symbol(moo, VOCA_PRIMITIVE_S)) else if (is_token_symbol(moo, VOCA_PRIMITIVE_S))
{ {
/* method(#primitive) */ /* method(#primitive) */
if (cc->mth.primitive) if (mth->primitive)
{ {
/* #primitive duplicate modifier */ /* #primitive duplicate modifier */
moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
cc->mth.primitive = 1; mth->primitive = 1;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
else if (is_token_symbol(moo, VOCA_LENIENT_S)) else if (is_token_symbol(moo, VOCA_LENIENT_S))
{ {
/* method(#lenient) */ /* method(#lenient) */
if (cc->mth.lenient) if (mth->lenient)
{ {
moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
cc->mth.lenient = 1; mth->lenient = 1;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
else if (is_token_symbol(moo, VOCA_VARIADIC_S) || else if (is_token_symbol(moo, VOCA_VARIADIC_S) ||
is_token_symbol(moo, VOCA_LIBERAL_S)) is_token_symbol(moo, VOCA_LIBERAL_S))
{ {
/* method(#variadic) or method(#liberal) */ /* method(#variadic) or method(#liberal) */
if (cc->mth.variadic) if (mth->variadic)
{ {
/* #variadic duplicate modifier */ /* #variadic duplicate modifier */
moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_MODIFIERDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo));
@ -6762,9 +6773,9 @@ static int process_method_modifiers (moo_t* moo)
} }
if (is_token_symbol(moo, VOCA_LIBERAL_S)) if (is_token_symbol(moo, VOCA_LIBERAL_S))
cc->mth.variadic = MOO_METHOD_PREAMBLE_FLAG_LIBERAL; mth->variadic = MOO_METHOD_PREAMBLE_FLAG_LIBERAL;
else else
cc->mth.variadic = MOO_METHOD_PREAMBLE_FLAG_VARIADIC; mth->variadic = MOO_METHOD_PREAMBLE_FLAG_VARIADIC;
GET_TOKEN (moo); GET_TOKEN (moo);
} }
@ -6942,15 +6953,17 @@ static int resolve_primitive_method (moo_t* moo)
static int __compile_method_definition (moo_t* moo) static int __compile_method_definition (moo_t* moo)
{ {
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN) if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN)
{ {
/* process method modifiers */ /* process method modifiers */
if (process_method_modifiers(moo) <= -1) return -1; if (process_method_modifiers(moo, &cc->mth) <= -1) return -1;
} }
if (compile_method_name(moo) <= -1) return -1; if (compile_method_name(moo, &cc->mth) <= -1) return -1;
if (((moo_cunit_class_t*)moo->c->cunit)->mth.primitive) if (cc->mth.primitive)
{ {
/* the primitive method doesn't have body */ /* the primitive method doesn't have body */
if (resolve_primitive_method(moo) <= -1) return -1; if (resolve_primitive_method(moo) <= -1) return -1;
@ -6991,10 +7004,10 @@ static int compile_method_definition (moo_t* moo)
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit; moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
int n; int n;
/* clear data required to compile a method */
MOO_ASSERT (moo, moo->c->balit.count == 0); MOO_ASSERT (moo, moo->c->balit.count == 0);
MOO_ASSERT (moo, moo->c->arlit.count == 0); MOO_ASSERT (moo, moo->c->arlit.count == 0);
/* clear data required to compile a method */
cc->mth.active = 1; cc->mth.active = 1;
reset_method_data (moo, &cc->mth); reset_method_data (moo, &cc->mth);
@ -7013,7 +7026,7 @@ static int make_getter_method (moo_t* moo, const moo_oocs_t* name, const var_inf
MOO_ASSERT (moo, moo->c->arlit.count == 0); MOO_ASSERT (moo, moo->c->arlit.count == 0);
MOO_ASSERT (moo, cc->mth.name.len == 0); MOO_ASSERT (moo, cc->mth.name.len == 0);
if (add_method_name_fragment(moo, name) <= -1) return -1; if (add_method_name_fragment(moo, &cc->mth, name) <= -1) return -1;
switch (var->type) switch (var->type)
{ {
@ -7062,8 +7075,8 @@ static int make_setter_method (moo_t* moo, const moo_oocs_t* name, const var_inf
MOO_ASSERT (moo, moo->c->arlit.count == 0); MOO_ASSERT (moo, moo->c->arlit.count == 0);
MOO_ASSERT (moo, cc->mth.name.len == 0); MOO_ASSERT (moo, cc->mth.name.len == 0);
if (add_method_name_fragment(moo, name) <= -1 || if (add_method_name_fragment(moo, &cc->mth, name) <= -1 ||
add_method_name_fragment(moo, &colons) <= -1) return -1; add_method_name_fragment(moo, &cc->mth, &colons) <= -1) return -1;
switch (var->type) switch (var->type)
{ {
@ -7238,40 +7251,6 @@ static int make_default_initial_values (moo_t* moo, var_type_t var_type)
return 0; return 0;
} }
static int make_defined_interface (moo_t* moo)
{
moo_cunit_class_t* cc = (moo_cunit_class_t*)moo->c->cunit;
moo_oop_t tmp;
/* TODO: instantiate differently... */
tmp = moo_instantiate(moo, moo->_class, MOO_NULL, 0);
if (!tmp) return -1;
cc->self_oop = (moo_oop_class_t)tmp;
tmp = moo_makesymbol(moo, cc->name.ptr, cc->name.len);
if (!tmp) return -1;
cc->self_oop->name = (moo_oop_char_t)tmp;
tmp = (moo_oop_t)moo_makedic(moo, moo->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
cc->self_oop->mthdic[MOO_METHOD_INSTANCE] = (moo_oop_dic_t)tmp;
/* TOOD: good dictionary size */
tmp = (moo_oop_t)moo_makedic(moo, moo->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
cc->self_oop->mthdic[MOO_METHOD_CLASS] = (moo_oop_dic_t)tmp;
if (!moo_putatdic(moo, (moo_oop_dic_t)cc->ns_oop, (moo_oop_t)cc->self_oop->name, (moo_oop_t)cc->self_oop)) return -1;
cc->self_oop->nsup = cc->ns_oop;
cc->self_oop->spec = MOO_SMOOI_TO_OOP(0);
cc->self_oop->selfspec = MOO_SMOOI_TO_OOP(0);
/* TODO: .......... */
return 0;
}
static int make_defined_class (moo_t* moo) static int make_defined_class (moo_t* moo)
{ {
/* this function makes a class object with no functions/methods */ /* this function makes a class object with no functions/methods */
@ -7656,8 +7635,7 @@ static int __compile_class_definition (moo_t* moo, int class_type)
if (process_class_modifiers(moo, &type_loc) <= -1) return -1; if (process_class_modifiers(moo, &type_loc) <= -1) return -1;
} }
if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
{ {
/* class name expected. */ /* class name expected. */
moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo));
@ -7675,7 +7653,7 @@ static int __compile_class_definition (moo_t* moo, int class_type)
if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word(TOKEN_NAME(moo))) if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word(TOKEN_NAME(moo)))
{ {
/* wrong class name */ /* wrong class name */
moo_setsynerr (moo, MOO_SYNERR_CLASSNAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo), "invalid class name");
return -1; return -1;
} }
#endif #endif
@ -7792,7 +7770,7 @@ static int __compile_class_definition (moo_t* moo, int class_type)
/* the object found with the name is not a class object /* the object found with the name is not a class object
* or the the class object found is a fully defined kernel * or the the class object found is a fully defined kernel
* class object */ * class object */
moo_setsynerr (moo, MOO_SYNERR_CLASSDUPL, &cc->fqn_loc, &cc->name); moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEDUPL, &cc->fqn_loc, &cc->name, "duplicate class name");
return -1; return -1;
} }
@ -7818,8 +7796,7 @@ static int __compile_class_definition (moo_t* moo, int class_type)
if (var.type != VAR_GLOBAL) goto unknown_superclass; if (var.type != VAR_GLOBAL) goto unknown_superclass;
if (MOO_CLASSOF(moo, var.u.gbl->value) == moo->_class && MOO_OBJ_GET_FLAGS_KERNEL(var.u.gbl->value) != 1) if (MOO_CLASSOF(moo, var.u.gbl->value) == moo->_class && MOO_OBJ_GET_FLAGS_KERNEL(var.u.gbl->value) != 1)
{ {
/* the value found must be a class and it must not be /* the value found must be a class and it must not be an incomplete internal class object.
* an incomplete internal class object.
* 0(non-kernel object) * 0(non-kernel object)
* 1(incomplete kernel object), * 1(incomplete kernel object),
* 2(complete kernel object) */ * 2(complete kernel object) */
@ -7878,7 +7855,7 @@ static int __compile_class_definition (moo_t* moo, int class_type)
* a period to a dash when mapping the module name to an * a period to a dash when mapping the module name to an
* actual module file. disallowing a dash lowers confusion * actual module file. disallowing a dash lowers confusion
* when loading a module. */ * when loading a module. */
moo_setsynerr (moo, MOO_SYNERR_MODNAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo), "invalid module name");
return -1; return -1;
} }
@ -8144,13 +8121,83 @@ static int compile_class_definition (moo_t* moo, int class_type)
return n; return n;
} }
static int __compile_method_signature (moo_t* moo)
{
moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
if (TOKEN_TYPE(moo) == MOO_IOTOK_LPAREN)
{
/* process method modifiers */
if (process_method_modifiers(moo, &ifce->mth) <= -1) return -1;
}
if (compile_method_name(moo, &ifce->mth) <= -1) return -1;
if (TOKEN_TYPE(moo) != MOO_IOTOK_PERIOD)
{
/* . expected */
moo_setsynerr (moo, MOO_SYNERR_PERIOD, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1;
}
GET_TOKEN (moo);
return 0;
}
static int compile_method_signature (moo_t* moo)
{
moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
int n;
MOO_ASSERT (moo, moo->c->balit.count == 0);
MOO_ASSERT (moo, moo->c->arlit.count == 0);
ifce->mth.active = 1;
reset_method_data (moo, &ifce->mth);
n = __compile_method_signature(moo);
ifce->mth.active = 0;
return n;
}
static int make_defined_interface (moo_t* moo)
{
moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
moo_oop_t tmp;
/* TODO: instantiate differently... */
tmp = moo_instantiate(moo, moo->_interface, MOO_NULL, 0);
if (!tmp) return -1;
ifce->self_oop = (moo_oop_interface_t)tmp;
tmp = moo_makesymbol(moo, ifce->name.ptr, ifce->name.len);
if (!tmp) return -1;
ifce->self_oop->name = (moo_oop_char_t)tmp;
tmp = (moo_oop_t)moo_makedic(moo, moo->_method_dictionary, INSTANCE_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
ifce->self_oop->mthdic[MOO_METHOD_INSTANCE] = (moo_oop_dic_t)tmp;
/* TOOD: good dictionary size */
tmp = (moo_oop_t)moo_makedic(moo, moo->_method_dictionary, CLASS_METHOD_DICTIONARY_SIZE);
if (!tmp) return -1;
ifce->self_oop->mthdic[MOO_METHOD_CLASS] = (moo_oop_dic_t)tmp;
if (!moo_putatdic(moo, (moo_oop_dic_t)ifce->ns_oop, (moo_oop_t)ifce->self_oop->name, (moo_oop_t)ifce->self_oop)) return -1;
ifce->self_oop->nsup = ifce->ns_oop;
return 0;
}
static int __compile_interface_definition (moo_t* moo) static int __compile_interface_definition (moo_t* moo)
{ {
moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit; moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
moo_oop_association_t ass; moo_oop_association_t ass;
if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && if (TOKEN_TYPE(moo) != MOO_IOTOK_IDENT && TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
TOKEN_TYPE(moo) != MOO_IOTOK_IDENT_DOTTED)
{ {
/* interface name expected. */ /* interface name expected. */
moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_IDENT, TOKEN_LOC(moo), TOKEN_NAME(moo));
@ -8168,7 +8215,7 @@ static int __compile_interface_definition (moo_t* moo)
if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word(TOKEN_NAME(moo))) if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word(TOKEN_NAME(moo)))
{ {
/* wrong class name */ /* wrong class name */
moo_setsynerr (moo, MOO_SYNERR_CLASSNAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_NAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo), "invalid interface name");
return -1; return -1;
} }
#endif #endif
@ -8183,7 +8230,7 @@ static int __compile_interface_definition (moo_t* moo)
if (ifce->cunit_parent && ifce->cunit_parent->cunit_type == MOO_CUNIT_CLASS) if (ifce->cunit_parent && ifce->cunit_parent->cunit_type == MOO_CUNIT_CLASS)
{ {
/* nested inside a class */ /* nested inside a class */
moo_cunit_interface_t* c = (moo_cunit_interface_t*)ifce->cunit_parent; moo_cunit_class_t* c = (moo_cunit_class_t*)ifce->cunit_parent;
if ((moo_oop_t)c->self_oop->nsdic == moo->_nil) if ((moo_oop_t)c->self_oop->nsdic == moo->_nil)
{ {
/* attach a new namespace dictionary to the nsdic field of the class */ /* attach a new namespace dictionary to the nsdic field of the class */
@ -8206,13 +8253,11 @@ static int __compile_interface_definition (moo_t* moo)
ass = moo_lookupdic(moo, (moo_oop_dic_t)ifce->ns_oop, &ifce->name); ass = moo_lookupdic(moo, (moo_oop_dic_t)ifce->ns_oop, &ifce->name);
if (ass) if (ass)
{ {
// The interface name already exists. An interface cannot be defined with an existing name /* The interface name already exists. An interface cannot be defined with an existing name */
moo_setsynerr (moo, MOO_SYNERR_CLASSDUPL, &ifce->fqn_loc, &ifce->name); /* TODO: change the error code to MOO_SYNERR_IFCEDUPL? */ moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEDUPL, &ifce->fqn_loc, &ifce->name, "duplicate interface name");
return -1; return -1;
} }
/* an interface doesn't inherit anything */
ifce->super_oop = moo->_nil;
if (TOKEN_TYPE(moo) != MOO_IOTOK_LBRACE) if (TOKEN_TYPE(moo) != MOO_IOTOK_LBRACE)
{ {
@ -8220,55 +8265,6 @@ static int __compile_interface_definition (moo_t* moo)
return -1; return -1;
} }
#if 0
MOO_ASSERT (moo, ifce->super_oop != MOO_NULL);
if (ifce->super_oop != moo->_nil)
{
/* adjust the instance variable count and the class instance variable
* count to include that of a superclass */
moo_oop_class_t c;
moo_oow_t spec, self_spec;
c = (moo_oop_class_t)ifce->super_oop;
spec = MOO_OOP_TO_SMOOI(c->spec);
self_spec = MOO_OOP_TO_SMOOI(c->selfspec);
/* [NOTE] class variables are not inherited.
* so no data about them are not transferred over */
if ((ifce->flags & CLASS_INDEXED) && ifce->indexed_type != MOO_OBJ_TYPE_OOP)
{
/* the class defined is a non-pointer object. */
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 */
moo_setsynerrbfmt (moo, MOO_SYNERR_INHERITBANNED, &ifce->fqn_loc, &ifce->fqn,
"the non-pointer class %.*js cannot inherit from a pointer class defined with instance variables",
ifce->fqn.len, ifce->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 (ifce->non_pointer_instsize < MOO_CLASS_SPEC_NAMED_INSTVARS(spec))
{
moo_setsynerrbfmt (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 ",
ifce->non_pointer_instsize, ifce->fqn.len, ifce->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, ifce->non_pointer_instsize == 0); /* no such thing as class(#pointer(N)). so it must be 0 */
ifce->var[VAR_INSTANCE].total_count = MOO_CLASS_SPEC_NAMED_INSTVARS(spec);
}
ifce->var[VAR_CLASSINST].total_count = MOO_CLASS_SELFSPEC_CLASSINSTVARS(self_spec);
}
GET_TOKEN (moo); GET_TOKEN (moo);
/* an interface cannot have variables */ /* an interface cannot have variables */
@ -8289,7 +8285,7 @@ static int __compile_interface_definition (moo_t* moo)
{ {
/* method definition in class definition */ /* method definition in class definition */
GET_TOKEN (moo); GET_TOKEN (moo);
if (compile_method_definition(moo) <= -1) return -1; if (compile_method_signature(moo) <= -1) return -1;
} }
else break; else break;
} }
@ -8300,7 +8296,7 @@ static int __compile_interface_definition (moo_t* moo)
moo_setsynerr (moo, MOO_SYNERR_RBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerr (moo, MOO_SYNERR_RBRACE, TOKEN_LOC(moo), TOKEN_NAME(moo));
return -1; return -1;
} }
#endif
GET_TOKEN (moo); GET_TOKEN (moo);
return 0; return 0;
@ -8463,6 +8459,15 @@ static int __compile_pooldic_definition (moo_t* moo)
goto oops; goto oops;
} }
#if 0
if (TOKEN_TYPE(moo) == MOO_IOTOK_IDENT && is_restricted_word(TOKEN_NAME(moo)))
{
/* wrong pooldic name */
moo_setsynerr (moo, MOO_SYNERR_NAMEINVAL, TOKEN_LOC(moo), TOKEN_NAME(moo), "invalid pooldic name");
return -1;
}
#endif
/* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested /* [NOTE] TOKEN_NAME(moo) doesn't contain the full name if it's nested
* inside a class. it is merely a name that appeared in the source * inside a class. it is merely a name that appeared in the source
* code. * code.
@ -8492,7 +8497,7 @@ static int __compile_pooldic_definition (moo_t* moo)
if (moo_lookupdic(moo, (moo_oop_dic_t)pd->ns_oop, &pd->name)) if (moo_lookupdic(moo, (moo_oop_dic_t)pd->ns_oop, &pd->name))
{ {
/* a conflicting entry has been found */ /* a conflicting entry has been found */
moo_setsynerr (moo, MOO_SYNERR_POOLDICDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo)); moo_setsynerrbfmt (moo, MOO_SYNERR_NAMEDUPL, TOKEN_LOC(moo), TOKEN_NAME(moo), "duplicate pooldic name");
goto oops; goto oops;
} }
@ -8844,21 +8849,12 @@ static void gc_cunit_chain (moo_t* moo)
if (ifce->self_oop) if (ifce->self_oop)
ifce->self_oop = (moo_oop_class_t)moo_moveoop(moo, (moo_oop_t)ifce->self_oop); ifce->self_oop = (moo_oop_class_t)moo_moveoop(moo, (moo_oop_t)ifce->self_oop);
if (ifce->super_oop)
ifce->super_oop = moo_moveoop(moo, ifce->super_oop);
if (ifce->ns_oop) if (ifce->ns_oop)
{ {
register moo_oop_t x = moo_moveoop(moo, (moo_oop_t)ifce->ns_oop); register moo_oop_t x = moo_moveoop(moo, (moo_oop_t)ifce->ns_oop);
ifce->ns_oop = (moo_oop_nsdic_t)x; ifce->ns_oop = (moo_oop_nsdic_t)x;
} }
if (ifce->superns_oop)
{
register moo_oop_t x = moo_moveoop(moo, (moo_oop_t)ifce->superns_oop);
ifce->superns_oop = (moo_oop_nsdic_t)x;
}
break; break;
} }
} }
@ -8977,8 +8973,6 @@ static void pop_cunit (moo_t* moo)
ifce = (moo_cunit_interface_t*)cunit; ifce = (moo_cunit_interface_t*)cunit;
if (ifce->fqn.ptr) moo_freemem (moo, ifce->fqn.ptr); if (ifce->fqn.ptr) moo_freemem (moo, ifce->fqn.ptr);
if (ifce->superfqn.ptr) moo_freemem (moo, ifce->superfqn.ptr);
break; break;
} }

View File

@ -105,10 +105,10 @@ static moo_ooch_t synerrstr_25[] = {'i','d','e','n','t','i','f','i','e','r',' ',
static moo_ooch_t synerrstr_26[] = {'i','n','t','e','g','e','r',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_26[] = {'i','n','t','e','g','e','r',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_27[] = {'p','r','i','m','i','t','i','v','e',':',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_27[] = {'p','r','i','m','i','t','i','v','e',':',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_28[] = {'w','r','o','n','g',' ','d','i','r','e','c','t','i','v','e','\0'}; static moo_ooch_t synerrstr_28[] = {'w','r','o','n','g',' ','d','i','r','e','c','t','i','v','e','\0'};
static moo_ooch_t synerrstr_29[] = {'u','n','d','e','f','i','n','e','d',' ','c','l','a','s','s','\0'}; static moo_ooch_t synerrstr_29[] = {'w','r','o','n','g',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_30[] = {'d','u','p','l','i','c','a','t','e',' ','c','l','a','s','s','\0'}; static moo_ooch_t synerrstr_30[] = {'d','u','p','l','i','c','a','t','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_31[] = {'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_31[] = {'u','n','d','e','f','i','n','e','d',' ','c','l','a','s','s','\0'};
static moo_ooch_t synerrstr_32[] = {'w','r','o','n','g',' ','c','l','a','s','s',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_32[] = {'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_33[] = {'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_33[] = {'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_34[] = {'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_34[] = {'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_35[] = {'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[] = {'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'};
@ -140,17 +140,16 @@ static moo_ooch_t synerrstr_60[] = {'t','o','o',' ','l','a','r','g','e',' ','a',
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',' ','n','u','m','b','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',' ','n','u','m','b','e','r','\0'};
static moo_ooch_t synerrstr_62[] = {'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_62[] = {'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_63[] = {'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_63[] = {'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_64[] = {'w','r','o','n','g',' ','m','o','d','u','l','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_64[] = {'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_65[] = {'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_65[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'};
static moo_ooch_t synerrstr_66[] = {'#','i','n','c','l','u','d','e',' ','e','r','r','o','r','\0'}; static moo_ooch_t synerrstr_66[] = {'w','r','o','n','g',' ','p','r','a','g','m','a',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_67[] = {'w','r','o','n','g',' ','p','r','a','g','m','a',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_67[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_68[] = {'w','r','o','n','g',' ','n','a','m','e','s','p','a','c','e',' ','n','a','m','e','\0'}; static moo_ooch_t synerrstr_68[] = {'w','r','o','n','g',' ','p','o','o','l','d','i','c','i','m','p','o','r','t',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_69[] = {'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_69[] = {'d','u','p','l','i','c','a','t','e',' ','p','o','o','l','d','i','c','i','m','p','o','r','t',' ','n','a','m','e','\0'};
static moo_ooch_t synerrstr_70[] = {'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_70[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_71[] = {'l','i','t','e','r','a','l',' ','e','x','p','e','c','t','e','d','\0'}; static moo_ooch_t synerrstr_71[] = {'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_72[] = {'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_72[] = {'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_73[] = {'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_73[] = {'w','h','i','l','e',' ','e','x','p','e','c','t','e','d','\0'};
static moo_ooch_t synerrstr_74[] = {'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,
@ -162,7 +161,7 @@ static moo_ooch_t* synerrstr[] =
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, synerrstr_73, synerrstr_74 synerrstr_72, synerrstr_73
}; };
#endif #endif
/* END: GENERATED WITH generr.moo */ /* END: GENERATED WITH generr.moo */

View File

@ -132,7 +132,7 @@ static kernel_class_info_t kernel_classes[] =
{ 'I','n','t','e','r','f','a','c','e' }, { 'I','n','t','e','r','f','a','c','e' },
MOO_CLASS_SELFSPEC_FLAG_LIMITED, MOO_CLASS_SELFSPEC_FLAG_LIMITED,
0, 0,
MOO_CLASS_NAMED_INSTVARS, MOO_INTERFACE_NAMED_INSTVARS,
1, 1,
MOO_OBJ_TYPE_OOP, MOO_OBJ_TYPE_OOP,
MOO_OFFSETOF(moo_t, _interface) }, MOO_OFFSETOF(moo_t, _interface) },

View File

@ -642,19 +642,14 @@ struct moo_cunit_interface_t
{ {
MOO_CUNIT_HEADER; MOO_CUNIT_HEADER;
moo_oop_class_t self_oop; moo_oop_interface_t self_oop;
moo_oop_t super_oop; /* this may be nil. so the type is moo_oop_t */
moo_oop_nsdic_t ns_oop; moo_oop_nsdic_t ns_oop;
moo_oocs_t fqn; moo_oocs_t fqn;
moo_oocs_t name; moo_oocs_t name;
moo_oow_t fqn_capa; moo_oow_t fqn_capa;
moo_ioloc_t fqn_loc; moo_ioloc_t fqn_loc;
moo_oop_nsdic_t superns_oop; moo_method_data_t mth;
moo_oocs_t superfqn;
moo_oocs_t supername;
moo_oow_t superfqn_capa;
moo_ioloc_t superfqn_loc;
}; };
struct moo_compiler_t struct moo_compiler_t

View File

@ -518,6 +518,10 @@ struct moo_dic_t
typedef struct moo_nsdic_t moo_nsdic_t; typedef struct moo_nsdic_t moo_nsdic_t;
typedef struct moo_nsdic_t* moo_oop_nsdic_t; typedef struct moo_nsdic_t* moo_oop_nsdic_t;
#define MOO_INTERFACE_NAMED_INSTVARS 4
typedef struct moo_interface_t moo_interface_t;
typedef struct moo_interface_t* moo_oop_interface_t;
#define MOO_CLASS_NAMED_INSTVARS 18 #define MOO_CLASS_NAMED_INSTVARS 18
typedef struct moo_class_t moo_class_t; typedef struct moo_class_t moo_class_t;
typedef struct moo_class_t* moo_oop_class_t; typedef struct moo_class_t* moo_oop_class_t;
@ -541,9 +545,7 @@ struct moo_interface_t
/* [0] - instance methods, MethodDictionary /* [0] - instance methods, MethodDictionary
* [1] - class methods, MethodDictionary */ * [1] - class methods, MethodDictionary */
moo_oop_dic_t mthdic[2]; moo_oop_dic_t mthdic[2];
moo_oop_nsdic_t nsup; /* pointer to the upper namespace */ moo_oop_nsdic_t nsup; /* pointer to the upper namespace */
moo_oop_nsdic_t nsdic; /* dictionary used for namespacing - may be nil when there are no subitems underneath */
}; };
struct moo_class_t struct moo_class_t
@ -1664,10 +1666,10 @@ enum moo_synerrnum_t
MOO_SYNERR_INTEGER, /* integer expected */ MOO_SYNERR_INTEGER, /* integer expected */
MOO_SYNERR_PRIMITIVE, /* primitive: expected */ MOO_SYNERR_PRIMITIVE, /* primitive: expected */
MOO_SYNERR_DIRECTIVEINVAL, /* wrong directive */ MOO_SYNERR_DIRECTIVEINVAL, /* wrong directive */
MOO_SYNERR_NAMEINVAL, /* wrong name */
MOO_SYNERR_NAMEDUPL, /* duplicate name */
MOO_SYNERR_CLASSUNDEF, /* undefined class */ MOO_SYNERR_CLASSUNDEF, /* undefined class */
MOO_SYNERR_CLASSDUPL, /* duplicate class */
MOO_SYNERR_CLASSCONTRA, /* contradictory class */ MOO_SYNERR_CLASSCONTRA, /* contradictory class */
MOO_SYNERR_CLASSNAMEINVAL, /* wrong class name */
MOO_SYNERR_NPINSTSIZEINVAL, /* invalid non-pointer instance size */ MOO_SYNERR_NPINSTSIZEINVAL, /* invalid non-pointer instance size */
MOO_SYNERR_INHERITBANNED, /* prohibited inheritance */ MOO_SYNERR_INHERITBANNED, /* prohibited inheritance */
MOO_SYNERR_VARDCLBANNED, /* variable declaration not allowed */ MOO_SYNERR_VARDCLBANNED, /* variable declaration not allowed */
@ -1699,13 +1701,12 @@ enum moo_synerrnum_t
MOO_SYNERR_PFNUMINVAL, /* wrong primitive function number */ MOO_SYNERR_PFNUMINVAL, /* wrong primitive function number */
MOO_SYNERR_PFIDINVAL, /* wrong primitive function identifier */ MOO_SYNERR_PFIDINVAL, /* wrong primitive function identifier */
MOO_SYNERR_PFARGDEFINVAL, /* wrong primitive function argument definition */ MOO_SYNERR_PFARGDEFINVAL, /* wrong primitive function argument definition */
MOO_SYNERR_MODNAMEINVAL, /* wrong module name */
MOO_SYNERR_MODIMPFAIL, /* failed to import module */ MOO_SYNERR_MODIMPFAIL, /* failed to import module */
MOO_SYNERR_INCLUDE, /* #include error */ MOO_SYNERR_INCLUDE, /* #include error */
MOO_SYNERR_PRAGMAINVAL, /* wrong pragma name */ MOO_SYNERR_PRAGMAINVAL, /* wrong pragma name */
MOO_SYNERR_NAMESPACEINVAL, /* wrong namespace name */ MOO_SYNERR_NAMESPACEINVAL, /* wrong namespace name */
MOO_SYNERR_POOLDICINVAL, /* wrong pool dictionary */ MOO_SYNERR_PDIMPINVAL, /* wrong pooldic import name */
MOO_SYNERR_POOLDICDUPL, /* duplicate pool dictionary */ MOO_SYNERR_PDIMPDUPL, /* duplicate pooldic import name */
MOO_SYNERR_LITERAL, /* literal expected */ MOO_SYNERR_LITERAL, /* literal expected */
MOO_SYNERR_NOTINLOOP, /* break or continue not within a loop */ MOO_SYNERR_NOTINLOOP, /* break or continue not within a loop */
MOO_SYNERR_INBLOCK, /* break or continue within a block */ MOO_SYNERR_INBLOCK, /* break or continue within a block */