scmno****@osdn*****
scmno****@osdn*****
Tue Jun 19 06:36:17 JST 2018
changeset 06a738bc166f in quipu/quipu details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=06a738bc166f user: Agustina Arzille <avarz****@riseu*****> date: Mon Jun 18 18:36:06 2018 -0300 description: Start reworking continuations (partial) diffstat: compiler.cpp | 7 +++++-- continuation.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ continuation.h | 1 + interp.cpp | 32 ++++++++++++-------------------- interp.h | 3 ++- memory.cpp | 13 +++++-------- memory.h | 6 +++--- quipu.cpp | 11 +++++++++-- symbol.cpp | 6 +----- 9 files changed, 78 insertions(+), 41 deletions(-) diffs (263 lines): diff -r 5cf600fc7c5e -r 06a738bc166f compiler.cpp --- a/compiler.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/compiler.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -2413,7 +2413,7 @@ as_int (stack[interp->cur_frame - 3]) - 1]; r_stkend(1) = retval; - lastf = (fn & EXTRA_BIT) ? as_int (fn) : interp->cur_frame; + lastf = interp->cur_frame - ((fn & EXTRA_BIT) ? intobj (fn) : 0); nargs = as_int (stack[lastf - 3]); bp = lastf - (interpreter::frame_size + nargs); fn = stack[bp - 1]; @@ -2734,7 +2734,10 @@ OP_(MKFRAMEL): sx = !bcode_long_p (*(ip - 1)) ? (int8_t)*ip++ : (int32_t)fetch32 (ip); - *interp->stkend++ = intobj (lastf) | EXTRA_BIT; + *interp->stkend = intobj (interp->stkdiff () + sx + 1 + + interpreter::frame_size - lastf) | EXTRA_BIT; + ++interp->stkend; + for (int32_t si = 0; si < sx; ++si) *interp->stkend++ = UNBOUND; diff -r 5cf600fc7c5e -r 06a738bc166f continuation.cpp --- a/continuation.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/continuation.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -33,6 +33,46 @@ return (ap->as_obj ()); } +static object +mark_argv (interpreter *interp, uint32_t ilastf, int *xfp) +{ + uint32_t start = ilastf - as_int (interp->stack[ilastf - 3]) - + interpreter::frame_size - 1; + uint32_t nf = 0, sp = interp->stkdiff (); + + ilastf = as_int (interp->stack[ilastf - 4]); + + for (uint32_t cf = interp->cur_frame; cf > ilastf; + cf = as_int (interp->stack[cf - 4]), ++nf) ; + + array *ap = as_array (alloc_array (interp, sp - start)); + copy_objs (ap->data, interp->stack + start, sp - start); + + QP_TMARK (interp); + uint32_t *offp = (uint32_t *)QP_TALLOC (interp, (nf + 1) * sizeof (*offp)); + offp[nf] = 0; + + for (uint32_t cf = interp->cur_frame; cf > ilastf; --nf) + { + uint32_t prev = as_int (interp->stack[cf - 4]); + offp[nf - 1] = cf - prev; + cf = prev; + } + + start = 0; + + do + { + ap->data[*offp++] = start; + start += *offp; + } + while (!*offp); + + *xfp = (int)start; + return (ap->as_obj ()); +} + + void continuation::push (interpreter *interp) { array *ap = as_array (this->argv); diff -r 5cf600fc7c5e -r 06a738bc166f continuation.h --- a/continuation.h Mon Jun 18 14:24:10 2018 -0300 +++ b/continuation.h Mon Jun 18 18:36:06 2018 -0300 @@ -19,6 +19,7 @@ int ip_offset; int nframes; int sp_diff; + int xframe; }; inline bool continuation_p (object __obj) diff -r 5cf600fc7c5e -r 06a738bc166f interp.cpp --- a/interp.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/interp.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -47,11 +47,13 @@ void interpreter::init () { - this->nstack = 64; - this->stack = this->stkend = - (object *)xmalloc (this->nstack * sizeof (object)); - for (uint32_t i = 0; i < this->nstack; ++i) - this->stack[i] = UNBOUND; + // Initialization order is important for bootstrapping. + this->values.init_head (); + this->hooks.init_head (); + this->mmgr = memmgr_alloc (); + + this->stkobj = alloc_array (this, 64, UNBOUND); + this->stack = this->stkend = &xaref(this->stkobj, 0); this->cur_frame = this->throw_frame = 0; this->ilock = 0; @@ -73,10 +75,6 @@ this->npendev = 0; this->evh_active = true; - this->values.init_head (); - this->hooks.init_head (); - this->mmgr = memmgr_alloc (); - for (size_t i = 0; i < QP_NELEM (this->num_hooks); ++i) this->num_hooks[i] = 0; } @@ -93,21 +91,15 @@ { evh_guard eg (this); uint32_t sp = this->stkdiff (), size = sp + n; - if (qp_likely (size < this->nstack)) + if (qp_likely (size < (uint32_t)as_array(this->stkobj)->len)) return; - object *nsp = (object *)xmalloc (sizeof (*nsp) * (size = upsize (size))); - memcpy (nsp, this->stack, sp * sizeof (*nsp)); + object ns = alloc_array (this, size = upsize (size), UNBOUND); + memcpy (&xaref(ns, 0), this->stack, sp * sizeof (object)); - for (uint32_t off = this->nstack; off < size; ++off) - nsp[off] = UNBOUND; - - object *prev = this->stack; - this->stack = nsp; - this->stkend = nsp + sp; - this->nstack = size; + this->stack = &xaref(ns, 0); + this->stkend = this->stack + sp; this->call_hooks (HOOK_TYPE_STKMOV); - xfree (prev); } object* interpreter::push (object obj) diff -r 5cf600fc7c5e -r 06a738bc166f interp.h --- a/interp.h Mon Jun 18 14:24:10 2018 -0300 +++ b/interp.h Mon Jun 18 18:36:06 2018 -0300 @@ -3,6 +3,7 @@ #include "defs.h" #include "event.h" +#include "initop.h" QP_DECLS_BEGIN @@ -94,12 +95,12 @@ public: object *stack; object *stkend; - uint32_t nstack; uint32_t cur_frame; uint32_t throw_frame; intptr_t ilock; object thread; object lasterr; + object stkobj; // Interpreter registers. object retval; object alval; diff -r 5cf600fc7c5e -r 06a738bc166f memory.cpp --- a/memory.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/memory.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -1036,6 +1036,11 @@ } } +bool memory_init () +{ + return (QP_gc.init ()); +} + void memory_exit () { interpreter *interp = interpreter::self (); @@ -1051,13 +1056,5 @@ call_finalizers (&QP_gc.white.sets[FINOBJ_IDX]); } -static int -do_init_memory (interpreter *) -{ - return (QP_gc.init () ? init_op::result_ok : init_op::result_failed); -} - -init_op init_memory (do_init_memory, "memory"); - QP_DECLS_END diff -r 5cf600fc7c5e -r 06a738bc166f memory.h --- a/memory.h Mon Jun 18 14:24:10 2018 -0300 +++ b/memory.h Mon Jun 18 18:36:06 2018 -0300 @@ -52,12 +52,12 @@ // Perform a garbage collection. Collect all generations if FULL is true. QP_EXPORT void gc (bool __full); +// Initialize the memory subsystem. +QP_EXPORT bool memory_init (); + // Call finalizers before exiting. QP_EXPORT void memory_exit (); -// Init OP for the memory subsystem. -QP_EXPORT init_op init_memory; - QP_DECLS_END #endif diff -r 5cf600fc7c5e -r 06a738bc166f quipu.cpp --- a/quipu.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/quipu.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -12,9 +12,16 @@ bool quipu_init (void) { static interpreter ip_main; - ip_main.init (); + main_interp = &ip_main; - main_interp = &ip_main; + if (!memory_init ()) + { + fputs ("Failed to initialize memory subsystem", stderr); + return (false); + } + + main_interp->init (); + atexit (memory_exit); return (init_op_list::get().call (main_interp)); } diff -r 5cf600fc7c5e -r 06a738bc166f symbol.cpp --- a/symbol.cpp Mon Jun 18 14:24:10 2018 -0300 +++ b/symbol.cpp Mon Jun 18 18:36:06 2018 -0300 @@ -369,10 +369,6 @@ static int do_init_symbols (interpreter *interp) { - int ret = init_op::call_deps (interp, &init_memory); - if (ret != init_op::result_ok) - return (ret); - root_package = alloc_pkg (interp, string::make (interp, "*user*")); kword_package = alloc_pkg (interp, string::make (interp, "*keyword*")); local_package = alloc_pkg (interp, string::make (interp, "*local*")); @@ -392,7 +388,7 @@ symval(QP_S(t)) = QP_S(t); #undef INTERN - return (ret); + return (init_op::result_ok); } QP_EXPORT init_op init_memory;