Beispiel #1
0
        private static string InspectLinkedList(LinkedList <object> list, InspectOptions options = InspectOptions.Default, bool encloseList = true)
        {
            var sb = new StringBuilder( );

            if (encloseList)
            {
                sb.Append("(");
            }

            var curent  = list.First;
            var consLen = 0;

            while (curent != null && ++consLen < MAX_CONS_PRINT_LEN)
            {
                sb.Append(ObjectToString(curent.Value, options));

                curent = curent.Next;
                if (curent != null)
                {
                    sb.Append(" ");
                }
            }

            if (curent != null)
            {
                sb.Append(" ... ");
            }

            if (encloseList)
            {
                sb.Append(")");
            }

            return(sb.ToString( ));
        }
Beispiel #2
0
 private static string InspectInternal(SObject x, InspectOptions options = InspectOptions.Default)
 {
     if (x is Location)
     {
         return(InspectInternal(x as Location, options));
     }
     if (x is Token)
     {
         return(InspectInternal(x as Token, options));
     }
     if (x is ValuePair)
     {
         return(InspectInternal(x as ValuePair, options));
     }
     if (x is Syntax)
     {
         return(InspectInternal(x as Syntax, options));
     }
     if (x is AST)
     {
         return(InspectInternal(x as AST, options));
     }
     if (x is AstBinding)
     {
         return(InspectInternal(x as AstBinding, options));
     }
     if (x is Environment)
     {
         return(InspectInternal(x as Environment, options));
     }
     // all another just convert to string
     return(x.ToString());
 }
Beispiel #3
0
 internal ObjectGuide(IStructure structure, InspectOptions options)
 {
     Struct  = structure;
     Address = Mem.Nullptr;
     Value   = null;
     Options = options;
 }
Beispiel #4
0
        private static string InspectInternal(Syntax x, InspectOptions options = InspectOptions.Default)
        {
            var loc = x.Location;

            if (options == InspectOptions.Default)
            {
                if (loc == null)
                {
                    return(string.Format("#<syntax {0}>", Inspect(x.GetDatum(), options)));
                }
                else
                {
                    return(string.Format("#<syntax:{0}:{1} {2}>", loc.LineNumber, loc.ColNumber, Inspect(x.GetDatum(), options)));
                }
            }
            else
            {
                if (loc == null)
                {
                    return(string.Format("#<syntax {0}>", Inspect(x.GetExpression(), options)));
                }
                else
                {
                    return(string.Format("#<syntax:{0}:{1} {2}>", loc.LineNumber, loc.ColNumber, Inspect(x.GetExpression(), options)));
                }
            }
        }
Beispiel #5
0
        public static ObjectInfo Scan <T>(ref T value, InspectOptions options)
        {
            var info = Scan(value.GetType(), options);

            info.Update(ref value);

            return(info);
        }
Beispiel #6
0
        public static ObjectInfo Scan(Type t, InspectOptions options)
        {
            var info = new ObjectInfo(t, options);

            info.Update();

            return(info);
        }
Beispiel #7
0
        // --Inspect Mono Classes ------------------------------------------------------------------------

        private static string InspectMonoObject(object x, InspectOptions options = InspectOptions.Default)
        {
            // -- Simple objects will be just printed as it is
            if (x is float)
            {
                return(((float)x).ToString("0.0###################"));
            }

            if (x is bool)
            {
                return(((bool)x) ? "#t" : "#f");
            }

            if (x is string)
            {
                return(string.Format("\"{0}\"", x));
            }

            if (x is char)
            {
                return(NamedCharacter.CharacterToName((char)x));
            }

            if (x is Inspectable)
            {
                return((x as Inspectable).Inspect(options));
            }

            if (x is LinkedList <object> )
            {
                return(InspectLinkedList(x as LinkedList <object>));
            }

            if (x is List <object> )
            {
                return(InspectList(x as List <object>));
            }

            if (x is Dictionary <object, object> )
            {
                return(InspectDictionary(x as Dictionary <object, object>));
            }

            if (x is Array)
            {
                return(InspectArray((Array)x, options));
            }

            if (Type.GetTypeCode(x.GetType( )) == TypeCode.Object)
            {
                return(string.Format("#<{0}>", x.ToString( ).Trim( )));
            }

            return(x.ToString( ).Trim( ));
        }
Beispiel #8
0
        // -- Fields -----------------------------------------------------------------------------

        public string Inspect(InspectOptions options = InspectOptions.PrettyPrint)
        {
            if (options == InspectOptions.PrettyPrint)
            {
                return(SpecialForm.ToSpecialFormString(this));
            }
            else
            {
                return(ToString( ));
            }
        }
Beispiel #9
0
 public string Inspect(InspectOptions options = InspectOptions.Default)
 {
     if (options == InspectOptions.PrettyPrint)
     {
         return(InspectPrettyPrint( ));
     }
     else
     {
         return(InspectDefault( ));
     }
 }
Beispiel #10
0
 private static string InspectInternal(Value x, InspectOptions options = InspectOptions.Default)
 {
     if (x.IsVoid)
     {
         return(string.Empty);
     }
     if (x.IsNil || x.IsValueType)
     {
         return(x.ToString());
     }
     return(Inspect(x.RefVal, options));
 }
Beispiel #11
0
        private static string InspectInternal(Token x, InspectOptions options = InspectOptions.Default)
        {
            var loc = x.location;

            if (loc == null)
            {
                return(string.Format("#<token \"{0}\">", x.ToString()));
            }
            else
            {
                return(string.Format("#<token:{0}:{1} \"{2}\">", loc.LineNumber, loc.ColNumber, x.ToString()));
            }
        }
Beispiel #12
0
        private static string InspectInternal(Environment env, InspectOptions options = InspectOptions.Default)
        {
            var tabs   = env.GetEnvironmentIndex();
            var tabstr = new string(' ', tabs * 4);
            var sb     = new StringBuilder();

            sb.AppendLine(tabstr + "Lexical Environment");
            foreach (var b in env)
            {
                sb.AppendLine(tabstr + InspectInternal(b, options));
            }
            return(sb.ToString());
        }
Beispiel #13
0
        public static ObjectInfo Scan <T>(T value, InspectOptions options)
        {
            var info = Scan(value.GetType(), options);

            info.Value = value;

            if (options.HasFlagFast(InspectOptions.MemoryFields))
            {
                info.WithMemoryFields();
            }

            return(info);
        }
Beispiel #14
0
        private static string InspectInternal(LinkedList <Value> list, InspectOptions options = InspectOptions.Default, bool encloseList = true)
        {
            var sb = new StringBuilder();

            if (encloseList)
            {
                sb.Append("(");
            }

            var curent  = list.First;
            var consLen = 0;

            while (curent != null && ++consLen < MAX_CONS_PRINT_LEN)
            {
                var sym = curent.Value.AsSymbol();
                if (sym != null && sym.IsSpecialForm)
                {
                    if (options == InspectOptions.PrettyPrint)
                    {
                        sb.Append(sym.ToSpecialFormString());
                    }
                    else
                    {
                        sb.Append(sym.ToString());
                    }
                }
                else
                {
                    sb.Append(Inspect(curent.Value, options));
                }

                curent = curent.Next;
                if (curent != null)
                {
                    sb.Append(" ");
                }
            }

            if (curent != null)
            {
                sb.Append(" ... ");
            }

            if (encloseList)
            {
                sb.Append(")");
            }

            return(sb.ToString());
        }
Beispiel #15
0
        public static ObjectInfo Scan(Type t, InspectOptions options)
        {
            var info = new ObjectInfo(t, options);

            if (options.HasFlagFast(InspectOptions.Fields))
            {
                info.WithFields();
            }

            if (options.HasFlagFast(InspectOptions.Padding))
            {
                info.WithPaddingFields();
            }

            return(info);
        }
Beispiel #16
0
 private static string InspectInternal(AstBinding bind, InspectOptions options = InspectOptions.Default)
 {
     if (bind is UpBinding)
     {
         var upbind = bind as UpBinding;
         return(string.Format("[{0},{1}] {1}>", upbind.UpEnvIdx, upbind.UpVarIdx, bind.Identifier.Name));
     }
     else if (bind is PrimitiveBinding)
     {
         return(string.Format("#Prim {0}", bind.Identifier.Name));
     }
     else
     {
         return(string.Format(" {0}", bind.Identifier.Name));
     }
 }
Beispiel #17
0
        // -- Convert to string any object  --------------------------------------------------------------

        public static string ObjectToString(object obj, InspectOptions options = InspectOptions.Default)
        {
            if (obj == null)
            {
                return("null");
            }
            switch (options)
            {
            case InspectOptions.Default:
                return(obj.ToString( ));

            case InspectOptions.PrettyPrint:
                return(obj.ToString( ));

            default:
                return(obj.ToString( ));
            }
        }
Beispiel #18
0
        private static string InspectInternal(Dictionary <object, Value> table, InspectOptions options = InspectOptions.Default)
        {
            var sb          = new StringBuilder();
            var appendSpace = false;

            sb.Append("#hash(");
            foreach (var v in table)
            {
                if (appendSpace)
                {
                    sb.Append(" ");
                }
                sb.Append(string.Format("#<pair {0} {1}>", Inspect(v.Key, options), Inspect(v.Value, options)));
                appendSpace |= true;
            }
            sb.Append(")");
            return(sb.ToString());
        }
Beispiel #19
0
        private static string InspectInternal(List <Value> list, InspectOptions options = InspectOptions.Default)
        {
            var sb          = new StringBuilder();
            var appendSpace = false;

            sb.Append("#(");
            foreach (var v in list)
            {
                if (appendSpace)
                {
                    sb.Append(" ");
                }
                sb.Append(Inspect(v, options));
                appendSpace |= true;
            }
            sb.Append(")");
            return(sb.ToString());
        }
Beispiel #20
0
        public string Inspect(InspectOptions options = InspectOptions.Default)
        {
            var sb          = new StringBuilder( );
            var appendSpace = false;

            sb.Append("#(");
            foreach (var v in this)
            {
                if (appendSpace)
                {
                    sb.Append(" ");
                }
                sb.Append(Inspector.InspectObject(v, options));
                appendSpace |= true;
            }
            sb.Append(")");
            return(sb.ToString( ));
        }
Beispiel #21
0
        // --Inspect any object  -------------------------------------------------------------------------

        public static string InspectObject(object x, InspectOptions options = InspectOptions.Default)
        {
            if (x == null)
            {
                return("null");
            }

            if (x is Variant)
            {
                return(((Variant)x).Inspect());
            }

            if (x is SObject)
            {
                return(((SObject)x).ToString( ));
            }

            return(InspectMonoObject(x, options));
        }
Beispiel #22
0
        private static string InspectMonoObject(object x, InspectOptions options = InspectOptions.Default)
        {
            if (x is string)
            {
                return(string.Format(CultureInfo.CurrentCulture, "\"{0}\"", x));
            }

            if (x is char)
            {
                return(string.Format(CultureInfo.CurrentCulture, "#\\{0}", x));
            }

            if (x is LinkedList <Value> )
            {
                return(InspectInternal(x as LinkedList <Value>));
            }

            if (x is List <Value> )
            {
                return(InspectInternal(x as List <Value>));
            }

            if (x is Dictionary <object, Value> )
            {
                return(InspectInternal(x as Dictionary <object, Value>));
            }

            if (x is Array)
            {
                return(InspectArray((Array)x, options));
            }

            if (Type.GetTypeCode(x.GetType()) == TypeCode.Object)
            {
                return(string.Format(CultureInfo.CurrentCulture, "#<{0}>", x.ToString().Trim()));
            }

            return(x.ToString().Trim());
        }
Beispiel #23
0
        public static string Inspect(Object x, InspectOptions options = InspectOptions.Default)
        {
            if (x == null)
            {
                return("null");
            }

            if (x is Value)
            {
                return(InspectInternal((Value)x, options));
            }

            if (x is SObject)
            {
                return(InspectInternal(x as SObject, options));
            }

            if (x is Inspectable)
            {
                return((x as Inspectable).Inspect());
            }

            return(InspectMonoObject(x, options));
        }
Beispiel #24
0
 public string Inspect(InspectOptions options = InspectOptions.Default)
 {
     return(Inspect(0));
 }
Beispiel #25
0
        // ((uThis & uFlag) == uFlag)

        public static bool HasFlagFast(this InspectOptions value, InspectOptions flag)
        {
            return((value & flag) == flag);
        }
Beispiel #26
0
 private static string InspectInternal(Location x, InspectOptions options = InspectOptions.Default)
 {
     return(string.Format("#<location:{0}:{1} {2}>", x.LineNumber, x.ColNumber, x.File));
 }
Beispiel #27
0
        private static string InspectArray(Array arr, InspectOptions options = InspectOptions.Default)
        {
            var sb = new StringBuilder();

            // For large arrays, don't try to print the elements
            if (arr.Length > MAX_ARRAY_PRINT_LEN)
            {
                sb.Append("#<Array[");
                for (var ix = 0; ix < arr.Rank; ++ix)
                {
                    if (ix > 0)
                    {
                        sb.Append(" x ");
                    }
                    sb.Append(arr.GetUpperBound(ix) - arr.GetLowerBound(ix) + 1);
                }
                sb.Append("] ");
            }

            var ind = new int[arr.Rank];
            var lb  = new int[arr.Rank];
            var ub  = new int[arr.Rank];

            if (arr.Length <= MAX_ARRAY_PRINT_LEN)
            {
                sb.Append(String.Format(CultureInfo.CurrentCulture,
                                        arr.Rank > 1 ? "#{0}a" : "#", arr.Rank));
            }

            for (var ix = 0; ix < arr.Rank; ++ix)
            {
                ind[ix] = lb[ix] = arr.GetLowerBound(ix);
                ub[ix]  = arr.GetUpperBound(ix);
                sb.Append("(");
            }

            var printedElts = 0;

            do
            {
                try
                {
                    sb.Append(Inspect(arr.GetValue(ind)));
                    ++printedElts;
                }
                catch (IndexOutOfRangeException)
                {
                    // ignore - we just don't print out 0-length arrays
                }
            }while (IncrementIndex(arr.Rank - 1, ind, lb, ub, sb) &&
                    printedElts < MAX_ARRAY_PRINT_LEN);

            if (arr.Length > MAX_ARRAY_PRINT_LEN)
            {
                sb.Append(" ... ");
                for (var ix = 0; ix < arr.Rank; ++ix)
                {
                    sb.Append(')');
                }
                sb.Append(">");
            }

            return(sb.ToString());
        }
Beispiel #28
0
 private static string InspectInternal(AST x, InspectOptions options = InspectOptions.Default)
 {
     return(x.Inspect());
 }
Beispiel #29
0
 private static string InspectInternal(ValuePair x, InspectOptions options = InspectOptions.Default)
 {
     return(string.Format("({0} . {1})", Inspect(x.Item1, options), Inspect(x.Item2)));
 }