some compiler works

This commit is contained in:
hyunghwan.chung 2019-10-06 23:25:36 +00:00
parent 7b8b7d70fd
commit c50dba7c89
2 changed files with 156 additions and 63 deletions

View File

@ -7602,6 +7602,46 @@ static moo_ooi_t compute_preamble (moo_t* moo, moo_method_data_t* md)
return MOO_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index, preamble_flags); return MOO_METHOD_MAKE_PREAMBLE(preamble_code, preamble_index, preamble_flags);
} }
static void add_method_info_to_dbgi (moo_t* moo, moo_method_data_t* md)
{
#if 0
moo_oow_t file_offset;
moo_oow_t method_offset;
const moo_ooch_t* file_name;
MOO_ASSERT (moo, moo->dbgi != MOO_NULL);
file_name = md->start_loc.file;
if (!file_name) file_name = &_nul;
if (moo_addfiletodbgi(moo, file_name, &file_offset) <= -1)
{
/* TODO: warning */
file_offset = 0;
}
else if (file_offset > MOO_SMOOI_MAX)
{
/* TODO: warning */
file_offset = 0;
}
mth->dbgi_file_offset = MOO_SMOOI_TO_OOP(file_offset);
/* TODO: preserve source text... */
if (moo_addmethodtodbgi(moo, file_offset, cc->dbgi_class_offset, md->name.ptr, md->start_loc.line, md->code.locptr, md->code.len, MOO_NULL, 0, &method_offset) <= -1)
{
/* TODO: warning. no debug information about this method will be available */
method_offset = 0;
}
else if (method_offset > MOO_SMOOI_MAX)
{
method_offset = 0;
}
mth->dbgi_method_offset = MOO_SMOOI_TO_OOP(method_offset);
#endif
}
static int add_compiled_method_to_class (moo_t* moo) static int add_compiled_method_to_class (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;
@ -7639,7 +7679,8 @@ static int add_compiled_method_to_class (moo_t* moo)
mth->tmpr_count = MOO_SMOOI_TO_OOP(cc->mth.tmpr_count); mth->tmpr_count = MOO_SMOOI_TO_OOP(cc->mth.tmpr_count);
mth->tmpr_nargs = MOO_SMOOI_TO_OOP(cc->mth.tmpr_nargs); mth->tmpr_nargs = MOO_SMOOI_TO_OOP(cc->mth.tmpr_nargs);
if (moo->dbgi) if (moo->dbgi) add_method_info_to_dbgi (moo, &cc->mth);
#if 0
{ {
moo_oow_t file_offset; moo_oow_t file_offset;
moo_oow_t method_offset; moo_oow_t method_offset;
@ -7673,6 +7714,7 @@ static int add_compiled_method_to_class (moo_t* moo)
mth->dbgi_method_offset = MOO_SMOOI_TO_OOP(method_offset); mth->dbgi_method_offset = MOO_SMOOI_TO_OOP(method_offset);
} }
#endif
#if defined(MOO_DEBUG_COMPILER) #if defined(MOO_DEBUG_COMPILER)
moo_decode (moo, mth, &cc->fqn); moo_decode (moo, mth, &cc->fqn);
@ -7705,10 +7747,113 @@ oops:
static int add_compiled_method_to_interface (moo_t* moo) static int add_compiled_method_to_interface (moo_t* moo)
{ {
/* TODO: */ moo_cunit_interface_t* ifce = (moo_cunit_interface_t*)moo->c->cunit;
moo_oop_char_t name; /* selector */
moo_oop_method_t mth; /* method signature */
moo_ooi_t preamble_flags = 0;
moo_oow_t tmp_count = 0;
MOO_ASSERT (moo, moo->c->cunit->cunit_type == MOO_CUNIT_INTERFACE);
name = (moo_oop_char_t)moo_makesymbol(moo, ifce->mth.name.ptr, ifce->mth.name.len);
if (!name) goto oops;
moo_pushvolat (moo, (moo_oop_t*)&name); tmp_count++;
/* The variadic data part passed to moo_instantiate() is not GC-safe.
* let's delay initialization of variadic data a bit. */
mth = (moo_oop_method_t)moo_instantiatewithtrailer(moo, moo->_method, ifce->mth.literals.count, ifce->mth.code.ptr, ifce->mth.code.len);
if (!mth) goto oops;
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->owner, (moo_oop_t)ifce->self_oop);
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->name, (moo_oop_t)name);
preamble_flags |= ifce->mth.variadic; /* MOO_METHOD_PREAMBLE_FLAG_VARIADIC or MOO_METHOD_PREAMBLE_FLAG_LIBERAL */
if (ifce->mth.lenient) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_LENIENT;
if (ifce->mth.type == MOO_METHOD_DUAL) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_DUAL;
mth->preamble = MOO_SMOOI_TO_OOP(MOO_METHOD_MAKE_PREAMBLE(0,0,preamble_flags));
mth->preamble_data[0] = MOO_SMPTR_TO_OOP(0);
mth->preamble_data[1] = MOO_SMPTR_TO_OOP(0);
mth->tmpr_count = MOO_SMOOI_TO_OOP(ifce->mth.tmpr_count);
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[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops;
if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (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[MOO_METHOD_INSTANCE], &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_popvolats (moo, tmp_count); tmp_count = 0;
return 0;
oops:
moo_popvolats (moo, tmp_count);
return -1; return -1;
} }
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_ooi_t preamble_flags = 0;
moo_oow_t tmp_count = 0;
MOO_ASSERT (moo, moo->c->cunit->cunit_type == MOO_CUNIT_INTERFACE);
name = (moo_oop_char_t)moo_makesymbol(moo, ifce->mth.name.ptr, ifce->mth.name.len);
if (!name) goto oops;
moo_pushvolat (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_pushvolat (moo, (moo_oop_t*)&mth); tmp_count++;
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->owner, (moo_oop_t)ifce->self_oop);
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->name, (moo_oop_t)name);
preamble_flags |= ifce->mth.variadic; /* MOO_METHOD_PREAMBLE_FLAG_VARIADIC or MOO_METHOD_PREAMBLE_FLAG_LIBERAL */
if (ifce->mth.lenient) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_LENIENT;
if (ifce->mth.type == MOO_METHOD_DUAL) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_DUAL;
mth->preamble = MOO_SMOOI_TO_OOP(MOO_METHOD_MAKE_PREAMBLE(0,0,preamble_flags));
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[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops;
if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (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[MOO_METHOD_INSTANCE], &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_popvolats (moo, tmp_count); tmp_count = 0;
return 0;
oops:
moo_popvolats (moo, tmp_count);
return -1;
}
static void clear_pooldic_import_data (moo_t* moo, moo_pooldic_import_data_t* pdimp) static void clear_pooldic_import_data (moo_t* moo, moo_pooldic_import_data_t* pdimp)
{ {
if (pdimp->dcl.ptr) moo_freemem (moo, pdimp->dcl.ptr); if (pdimp->dcl.ptr) moo_freemem (moo, pdimp->dcl.ptr);
@ -9483,58 +9628,6 @@ static int compile_class_definition (moo_t* moo, int class_type)
return n; 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_ooi_t preamble_flags = 0;
moo_oow_t tmp_count = 0;
MOO_ASSERT (moo, moo->c->cunit->cunit_type == MOO_CUNIT_INTERFACE);
name = (moo_oop_char_t)moo_makesymbol(moo, ifce->mth.name.ptr, ifce->mth.name.len);
if (!name) goto oops;
moo_pushvolat (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_pushvolat (moo, (moo_oop_t*)&mth); tmp_count++;
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->owner, (moo_oop_t)ifce->self_oop);
MOO_STORE_OOP (moo, (moo_oop_t*)&mth->name, (moo_oop_t)name);
preamble_flags |= ifce->mth.variadic; /* MOO_METHOD_PREAMBLE_FLAG_VARIADIC or MOO_METHOD_PREAMBLE_FLAG_LIBERAL */
if (ifce->mth.lenient) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_LENIENT;
if (ifce->mth.type == MOO_METHOD_DUAL) preamble_flags |= MOO_METHOD_PREAMBLE_FLAG_DUAL;
mth->preamble = MOO_SMOOI_TO_OOP(MOO_METHOD_MAKE_PREAMBLE(0,0,preamble_flags));
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[MOO_METHOD_INSTANCE], (moo_oop_t)name, (moo_oop_t)mth)) goto oops;
if (!moo_putatdic(moo, ifce->self_oop->mthdic[MOO_METHOD_CLASS], (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[MOO_METHOD_INSTANCE], &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_popvolats (moo, tmp_count); tmp_count = 0;
return 0;
oops:
moo_popvolats (moo, tmp_count);
return -1;
}
static int __compile_method_signature (moo_t* moo) static int __compile_method_signature (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;

View File

@ -162,7 +162,7 @@ moo_pfrc_t moo_pf_equal (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs); rcv = MOO_STACK_GETRCV(moo, nargs);
arg = MOO_STACK_GETARG(moo, nargs, 0); arg = MOO_STACK_GETARG(moo, nargs, 0);
n = _equal_objects (moo, rcv, arg); n = _equal_objects(moo, rcv, arg);
if (n <= -1) return MOO_PF_FAILURE; if (n <= -1) return MOO_PF_FAILURE;
MOO_STACK_SETRET (moo, nargs, (n? moo->_true: moo->_false)); MOO_STACK_SETRET (moo, nargs, (n? moo->_true: moo->_false));
@ -177,7 +177,7 @@ moo_pfrc_t moo_pf_not_equal (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
rcv = MOO_STACK_GETRCV(moo, nargs); rcv = MOO_STACK_GETRCV(moo, nargs);
arg = MOO_STACK_GETARG(moo, nargs, 0); arg = MOO_STACK_GETARG(moo, nargs, 0);
n = _equal_objects (moo, rcv, arg); n = _equal_objects(moo, rcv, arg);
if (n <= -1) return MOO_PF_FAILURE; if (n <= -1) return MOO_PF_FAILURE;
MOO_STACK_SETRET (moo, nargs, (n? moo->_false: moo->_true)); MOO_STACK_SETRET (moo, nargs, (n? moo->_false: moo->_true));
@ -213,7 +213,7 @@ moo_pfrc_t moo_pf_basic_new (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (nargs >= 1) if (nargs >= 1)
{ {
szoop = MOO_STACK_GETARG(moo, nargs, 0); szoop = MOO_STACK_GETARG(moo, nargs, 0);
if (moo_inttooow (moo, szoop, &size) <= 0) if (moo_inttooow(moo, szoop, &size) <= 0)
{ {
/* integer out of range or not integer */ /* integer out of range or not integer */
moo_seterrbfmt (moo, MOO_EINVAL, "size out of range or not integer - %O", szoop); moo_seterrbfmt (moo, MOO_EINVAL, "size out of range or not integer - %O", szoop);
@ -274,7 +274,7 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
MOO_ASSERT (moo, nargs == 0); MOO_ASSERT (moo, nargs == 0);
rcv = MOO_STACK_GETRCV (moo, nargs); rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_POINTER(rcv)) if (!MOO_OOP_IS_POINTER(rcv))
{ {
@ -288,7 +288,7 @@ moo_pfrc_t moo_pf_basic_size (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
if (!sz) return MOO_PF_FAILURE; if (!sz) return MOO_PF_FAILURE;
} }
MOO_STACK_SETRET(moo, nargs, sz); MOO_STACK_SETRET (moo, nargs, sz);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
@ -300,7 +300,7 @@ moo_pfrc_t moo_pf_basic_first_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs
MOO_ASSERT (moo, nargs == 0); MOO_ASSERT (moo, nargs == 0);
rcv = MOO_STACK_GETRCV (moo, nargs); rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_POINTER(rcv) || MOO_OBJ_GET_SIZE(rcv) == 0) if (!MOO_OOP_IS_POINTER(rcv) || MOO_OBJ_GET_SIZE(rcv) == 0)
{ {
@ -311,7 +311,7 @@ moo_pfrc_t moo_pf_basic_first_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs
sz = MOO_SMOOI_TO_OOP(0); sz = MOO_SMOOI_TO_OOP(0);
} }
MOO_STACK_SETRET(moo, nargs, sz); MOO_STACK_SETRET (moo, nargs, sz);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }
@ -323,7 +323,7 @@ moo_pfrc_t moo_pf_basic_last_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
MOO_ASSERT (moo, nargs == 0); MOO_ASSERT (moo, nargs == 0);
rcv = MOO_STACK_GETRCV (moo, nargs); rcv = MOO_STACK_GETRCV(moo, nargs);
if (!MOO_OOP_IS_POINTER(rcv)) if (!MOO_OOP_IS_POINTER(rcv))
{ {
@ -346,7 +346,7 @@ moo_pfrc_t moo_pf_basic_last_index (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
} }
} }
MOO_STACK_SETRET(moo, nargs, sz); MOO_STACK_SETRET (moo, nargs, sz);
return MOO_PF_SUCCESS; return MOO_PF_SUCCESS;
} }