Exemple #1
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);
            }
        }
Exemple #2
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);
            }
        }
Exemple #3
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);
            }
        }