Пример #1
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())));
        }
Пример #2
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);
            }
        }
Пример #3
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)));
        }
Пример #4
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);
            }
        }
Пример #5
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);
            }
        }