From 6d70ad19ddd68343a6a1178cdaffab712c0a99d0 Mon Sep 17 00:00:00 2001 From: Ted Blackman Date: Tue, 15 Jan 2019 20:03:24 -0800 Subject: [PATCH] WIP simplified conditionals, still dies, appears stateful? --- noun/retrieve.c | 73 +++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 39 deletions(-) diff --git a/noun/retrieve.c b/noun/retrieve.c index 33cd75225..5565aaf10 100644 --- a/noun/retrieve.c +++ b/noun/retrieve.c @@ -1694,58 +1694,53 @@ u3r_mug(u3_noun veb) c3_w a; c3_w b; u3a_noun* veb_u; + u3_noun hed, tal; while ( don != fam ) { a = fam->a; b = fam->b; veb = fam->veb; veb_u = u3a_to_ptr(veb); + //u3m_p("veb", veb); + c3_assert(_(u3a_is_cell(veb))); + // already mugged; pop stack + // + if ( veb_u->mug_w ) { + //fprintf(stderr, "already mugged\r\n"); + mug_w = veb_u->mug_w; + fam = _mug_pop(mov, off, mug_w); + } + // neither head nor tail are mugged; start with head + // + else if ( 0 == a ) { + hed = u3h(veb); + if ( _(u3a_is_atom(hed)) ) { + fam->a = _mug_atom(hed); + } + else { + fam = _mug_push(mov, off, hed); + } + } + // head is mugged, but not tail; mug tail or push tail onto stack + // + else if ( 0 == b ) { + tal = u3t(veb); + if ( _(u3a_is_atom(tal)) ) { + fam->b = _mug_atom(tal); + } + else { + fam = _mug_push(mov, off, tal); + } + } // both head and tail are mugged; combine them and pop stack // - if ( (0 != a) && (0 != b) ) { - fprintf(stderr, "combining head and tail mugs\r\n"); + else { + //fprintf(stderr, "combining head and tail mugs\r\n"); mug_w = u3r_mug_both(a, b); veb_u->mug_w = mug_w; fam = _mug_pop(mov, off, mug_w); } - // head is mugged, but not tail; push tail onto stack - // - else if ( (0 != a) && (0 == b) ) { - if ( _(u3a_is_atom(u3t(veb))) ) { - fprintf(stderr, "tail is atom\r\n"); - mug_w = _mug_atom(u3t(veb)); - fam->b = mug_w; - } - else { - fprintf(stderr, "pushing tail\r\n"); - fam = _mug_push(mov, off, u3t(veb)); - } - } - // cell, and neither head nor tail is mugged; push head onto stack - // - else { - fprintf(stderr, "asserting cell\r\n"); - c3_assert(_(u3a_is_cell(veb))); - // already mugged; pop stack - // - if ( veb_u->mug_w ) { - fprintf(stderr, "already mugged\r\n"); - mug_w = veb_u->mug_w; - fam = _mug_pop(mov, off, mug_w); - } - else { - if ( _(u3a_is_atom(u3h(veb))) ) { - fprintf(stderr, "head is atom\r\n"); - mug_w = _mug_atom(u3h(veb)); - fam->a = mug_w; - } - else { - fprintf(stderr, "pushing head\r\n"); - fam = _mug_push(mov, off, u3h(veb)); - } - } - } } u3R->cap_p = empty; return mug_w;