Exemplo n.º 1
0
 public void UnshiftD(VarDeque vrs)
 {
     if (vrs == this)
     {
         UnshiftN(vrs.CopyAsArray()); return;
     }
     for (int i = vrs.count - 1; i >= 0; i--)
     {
         Unshift(vrs[i]);
     }
 }
Exemplo n.º 2
0
 public void PushD(VarDeque vrs)
 {
     if (vrs == this)
     {
         PushN(vrs.CopyAsArray()); return;
     }
     for (int i = 0; i < vrs.count; i++)
     {
         Push(vrs[i]);
     }
 }
Exemplo n.º 3
0
        public static Variable DownCall(Variable list)
        {
            List <object> lo = new List <object>();
            VarDeque      it = Builtins.start_iter(list);

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

            return(DCResult(RawDowncall(lo.ToArray())));
        }
Exemplo n.º 4
0
        internal static VarDeque Thaw(ThawBuffer tb)
        {
            VarDeque r = new VarDeque();

            tb.Register(r);
            int c = tb.Int();

            for (int i = 0; i < c; i++)
            {
                r.Push((Variable)tb.ObjRef());
            }
            return(r);
        }
Exemplo n.º 5
0
        internal static object DCArg(Variable v)
        {
            P6any o = v.Fetch();
            var   s = o.mo.setting;

            if (o is BoxObject <object> )
            {
                return(Kernel.UnboxAny <object>(o));
            }
            else if (o.IsDefined())
            {
                if (o.Isa(s.StrMO))
                {
                    return((string)o.mo.mro_raw_Str.Get(v));
                }
                else if (o.Isa(s.BoolMO))
                {
                    return((bool)o.mo.mro_raw_Bool.Get(v));
                }
                else if (o.Isa(s.NumMO))
                {
                    double d = Kernel.UnboxAny <double>(o);
                    if ((d % 1) == 0 && d <= int.MaxValue && d >= int.MinValue)
                    {
                        return((object)(int)d);
                    }
                    return((object)d);
                }
                else if (o.Isa(s.ListMO))
                {
                    VarDeque it = o.mo.mro_raw_iterator.Get(v);
                    var      lo = new List <object>();
                    while (Kernel.IterHasFlat(it, true))
                    {
                        lo.Add(DCArg(it.Shift()));
                    }
                    return(lo.ToArray());
                }
                else
                {
                    return((int)o.mo.mro_raw_Numeric.Get(v));
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        protected Variable Slice(Variable obj, Variable key)
        {
            if (key.Fetch().mo.HasType(Kernel.JunctionMO))
            {
                return(Builtins.AutoThread(key.Fetch(), delegate(Variable v) {
                    return Get(obj, v);
                }));
            }

            VarDeque        iter  = Builtins.start_iter(key);
            List <Variable> items = new List <Variable>();

            while (Kernel.IterHasFlat(iter, true))
            {
                items.Add(Get(obj, iter.Shift()));
            }
            // TODO: 1-element slices should be deparceled.  Requires
            // LISTSTORE improvements though.
            return(Kernel.NewRWListVar(Kernel.BoxRaw <Variable[]>(
                                           items.ToArray(), Kernel.ParcelMO)));
        }
Exemplo n.º 7
0
        internal static object DCArg(Variable v)
        {
            P6any o = v.Fetch();

            if (o is BoxObject <object> )
            {
                return(Kernel.UnboxAny <object>(o));
            }
            else if (o.IsDefined())
            {
                if (o.Isa(Kernel.StrMO))
                {
                    return((string)o.mo.mro_raw_Str.Get(v));
                }
                else if (o.Isa(Kernel.BoolMO))
                {
                    return((bool)o.mo.mro_raw_Bool.Get(v));
                }
                else if (o.Isa(Kernel.ListMO))
                {
                    VarDeque it = o.mo.mro_raw_iterator.Get(v);
                    var      lo = new List <object>();
                    while (Kernel.IterHasFlat(it, true))
                    {
                        lo.Add(DCArg(it.Shift()));
                    }
                    return(lo.ToArray());
                }
                else
                {
                    return((int)o.mo.mro_raw_Numeric.Get(v));
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        internal static void SerializeNam(Variable v, StringBuilder sb,
                                          List <object> refs)
        {
            P6any o = v.Fetch();

            if (o is BoxObject <int> ) /* includes bool */
            {
                sb.Append(Kernel.UnboxAny <int>(o));
            }
            else if (o is BoxObject <double> )
            {
                sb.Append(Utils.N2S(Kernel.UnboxAny <double>(o)));
            }
            else if (o is BoxObject <string> )
            {
                string s = Kernel.UnboxAny <string>(o);
                sb.Append('"');
                foreach (char c in s)
                {
                    if (c >= ' ' && c <= '~' && c != '\\' && c != '"')
                    {
                        sb.Append(c);
                    }
                    else
                    {
                        sb.Append("\\u");
                        sb.AppendFormat("{0:X4}", (int)c);
                    }
                }
                sb.Append('"');
            }
            else if (!o.IsDefined())
            {
                sb.Append("null");
            }
            else if (o.Isa(o.mo.setting.ListMO))
            {
                VarDeque d     = o.mo.mro_raw_iterator.Get(v);
                bool     comma = false;
                sb.Append('[');
                while (Kernel.IterHasFlat(d, true))
                {
                    if (comma)
                    {
                        sb.Append(',');
                    }
                    SerializeNam(d.Shift(), sb, refs);
                    comma = true;
                }
                sb.Append(']');
            }
            else if (o is BoxObject <object> )
            {
                sb.Append('!');
                sb.Append(refs.Count);
                refs.Add(Kernel.UnboxAny <object>(o));
            }
            else
            {
                throw new NieczaException("weird object in sub_finish " + o.mo.name);
            }
        }
Exemplo n.º 9
0
 public VarDeque(VarDeque tp)
 {
     data  = (Variable[])tp.data.Clone();
     head  = tp.head;
     count = tp.count;
 }
Exemplo n.º 10
0
 public void Shift_UnshiftD(VarDeque vrs)
 {
     Shift(); UnshiftD(vrs);
 }