internal static Frame CommonMEMap_C(Frame th) { ItemSource src = (ItemSource) th.lex0; VarDeque outq = (VarDeque) th.lex1; object fnc = th.lex2; int tailmode = th.lexi0; switch (th.ip) { case 0: Variable[] pen; if (!src.TryGet(out pen, tailmode != 0)) { P6opaque thunk = new P6opaque(Kernel.GatherIteratorMO); th.coro_return = th; th.MarkSharedChain(); thunk.slots[0] = Kernel.NewMuScalar(th); thunk.slots[1] = Kernel.NewMuScalar(Kernel.AnyP); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0] = outq; lst.slots[1] = new VarDeque(Kernel.NewROScalar(thunk)); th.caller.resultSlot = Kernel.NewRWListVar(lst); th.lexi0 = 1; return th.Return(); } if (pen == null) { if (tailmode != 0) return Kernel.Take(th, Kernel.NewROScalar(Kernel.EMPTYP)); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0] = outq; lst.slots[1] = new VarDeque(); th.caller.resultSlot = Kernel.NewRWListVar(lst); return th.Return(); } th.lex3 = pen; th.ip = 1; goto case 1; case 1: th.ip = 2; if (fnc is P6any) { return ((P6any)fnc).Invoke(th, (Variable[])th.lex3, null); } else if (fnc == null) { th.resultSlot = MakeParcel((Variable[]) th.lex3); goto case 2; } else { th.resultSlot = ((Func<Variable,Variable>)fnc).Invoke( ((Variable[])th.lex3)[0]); goto case 2; } case 2: if (tailmode != 0) { th.ip = 0; return Kernel.Take(th, (Variable)th.resultSlot); } else { outq.Push((Variable) th.resultSlot); th.ip = 0; goto case 0; } case 3: th.lex0 = src = ItemSource.Empty; th.ip = 0; goto case 0; default: return Kernel.Die(th, "Invalid IP"); } }
// currently just used for protoregex public Frame EndWith(Frame th, Cursor m) { if (st.pos > global.highwater) global.IncHighwater(st.pos); if ((flags & RETURN_ONE) != 0) { return Kernel.Take(th, Kernel.NewROScalar(m)); } else { th.MarkSharedChain(); flags |= RETURN_ONE; VarDeque ks = new VarDeque(); ks.Push(Kernel.NewROScalar(m)); th.coro_return = th; P6opaque it = new P6opaque(Kernel.GatherIteratorMO); it.slots[0 /*frame*/] = Kernel.NewMuScalar(th); it.slots[1 /*reify*/] = Kernel.NewMuScalar(Kernel.AnyP); VarDeque iss = new VarDeque(); iss.Push(Kernel.NewROScalar(it)); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0 /*items*/] = ks; lst.slots[1 /*rest*/ ] = iss; th.caller.resultSlot = Kernel.NewRWListVar(lst); } return th.Return(); }
internal static Frame CommonGrep_C(Frame th) { VarDeque src = (VarDeque) th.lex0; VarDeque outq = (VarDeque) th.lex1; Variable flt = (Variable) th.lex2; int tailmode = th.lexi0; switch (th.ip) { case 0: Variable pen = null; while (pen == null) { if (tailmode != 0) { if (!Kernel.IterHasFlat(src, false)) break; } else { if (src.Count() == 0) break; if (src[0].Fetch().mo.HasMRO(Kernel.IterCursorMO)) { P6opaque thunk = new P6opaque(Kernel.GatherIteratorMO); th.coro_return = th; th.MarkSharedChain(); thunk.slots[0] = Kernel.NewMuScalar(th); thunk.slots[1] = Kernel.NewMuScalar(Kernel.AnyP); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0] = outq; lst.slots[1] = new VarDeque(Kernel.NewROScalar(thunk)); th.caller.resultSlot = Kernel.NewRWListVar(lst); th.lexi0 = 1; return th.Return(); } } pen = src.Shift(); } if (pen == null) { if (tailmode != 0) return Kernel.Take(th, Kernel.NewROScalar(Kernel.EMPTYP)); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0] = outq; lst.slots[1] = new VarDeque(); th.caller.resultSlot = Kernel.NewRWListVar(lst); return th.Return(); } th.lex3 = pen; th.ip = 1; goto case 1; case 1: th.ip = 2; return flt.Fetch().InvokeMethod(th, "ACCEPTS", new Variable[] { flt, (Variable)th.lex3 }, null); case 2: Variable r = (Variable) th.resultSlot; if (!r.Fetch().mo.mro_raw_Bool.Get(r)) { th.ip = 0; goto case 0; } if (tailmode != 0) { th.ip = 0; return Kernel.Take(th, (Variable)th.lex3); } else { outq.Push((Variable) th.lex3); th.ip = 0; goto case 0; } case 3: th.lex0 = src = new VarDeque(); th.ip = 0; goto case 0; default: return Kernel.Die(th, "Invalid IP"); } }
// currently just used for protoregex public Frame EndWith(Frame th, Cursor m) { if (st.pos > global.highwater) global.IncHighwater(st.pos); if (return_one) { return Kernel.Take(th, Kernel.NewROScalar(m)); } else { th.MarkSharedChain(); return_one = true; VarDeque ks = new VarDeque(); ks.Push(Kernel.NewROScalar(m)); th.lex = new Dictionary<string,object>(); th.lex["!return"] = null; P6opaque it = new P6opaque(Kernel.GatherIteratorMO); it.slots[0 /*frame*/] = Kernel.NewMuScalar(th); it.slots[1 /*reify*/] = Kernel.NewMuScalar(Kernel.AnyP); VarDeque iss = new VarDeque(); iss.Push(Kernel.NewROScalar(it)); P6opaque lst = new P6opaque(Kernel.ListMO); lst.slots[0 /*items*/] = ks; lst.slots[1 /*rest*/ ] = iss; th.caller.resultSlot = Kernel.NewRWListVar(lst); } return th.caller; }