コード例 #1
0
ファイル: Builtins.cs プロジェクト: pmurias/niecza
    public static VarDeque HashIterRaw(int mode, Variable v)
    {
        IP6 o = NominalCheck("$x", Kernel.AnyMO, v);
        VarHash d = Kernel.UnboxAny<VarHash>(o);

        VarDeque lv = new VarDeque();

        foreach (KeyValuePair<string,Variable> kv in d) {
            switch (mode) {
                case 0:
                    lv.Push(Kernel.BoxAnyMO<string>(kv.Key, Kernel.StrMO));
                    break;
                case 1:
                    lv.Push(kv.Value);
                    break;
                case 2:
                    lv.Push(Kernel.BoxAnyMO<string>(kv.Key, Kernel.StrMO));
                    lv.Push(kv.Value);
                    break;
                case 3:
                    DynObject p = new DynObject(Kernel.PairMO);
                    p.slots[0] = Kernel.BoxAnyMO<string>(kv.Key, Kernel.StrMO);
                    p.slots[1] = kv.Value;
                    lv.Push(Kernel.NewROScalar(p));
                    break;
            }
        }
        return lv;
    }
コード例 #2
0
    Variable GetFromArray()
    {
        SkipCharWS('[');
        VarDeque kids = new VarDeque();
        P6opaque obj  = new P6opaque(Kernel.ArrayMO);

        obj.SetSlot("items", kids);
        obj.SetSlot("rest", new VarDeque());
        bool   comma = false;
        string a_tag = null;

        if (SkipWhite(true) == '"')
        {
            GetString();
            comma = true;
        }

        if (comma)
        {
            if (s_content_type == NONE)
            {
                a_tag = s_tag;
                if (s_anchor != null)
                {
                    AddAnchor(s_anchor, obj);
                }
            }
            else
            {
                kids.Push(GetFromString());
            }
        }

        while (true)
        {
            if (SkipWhite(true) == ']')
            {
                break;
            }
            if (comma)
            {
                SkipChar(',');
            }
            kids.Push(GetObj());
            comma = true;
        }
        SkipCharWS(']');
        if (a_tag != null)
        {
            Err("Typed arrays are NYI in Niecza Perl 6");
        }
        return(Kernel.NewRWScalar(Kernel.AnyMO, obj));
    }
コード例 #3
0
ファイル: CompilerBinding.cs プロジェクト: renesugar/niecza
    public static Variable cb_downcall(Variable list)
    {
        List <object> lo = new List <object>();
        VarDeque      it = Builtins.start_iter(list);

        while (Kernel.IterHasFlat(it, true))
        {
            lo.Add(Downcaller.DCArg(it.Shift()));
        }

        return(Downcaller.DCResult(list.Fetch().mo.setting, Downcaller.RawDowncall(lo.ToArray())));
    }
コード例 #4
0
ファイル: JSYNC.cs プロジェクト: renesugar/niecza
    internal void WriteObj(P6any obj)
    {
        bool comma = false;
        bool def   = obj.IsDefined();

        if (def && obj.Isa(setting.HashMO))
        {
            VarHash vh = Kernel.UnboxAny <VarHash>(obj);
            o.Append('{');
            foreach (KeyValuePair <string, Variable> kv in vh)
            {
                if (comma)
                {
                    o.Append(',');
                }
                comma = true;
                o.Append('"');
                JsyncWriter.AddStringContents(o, kv.Key);
                o.Append('"');
                o.Append(':');
                WriteVal(kv.Value.Fetch());
            }
            o.Append('}');
        }
        else if (def && obj.Isa(setting.ListMO))
        {
            VarDeque iter = obj.mo.mro_raw_iterator.Get(obj);
            o.Append('[');
            while (Kernel.IterHasFlat(iter, true))
            {
                if (comma)
                {
                    o.Append(',');
                }
                comma = true;
                WriteVal(iter.Shift().Fetch());
            }
            o.Append(']');
        }
        else if (JsyncWriter.FailSoft)
        {
            o.Append("\"*UNSERIALIZABLE*\"");
        }
        else
        {
            throw new NieczaException("JSON writer encountered value of type " +
                                      obj.mo.name);
        }
    }
コード例 #5
0
ファイル: JSYNC.cs プロジェクト: renesugar/niecza
    void WriteArray(P6any obj)
    {
        int a = nextanchor++;

        anchors[obj] = a;
        VarDeque iter = obj.mo.mro_raw_iterator.Get(obj);

        o.AppendFormat("[\"&A{0}\"", a);
        contUsed = true;
        while (Kernel.IterHasFlat(iter, true))
        {
            o.Append(',');
            WriteObj(iter.Shift().Fetch());
        }
        o.Append(']');
    }
コード例 #6
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    public static Variable cursor_allcaps(Variable cv)
    {
        Cursor c = (Cursor) cv.Fetch();
        VarDeque dq = new VarDeque();

        for (CapInfo it = c.captures; it != null; it = it.prev) {
            if (it.names[0] == null || it.cap == null)
                continue; // special node
            if (!it.cap.Fetch().Isa(Kernel.MatchMO))
                continue;
            foreach (string name in it.names)
                dq.Unshift(pair(MakeStr(name), it.cap));
        }

        P6opaque lst = new P6opaque(Kernel.ListMO);
        lst.slots[0 /*items*/] = dq;
        lst.slots[1 /*rest*/ ] = new VarDeque();
        return Kernel.NewRWListVar(lst);
    }
コード例 #7
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    public void UnpackCaps(P6any into)
    {
        List<VarDeque> posr = new List<VarDeque>();
        Dictionary<string,VarDeque> namr = new Dictionary<string,VarDeque>();
        CapInfo it = captures;

        for (; it != null; it = it.prev) {
            if (it.names[0] == null)
                continue; // special node
            foreach (string name in it.names) {
                int nami;
                VarDeque t;
                if (int.TryParse(name, out nami) && nami >= 0) {
                    while(posr.Count <= nami) posr.Add(new VarDeque());
                    t = posr[nami];
                } else {
                    if (!namr.TryGetValue(name, out t))
                        namr[name] = t = new VarDeque();
                }
                t.Unshift(it.cap);
            }
        }

        VarHash nam = new VarHash();
        Variable[] pos = new Variable[posr.Count];

        foreach (KeyValuePair<string, VarDeque> kv in namr)
            nam[kv.Key] = FixupList(kv.Value);
        for (int i = 0; i < pos.Length; i++)
            pos[i] = FixupList(posr[i]);

        into.SetSlot(Kernel.CaptureMO, "$!positionals", pos);
        into.SetSlot(Kernel.CaptureMO, "$!named", nam);
    }
コード例 #8
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 // 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();
 }
コード例 #9
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
    // TODO: cache generated lists
    public Variable GetKey(string str)
    {
        CapInfo it = captures;
        VarDeque caps = new VarDeque();

        for (; it != null; it = it.prev) {
            if (it.names[0] == null)
                continue; // special node
            foreach (string cn in it.names) {
                if (cn == str) {
                    caps.Unshift(it.cap);
                    break;
                }
            }
        }

        return FixupList(caps);
    }
コード例 #10
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 public static Variable array_constructor(Variable bits)
 {
     VarDeque rest  = start_iter(bits);
     VarDeque items = new VarDeque();
     while (Kernel.IterHasFlat(rest, true))
         items.Push(Kernel.NewMuScalar(rest.Shift().Fetch()));
     P6any l = new P6opaque(Kernel.ArrayMO);
     l.SetSlot("rest", rest);
     l.SetSlot("items", items);
     return Kernel.NewROScalar(l);
 }
コード例 #11
0
ファイル: Cursor.cs プロジェクト: pmurias/niecza
    // TODO: cache generated lists
    public Variable GetKey(string str)
    {
        CapInfo it = captures;
        VarDeque caps = new VarDeque();

        while (it != null) {
            foreach (string cn in it.names) {
                if (cn == str) {
                    caps.Unshift(it.cap);
                    break;
                }
            }
            it = it.prev;
        }

        return FixupList(caps);
    }
コード例 #12
0
ファイル: Builtins.cs プロジェクト: nbrown/niecza
 public static P6any MakeList(VarDeque items, VarDeque rest)
 {
     P6any l = new P6opaque(Kernel.ListMO);
     l.SetSlot(Kernel.ListMO, "$!rest", rest);
     l.SetSlot(Kernel.ListMO, "$!items", items);
     return l;
 }
コード例 #13
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 public override bool TryGet(out Variable[] r, bool block)
 {
     r = null;
     if (state == 0) {
         // Make sure all the lists are non-empty.
         for (int i = 0; i < iter.Length; i++) {
             switch (TryOne(iter[i], block)) {
                 case -1: return true;
                 case 0:  return false;
                 case 1:  break;
             }
         }
         for (int i = 0; i < iter.Length; i++) {
             iter_top[i] = iter[i].Shift();
             if (i != 0) {
                 basic[i] = new VarDeque(iter[i]);
                 basic_top[i] = iter_top[i];
             }
         }
     }
     else if (state == 1) {
         return true;
     }
     else {
     again:
         int wheel = state - 2;
         switch (TryOne(iter[wheel], block)) {
             case 0:  return false;
             case +1:
                 iter_top[wheel] = iter[wheel].Shift();
                 break;
             case -1:
                 if (wheel == 0) return true;
                 iter[wheel] = new VarDeque(basic[wheel]);
                 iter_top[wheel] = basic_top[wheel];
                 state--;
                 goto again;
         }
     }
     r = new Variable[iter_top.Length];
     for (int i = 0; i < iter_top.Length; i++)
         r[i] = iter_top[i];
     state = iter_top.Length + 1;
     return true;
 }
コード例 #14
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 public static Variable MakeJunction(int type, Variable[] elems)
 {
     if (type >= 8) {
         type -= 8;
         foreach (Variable e in elems)
             if (e.islist) goto need_flatten;
         goto flat_enough;
     need_flatten:;
         VarDeque iter = new VarDeque(elems);
         VarDeque into = new VarDeque();
         while (Kernel.IterHasFlat(iter, true))
             into.Push(iter.Shift());
         elems = into.CopyAsArray();
     flat_enough:;
     }
     P6opaque nj = new P6opaque(Kernel.JunctionMO);
     nj.slots[0] = Kernel.BoxRaw(type, Kernel.IntMO);
     nj.slots[1] = Kernel.BoxRaw(elems, Kernel.ParcelMO);
     return Kernel.NewROScalar(nj);
 }
コード例 #15
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
    public static Frame MEMap(Frame th, Variable[] lst)
    {
        VarDeque iter = new VarDeque(lst);
        Variable fcn = iter.Shift();
        P6any fcni = fcn.Fetch();
        int arity = get_count(fcni);

        Frame fr = th.MakeChild(null, Kernel.CommonMEMap_I, Kernel.AnyP);
        fr.lexi0 = 0;
        fr.lex0 = new BatchSource(arity, iter);
        fr.lex1 = new VarDeque();
        fr.lex2 = fcni;
        return fr;
    }
コード例 #16
0
ファイル: Cursor.cs プロジェクト: Util/niecza
    // TODO: cache generated lists
    public Variable GetKey(string str)
    {
        CapInfo it = captures;
        VarDeque caps = new VarDeque();

        while (it != null) {
            foreach (string cn in it.names) {
                if (cn == str) {
                    caps.Unshift(it.cap);
                    break;
                }
            }
            it = it.prev;
        }

        if (str == "0" && caps.Count() == 0)
            caps.Unshift(Kernel.NewROScalar(this));

        return FixupList(caps);
    }
コード例 #17
0
ファイル: Cursor.cs プロジェクト: Util/niecza
 // 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;
 }
コード例 #18
0
ファイル: Cursor.cs プロジェクト: Util/niecza
    public Variable O(VarHash caps)
    {
        Cursor nw = At(pos);
        foreach (KeyValuePair<string,Variable> kv in caps)
            nw.captures = new CapInfo(nw.captures, new string[] { kv.Key },
                    Kernel.NewMuScalar(kv.Value.Fetch()));
        VarDeque ks = new VarDeque();

        P6opaque lst = new P6opaque(Kernel.ListMO);
        lst.slots[0 /*items*/] = ks;
        lst.slots[1 /*rest*/ ] = new VarDeque();

        ks.Push(Kernel.NewROScalar(nw));
        return Kernel.NewRWListVar(lst);
    }
コード例 #19
0
ファイル: Builtins.cs プロジェクト: nbrown/niecza
 public static Variable BoxLoS(string[] los)
 {
     VarDeque items = new VarDeque();
     foreach (string i in los)
         items.Push(Kernel.BoxAnyMO(i, Kernel.StrMO));
     return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
 }
コード例 #20
0
ファイル: Builtins.cs プロジェクト: nbrown/niecza
 public static Variable sig_params(P6any sig)
 {
     VarDeque items = new VarDeque();
     foreach (Parameter p in ((Signature)sig).parms)
         items.Push(Kernel.NewROScalar(p));
     return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
 }
コード例 #21
0
ファイル: Cursor.cs プロジェクト: nbrown/niecza
 private Variable FixupList(VarDeque caps)
 {
     if (caps.Count() != 0 && caps[0] == null) {
         caps.Shift();
         P6opaque l = new P6opaque(Kernel.ListMO);
         l.slots[0 /*items*/] = caps;
         l.slots[1 /*rest*/ ] = new VarDeque();
         return Kernel.NewROScalar(l);
     } else {
         return caps.Count() != 0 ? caps[0] : Kernel.AnyMO.typeVar;
     }
 }
コード例 #22
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
    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");
        }
    }
コード例 #23
0
ファイル: JSYNC.cs プロジェクト: renesugar/niecza
    internal Variable GetFromJson(bool top_level)
    {
        char look = SkipWhite(true);

        if (look == '[')
        {
            VarDeque q = new VarDeque();
            SkipChar('[');
            while (true)
            {
                look = SkipWhite(true);
                if (look == ']')
                {
                    break;
                }
                if (q.Count() != 0)
                {
                    SkipChar(',');
                }
                q.Push(GetFromJson(false));
            }
            SkipWhite(true);
            SkipChar(']');
            return(setting.MakeArray(q, new VarDeque()));
        }
        else if (look == '{')
        {
            VarHash q  = new VarHash();
            int     ct = 0;
            SkipChar('{');
            while (true)
            {
                look = SkipWhite(true);
                if (look == '}')
                {
                    break;
                }
                if (ct != 0)
                {
                    SkipCharWS(',');
                }
                ct++;
                string key = GetJsonString();
                SkipWhite(true);
                SkipChar(':');
                q[key] = GetFromJson(false);
            }
            SkipWhite(true);
            SkipChar('}');
            return(BoxRW <VarHash>(q, setting.HashMO));
        }
        else if (top_level)
        {
            Err("Top-level scalar found");
            return(null);
        }
        else if (look == '"')
        {
            return(BoxRW <string>(GetJsonString(), setting.StrMO));
        }
        else if (look == 'n')
        {
            SkipToken("null");
            return(Kernel.NewMuScalar(setting.AnyP));
        }
        else if (look == 't')
        {
            SkipToken("true");
            return(Kernel.NewMuScalar(setting.TrueV.Fetch()));
        }
        else if (look == 'f')
        {
            SkipToken("false");
            return(Kernel.NewMuScalar(setting.FalseV.Fetch()));
        }
        else
        {
            double d;
            string tx = GetJsonNumber();
            if (!Utils.S2NB(tx, out d))
            {
                Err("Unparsable number " + tx);
            }
            return(BoxRW <double>(d, setting.NumMO));
        }
    }
コード例 #24
0
ファイル: Cursor.cs プロジェクト: Util/niecza
    public Variable SimpleWS()
    {
        string backing = global.orig_s;
        char[] backing_ca = global.orig_a;
        int l = backing_ca.Length;
        int p = pos;

        VarDeque ks = new VarDeque();

        P6opaque lst = new P6opaque(Kernel.ListMO);
        lst.slots[0 /*items*/] = ks;
        lst.slots[1 /*rest*/ ] = new VarDeque();

        if (p != 0 && p != l && CC.Word.Accepts(backing[p]) &&
                CC.Word.Accepts(backing[p-1])) {
            if (Trace)
                Console.WriteLine("! no match <ws> at {0}", pos);
        } else {
            while (p != l && Char.IsWhiteSpace(backing, p)) { p++; }
            if (Trace)
                Console.WriteLine("* match <ws> at {0} to {1}", pos, p);
            ks.Push(Kernel.NewROScalar(At(p)));
        }

        return Kernel.NewRWListVar(lst);
    }
コード例 #25
0
        public object ObjRef()
        {
            var tag = (SerializationCode)Byte();

            if (Config.SerTrace)
            {
                Console.WriteLine("Reading {0} from {1}...", tag, rpointer - 1);
            }
            int i, j;

            switch (tag)
            {
            case SerializationCode.Null:
                return(null);

            case SerializationCode.ForeignRef:
                i = Int();
                j = Int();
                return(unit_map[i].bynum[j]);

            case SerializationCode.SelfRef:
                i = Int();
                return(unit.bynum[i]);

            case SerializationCode.NewUnitRef:
                return(LoadNewUnit());

            case SerializationCode.RuntimeUnit:
                return(RuntimeUnit.Thaw(this));

            case SerializationCode.SubInfo:
                return(SubInfo.Thaw(this));

            case SerializationCode.STable:
                return(STable.Thaw(this));

            case SerializationCode.StashEnt:
                return(StashEnt.Thaw(this));

            case SerializationCode.Rat:
                return(Rat.Thaw(this));

            case SerializationCode.FatRat:
                return(FatRat.Thaw(this));

            case SerializationCode.Complex:
                return(Complex.Thaw(this));

            case SerializationCode.BigInteger:
                return(BigInteger.Thaw(this));

            case SerializationCode.VarDeque:
                return(VarDeque.Thaw(this));

            case SerializationCode.VarHash:
                return(VarHash.Thaw(this));

            case SerializationCode.DispatchEnt:
                return(DispatchEnt.Thaw(this));

            //case SerializationCode.RxFrame:
            //    return RxFrame.Thaw(this);
            case SerializationCode.P6how:
                return(P6how.Thaw(this));

            case SerializationCode.CC:
                return(CC.Thaw(this));

            case SerializationCode.AltInfo:
                return(AltInfo.Thaw(this));

            case SerializationCode.Signature:
                return(Signature.Thaw(this));

            case SerializationCode.Parameter:
                return(Parameter.Thaw(this));

            case SerializationCode.ReflectObj:
                return(ReflectObj.Thaw(this));

            case SerializationCode.P6opaque:
                return(P6opaque.Thaw(this));

            case SerializationCode.Frame:
                return(Frame.Thaw(this));

            //Cursor,

            case SerializationCode.String:
                return(Register(String()));

            case SerializationCode.ArrP6any:
                return(RefsARegister <P6any>());

            case SerializationCode.ArrVariable:
                return(RefsARegister <Variable>());

            case SerializationCode.ArrString:
                return(RefsARegister <string>());

            case SerializationCode.ArrCC:
                return(RefsARegister <CC>());

            case SerializationCode.Boolean:
                return(Register(Byte() != 0));

            case SerializationCode.Int:
                return(Register(Int()));

            case SerializationCode.Double:
                return(Register(Double()));

            case SerializationCode.Type:
                return(Register(Type.GetType(String(), true)));

            case SerializationCode.SimpleVariable:
            case SerializationCode.SimpleVariable_1:
            case SerializationCode.SimpleVariable_2:
            case SerializationCode.SimpleVariable_3:
                return(SimpleVariable.Thaw(this,
                                           (int)tag - (int)SerializationCode.SimpleVariable));

            case SerializationCode.SubstrLValue:
                return(SubstrLValue.Thaw(this));

            case SerializationCode.TiedVariable:
                return(TiedVariable.Thaw(this));

            case SerializationCode.SubViviHook:
                return(SubViviHook.Thaw(this));

            case SerializationCode.ArrayViviHook:
                return(ArrayViviHook.Thaw(this));

            case SerializationCode.NewArrayViviHook:
                return(NewArrayViviHook.Thaw(this));

            case SerializationCode.HashViviHook:
                return(HashViviHook.Thaw(this));

            case SerializationCode.NewHashViviHook:
                return(NewHashViviHook.Thaw(this));

            case SerializationCode.LADNone:
                return(Register(new LADNone()));

            case SerializationCode.LADNull:
                return(Register(new LADNull()));

            case SerializationCode.LADDot:
                return(Register(new LADDot()));

            case SerializationCode.LADDispatcher:
                return(Register(new LADDispatcher()));

            case SerializationCode.LADImp:
                return(Register(new LADImp()));

            case SerializationCode.LADStr:
                return(LADStr.Thaw(this));

            case SerializationCode.LADStrNoCase:
                return(LADStrNoCase.Thaw(this));

            case SerializationCode.LADMethod:
                return(LADMethod.Thaw(this));

            case SerializationCode.LADParam:
                return(LADParam.Thaw(this));

            case SerializationCode.LADQuant:
                return(LADQuant.Thaw(this));

            case SerializationCode.LADSequence:
                return(LADSequence.Thaw(this));

            case SerializationCode.LADAny:
                return(LADAny.Thaw(this));

            case SerializationCode.LADCC:
                return(LADCC.Thaw(this));

            default:
                throw new ThawException("unexpected object tag " + tag);
            }
        }
コード例 #26
0
ファイル: Builtins.cs プロジェクト: o-fun/niecza
    public static VarDeque HashIterRaw(int mode, Variable v)
    {
        P6any o = NominalCheck("$x", v);
        VarHash d = Kernel.UnboxAny<VarHash>(o);
        var s = o.mo.setting;

        VarDeque lv = new VarDeque();

        foreach (KeyValuePair<string,Variable> kv in d) {
            switch (mode) {
                case 0:
                    lv.Push(s.MakeStr(kv.Key));
                    break;
                case 1:
                    lv.Push(kv.Value);
                    break;
                case 2:
                    lv.Push(s.MakeStr(kv.Key));
                    lv.Push(kv.Value);
                    break;
                case 3:
                    P6opaque p = new P6opaque(s.PairMO);
                    p.slots[0] = s.MakeStr(kv.Key);
                    p.slots[1] = kv.Value;
                    lv.Push(p);
                    break;
            }
        }
        return lv;
    }
コード例 #27
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
    public static Frame MEGrep(Frame th, Variable[] lst)
    {
        VarDeque iter = new VarDeque(lst);
        Variable fcn = iter.Shift();
        iter = Kernel.IterFlatten(iter);

        Frame fr = th.MakeChild(null, Kernel.CommonGrep_I, Kernel.AnyP);
        fr.lexi0 = 0;
        fr.lex0 = iter;
        fr.lex1 = new VarDeque();
        fr.lex2 = fcn;
        return fr;
    }
コード例 #28
0
ファイル: Builtins.cs プロジェクト: o-fun/niecza
 public static Variable param_value_constraints(P6any param)
 {
     var p = param as Parameter;
     VarDeque items = new VarDeque();
     if (p.post_constraints != null) {
         foreach (object o in p.post_constraints) {
             if (o is Variable)
                 items.Push((Variable)o);
         }
     }
     return Kernel.NewRWListVar(param.mo.setting.MakeList(items, new VarDeque()));
 }
コード例 #29
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
    public static Frame MEMap_for_each(Frame th, P6any lst,
            Func<Variable,Variable> fcn)
    {
        VarDeque iter = new VarDeque(Kernel.NewRWListVar(lst));

        Frame fr = th.MakeChild(null, Kernel.CommonMEMap_I, Kernel.AnyP);
        fr.lexi0 = 0;
        fr.lex0 = new BatchSource(1, iter);
        fr.lex1 = new VarDeque();
        fr.lex2 = fcn;
        return fr;
    }
コード例 #30
0
ファイル: Builtins.cs プロジェクト: o-fun/niecza
 public static Variable sig_params(Constants c, P6any sig)
 {
     VarDeque items = new VarDeque();
     items.PushN(((Signature)sig).parms);
     return Kernel.NewRWListVar(c.setting.MakeList(items, new VarDeque()));
 }
コード例 #31
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 public BatchSource(int count, VarDeque items)
 {
     this.arity = count;
     this.items = items;
 }
コード例 #32
0
ファイル: Builtins.cs プロジェクト: o-fun/niecza
 public static Variable array_constructor(Constants c, Variable bits)
 {
     VarDeque rest  = start_iter(bits);
     VarDeque items = new VarDeque();
     while (Kernel.IterHasFlat(rest, true))
         items.Push(Kernel.NewMuScalar(rest.Shift().Fetch()));
     return c.setting.MakeArray(items, rest);
 }
コード例 #33
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 protected static int TryOne(VarDeque items, bool block)
 {
     if (block) {
         return Kernel.IterHasFlat(items, true) ? +1 : -1;
     } else {
     again:
         if (items.Count() == 0) return -1;
         Variable v = items[0];
         P6any i = v.Fetch();
         if (i.mo.HasMRO(Kernel.IterCursorMO))
             return 0;
         if (v.islist) {
             items.Shift();
             items.UnshiftD(i.mo.mro_raw_iterator.Get(v));
             goto again;
         }
         return +1;
     }
 }
コード例 #34
0
ファイル: Builtins.cs プロジェクト: o-fun/niecza
 public static Variable code_candidates(P6any sub)
 {
     // Not foolproof
     SubInfo si = Kernel.GetInfo(sub);
     VarDeque items = new VarDeque();
     if (si.param != null && si.param[0] is P6any[]) {
         foreach (P6any cand in (P6any[])si.param[0])
             if (cand != null)
                 items.Push(cand);
     } else {
         items.Push(sub);
     }
     return Kernel.NewRWListVar(si.setting.MakeList(items, new VarDeque()));
 }
コード例 #35
0
ファイル: Builtins.cs プロジェクト: ebassi/niecza
 public static Variable BoxLoS(string[] los)
 {
     VarDeque items = new VarDeque();
     foreach (string i in los)
         items.Push(Kernel.BoxAnyMO(i, Kernel.StrMO));
     P6any l = new P6opaque(Kernel.ListMO);
     l.SetSlot("rest", new VarDeque());
     l.SetSlot("items", items);
     return Kernel.NewRWListVar(l);
 }
コード例 #36
0
 private Variable FixupList(VarDeque caps) {
     if (caps.Count() != 0 && caps[0] == null) {
         caps.Shift();
         P6opaque l = new P6opaque(global.setting.ListMO);
         l.slots[0 /*items*/] = caps;
         l.slots[1 /*rest*/ ] = new VarDeque();
         return l;
     } else {
         return caps.Count() != 0 ? caps[0] : global.setting.AnyP;
     }
 }