relocated gc related primitive functions

This commit is contained in:
hyunghwan.chung 2017-12-09 17:45:10 +00:00
parent 7c5afe2d5b
commit 6a8db215f8
4 changed files with 43 additions and 36 deletions

View File

@ -3082,38 +3082,6 @@ static moo_pfrc_t pf_system_log (moo_t* moo, moo_ooi_t nargs)
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_system_collect_garbage (moo_t* moo, moo_ooi_t nargs)
{
moo_gc (moo);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
static moo_pfrc_t pf_system_pop_collectable (moo_t* moo, moo_ooi_t nargs)
{
if (moo->collectable.first)
{
moo_finalizable_t* first;
first = moo->collectable.first;
/* TODO: if it's already fininalized, delete it from collectable */
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(first->oop));
MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_GCFIN(first->oop) & MOO_GCFIN_FINALIZABLE);
MOO_STACK_SETRET (moo, nargs, first->oop);
MOO_OBJ_SET_FLAGS_GCFIN (first->oop, MOO_OBJ_GET_FLAGS_GCFIN(first->oop) | MOO_GCFIN_FINALIZED);
MOO_DELETE_FROM_LIST (&moo->collectable, first);
moo_freemem (moo, first); /* TODO: move it to the free list instead... */
}
else
{
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ENOENT);
}
return MOO_PF_SUCCESS;
}
static void sprintptr (moo_ooch_t* nbuf, moo_oow_t num, moo_oow_t *lenp)
@ -3277,7 +3245,7 @@ static pf_t pftab[] =
{ "System_calloc", { moo_pf_system_calloc, 1, 1 } },
{ "System_calloc:", { moo_pf_system_calloc, 1, 1 } },
{ "System_collectGarbage", { pf_system_collect_garbage, 0, 0 } },
{ "System_collectGarbage", { moo_pf_system_collect_garbage, 0, 0 } },
{ "System_free", { moo_pf_system_free, 1, 1 } },
{ "System_free:", { moo_pf_system_free, 1, 1 } },
{ "System_getBytes", { moo_pf_system_get_bytes, 5, 5 } },
@ -3292,7 +3260,7 @@ static pf_t pftab[] =
{ "System_log", { pf_system_log, 2, MA } },
{ "System_malloc", { moo_pf_system_malloc, 1, 1 } },
{ "System_malloc:", { moo_pf_system_malloc, 1, 1 } },
{ "System_popCollectable", { pf_system_pop_collectable, 0, 0 } },
{ "System_popCollectable", { moo_pf_system_pop_collectable, 0, 0 } },
{ "System_putBytes", { moo_pf_system_put_bytes, 5, 5 } },
{ "System_putInt8", { moo_pf_system_put_int8, 3, 3 } },
{ "System_putInt16", { moo_pf_system_put_int16, 3, 3 } },

View File

@ -563,7 +563,7 @@ static void print_object (moo_t* moo, moo_oow_t mask, moo_oop_t oop, outbfmt_t o
}
else
{
outbfmt (moo, mask, "instance of %.*js(%p)", MOO_OBJ_GET_SIZE(c->name), ((moo_oop_char_t)c->name)->slot, oop);
outbfmt (moo, mask, "<<%.*js>>", MOO_OBJ_GET_SIZE(c->name), ((moo_oop_char_t)c->name)->slot);
}
}
}

View File

@ -1331,7 +1331,6 @@ moo_pfrc_t moo_pf_system_calloc (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_free (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_smptr_free (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_get_int8 (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_get_int16 (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_get_int32 (moo_t* moo, moo_ooi_t nargs);
@ -1379,6 +1378,9 @@ moo_pfrc_t moo_pf_smptr_put_uint64 (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_smptr_get_bytes (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_collect_garbage (moo_t* moo, moo_ooi_t nargs);
moo_pfrc_t moo_pf_system_pop_collectable (moo_t* moo, moo_ooi_t nargs);
/* TODO: remove the following debugging functions */
/* ========================================================================= */
/* debug.c */

View File

@ -967,3 +967,40 @@ moo_pfrc_t moo_pf_smptr_put_bytes (moo_t* moo, moo_ooi_t nargs)
MOO_STACK_SETRET (moo, nargs, MOO_SMOOI_TO_OOP(len_in_buffer));
return MOO_PF_SUCCESS;
}
/* ------------------------------------------------------------------------------------- */
moo_pfrc_t moo_pf_system_collect_garbage (moo_t* moo, moo_ooi_t nargs)
{
moo_gc (moo);
MOO_STACK_SETRETTORCV (moo, nargs);
return MOO_PF_SUCCESS;
}
moo_pfrc_t moo_pf_system_pop_collectable (moo_t* moo, moo_ooi_t nargs)
{
if (moo->collectable.first)
{
moo_finalizable_t* first;
first = moo->collectable.first;
/* TODO: if it's already fininalized, delete it from collectable */
MOO_ASSERT (moo, MOO_OOP_IS_POINTER(first->oop));
MOO_ASSERT (moo, MOO_OBJ_GET_FLAGS_GCFIN(first->oop) & MOO_GCFIN_FINALIZABLE);
MOO_STACK_SETRET (moo, nargs, first->oop);
MOO_OBJ_SET_FLAGS_GCFIN (first->oop, MOO_OBJ_GET_FLAGS_GCFIN(first->oop) | MOO_GCFIN_FINALIZED);
MOO_DELETE_FROM_LIST (&moo->collectable, first);
moo_freemem (moo, first); /* TODO: move it to the free list instead... */
}
else
{
/*MOO_STACK_SETRET (moo, nargs, moo->_nil);*/
MOO_STACK_SETRETTOERROR (moo, nargs, MOO_ENOENT);
}
return MOO_PF_SUCCESS;
}