added the method signature class internally to support interface implementation

This commit is contained in:
hyunghwan.chung 2018-10-10 04:23:44 +00:00
parent 1a43722da1
commit 653b99545f
5 changed files with 94 additions and 19 deletions

View File

@ -5,10 +5,6 @@
## MAIN
#################################################################
## TODO: use #define to define a class or use #class to define a class.
## use #extend to extend a class
## using #class for both feels confusing.
extend Apex
{

View File

@ -6438,7 +6438,7 @@ static int add_compiled_method (moo_t* moo)
moo_ooi_t preamble_code, preamble_index, preamble_flags;
name = (moo_oop_char_t)moo_makesymbol(moo, cc->mth.name.ptr, cc->mth.name.len);
if (!name) return -1;
if (!name) goto oops;
moo_pushtmp (moo, (moo_oop_t*)&name); tmp_count++;
/* The variadic data part passed to moo_instantiate() is not GC-safe.
@ -8121,11 +8121,60 @@ static int compile_class_definition (moo_t* moo, int class_type)
return n;
}
static int add_method_signature (moo_t* moo)
{
moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
moo_oop_char_t name; /* selector */
moo_oop_methsig_t mth; /* method signature */
moo_oow_t tmp_count = 0;
name = (moo_oop_char_t)moo_makesymbol(moo, ifce->mth.name.ptr, ifce->mth.name.len);
if (!name) goto oops;
moo_pushtmp (moo, (moo_oop_t*)&name); tmp_count++;
mth = (moo_oop_methsig_t)moo_instantiate(moo, moo->_methsig, MOO_NULL, 0);
if (!mth) goto oops;
moo_pushtmp (moo, (moo_oop_t*)&mth); tmp_count++;
mth->owner = ifce->self_oop;
mth->name = name;
/*
ifce->mth.variadic?
ifce->mth.lenient?
ifce->meth.type == DUAL? CLASS? INST?
*/
mth->modifiers = MOO_SMOOI_TO_OOP(0);
mth->tmpr_nargs = MOO_SMOOI_TO_OOP(ifce->mth.tmpr_nargs);
if (ifce->mth.type == MOO_METHOD_DUAL)
{
if (!moo_putatdic(moo, ifce->self_oop->mthdic[0], (moo_oop_t)name, (moo_oop_t)mth)) goto oops;
if (!moo_putatdic(moo, ifce->self_oop->mthdic[1], (moo_oop_t)name, (moo_oop_t)mth))
{
/* 'name' is a symbol created of ifce->mth.name. so use it as a key for deletion */
moo_deletedic (moo, ifce->self_oop->mthdic[0], &ifce->mth.name);
goto oops;
}
}
else
{
MOO_ASSERT (moo, ifce->mth.type < MOO_COUNTOF(ifce->self_oop->mthdic));
if (!moo_putatdic(moo, ifce->self_oop->mthdic[ifce->mth.type], (moo_oop_t)name, (moo_oop_t)mth)) goto oops;
}
moo_poptmps (moo, tmp_count); tmp_count = 0;
return 0;
oops:
moo_poptmps (moo, tmp_count);
return -1;
}
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 */
@ -8141,6 +8190,8 @@ static int __compile_method_signature (moo_t* moo)
return -1;
}
if (add_method_signature(moo) <= -1) return -1;
GET_TOKEN (moo);
return 0;
}
@ -8162,13 +8213,11 @@ static int compile_method_signature (moo_t* moo)
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;
@ -8181,7 +8230,6 @@ static int make_defined_interface (moo_t* moo)
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;
@ -8847,7 +8895,7 @@ static void gc_cunit_chain (moo_t* moo)
ifce = (moo_cunit_interface_t*)cunit;
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_interface_t)moo_moveoop(moo, (moo_oop_t)ifce->self_oop);
if (ifce->ns_oop)
{

View File

@ -200,6 +200,15 @@ static kernel_class_info_t kernel_classes[] =
MOO_OBJ_TYPE_OOP,
MOO_OFFSETOF(moo_t, _dictionary) },
{ 11,
{ 'A','s','s','o','c','i','a','t','i','o','n' },
0,
0,
MOO_ASSOCIATION_NAMED_INSTVARS,
0,
MOO_OBJ_TYPE_OOP,
MOO_OFFSETOF(moo_t, _association) },
{ 9,
{ 'N','a','m','e','s','p','a','c','e' },
MOO_CLASS_SELFSPEC_FLAG_LIMITED,
@ -236,15 +245,16 @@ static kernel_class_info_t kernel_classes[] =
MOO_OBJ_TYPE_OOP,
MOO_OFFSETOF(moo_t, _method) },
{ 11,
{ 'A','s','s','o','c','i','a','t','i','o','n' },
{ 15,
{ 'M','e','t','h','o','d','S','i','g','n','a','t','u','r','e' },
0,
0,
MOO_ASSOCIATION_NAMED_INSTVARS,
0,
MOO_METHSIG_NAMED_INSTVARS,
MOO_CLASS_SPEC_FLAG_INDEXED,
MOO_OBJ_TYPE_OOP,
MOO_OFFSETOF(moo_t, _association) },
MOO_OFFSETOF(moo_t, _methsig) },
{ 13,
{ 'M','e','t','h','o','d','C','o','n','t','e','x','t' },

View File

@ -2443,7 +2443,14 @@ int main (int argc, char* argv[])
if (argc < 2)
{
print_usage:
fprintf (stderr, "Usage: %s filename ...\n", argv[0]);
fprintf (stderr, "Usage: %s [options] filename ...\n", argv[0]);
fprintf (stderr, " --log filename[,logopts]\n");
#if defined(MOO_BUILD_DEBUG)
fprintf (stderr, " --debug dbgopts\n");
#endif
fprintf (stderr, " --memsize number\n");
fprintf (stderr, " --large-pages\n");
return -1;
}

View File

@ -597,6 +597,19 @@ struct moo_association_t
moo_oop_t value;
};
#define MOO_METHSIG_NAMED_INSTVARS 4
typedef struct moo_methsig_t moo_methsig_t;
typedef struct moo_methsig_t* moo_oop_methsig_t;
struct moo_methsig_t
{
MOO_OBJ_HEADER;
moo_oop_interface_t owner; /* Interface */
moo_oop_char_t name; /* Symbol, method name */
moo_oop_t modifiers; /* SmallInteger, modifiers specified */
moo_oop_t tmpr_nargs; /* SmallInteger */
};
#if defined(MOO_USE_METHOD_TRAILER)
# define MOO_METHOD_NAMED_INSTVARS 8
#else
@ -1415,13 +1428,14 @@ struct moo_t
moo_oop_class_t _array; /* Array */
moo_oop_class_t _byte_array; /* ByteArray */
moo_oop_class_t _symbol_table; /* SymbolTable */
moo_oop_class_t _dictionary;
moo_oop_class_t _association; /* Association */
moo_oop_class_t _namespace; /* Namespace */
moo_oop_class_t _pool_dictionary; /* PoolDictionary */
moo_oop_class_t _method_dictionary; /* MethodDictionary */
moo_oop_class_t _method; /* CompiledMethod */
moo_oop_class_t _association; /* Association */
moo_oop_class_t _methsig; /* MethodSignature */
moo_oop_class_t _method_context; /* MethodContext */
moo_oop_class_t _block_context; /* BlockContext */