Beispiel #1
0
        public PrototypeDictionary AsDictionary()
        {
            var dict = new PrototypeDictionary();

            MergeInto(dict);
            return(dict);
        }
Beispiel #2
0
        public static PrototypeDictionary ConvertToLispDictionary(IDictionary obj, bool caseInsensitive)
        {
            var dict = new PrototypeDictionary(caseInsensitive);

            foreach (DictionaryEntry item in obj)
            {
                dict[item.Key] = item.Value;
            }
            return(dict);
        }
Beispiel #3
0
        public static Prototype FromDictionary(PrototypeDictionary dict)
        {
            var proto = new Prototype();

            if (dict != null)
            {
                proto.Dict = dict;
            }
            return(proto);
        }
Beispiel #4
0
 public static void DumpDictionary(object stream, PrototypeDictionary dict)
 {
     if (dict != null)
     {
         foreach (var key in ToIter(SeqBase.Sort(dict.Keys, CompareApply, IdentityApply)))
         {
             object val  = dict[key];
             string line = string.Format("{0} => ", key);
             Write(line, Symbols.Escape, false, Symbols.Stream, stream);
             PrettyPrintLine(stream, line.Length, null, val);
         }
     }
 }
Beispiel #5
0
        public static Prototype Merge(params Prototype[] prototypes)
        {
            var dict = new PrototypeDictionary();

            foreach (var p in prototypes)
            {
                if (p != null)
                {
                    p.MergeInto(dict);
                }
            }
            return(FromDictionary(dict));
        }
Beispiel #6
0
        //[Lisp( "get-dynamic-variables-dictionary" )]
        public static Prototype GetDynamicVariablesDictionary(int pos)
        {
            var env = new PrototypeDictionary();

            for (var entry = GetSpecialVariablesAt(pos); entry != null; entry = entry.Link)
            {
                var key = entry.Sym.DiagnosticsName;
                if (!env.ContainsKey(key))
                {
                    env[key] = entry.Value;
                }
            }

            return(Prototype.FromDictionary(env));
        }
Beispiel #7
0
        public void MergeInto(PrototypeDictionary dict)
        {
            foreach (var item in Dict)
            {
                if (!dict.ContainsKey(item.Key))
                {
                    dict[item.Key] = item.Value;
                }
            }

            foreach (var parent in Parents)
            {
                parent.MergeInto(dict);
            }
        }
Beispiel #8
0
        //[Lisp( "get-lexical-variables-dictionary" )]
        public static Prototype GetLexicalVariablesDictionary(int pos)
        {
            Frame frame = GetFrameAt(pos);

            if (frame == null)
            {
                return(null);
            }

            var env = new PrototypeDictionary();

            for (; frame != null; frame = frame.Link)
            {
                if (frame.Names != null)
                {
                    for (var i = 0; i < frame.Names.Count; ++i)
                    {
                        var    key   = frame.Names[i].DiagnosticsName;
                        object value = null;
                        if (frame.Values != null && i < frame.Values.Count)
                        {
                            value = frame.Values[i];
                        }
                        if (key == Symbols.Tilde.Name)
                        {
                            if (frame == CurrentThreadContext.Frame)
                            {
                                env[key] = value;
                            }
                            else if (!env.ContainsKey(key))
                            {
                                env[key] = value;
                            }
                        }
                        else if (!env.ContainsKey(key))
                        {
                            env[key] = value;
                        }
                    }
                }
            }

            return(Prototype.FromDictionary(env));
        }
Beispiel #9
0
        public static PrototypeDictionary ConvertToDictionary(Type type, object obj, bool showNonPublic)
        {
            var flags = BindingFlags.Public | (obj == null ? BindingFlags.Static : BindingFlags.Instance) | BindingFlags.FlattenHierarchy;

            if (showNonPublic)
            {
                flags |= BindingFlags.NonPublic;
            }
            var members = type.GetMembers(flags);
            var dict    = new PrototypeDictionary();

            foreach (var m in members)
            {
                var    name  = m.Name;
                object value = null;

                try
                {
                    if (m is PropertyInfo)
                    {
                        var p = (PropertyInfo)m;
                        if (p.GetGetMethod() != null && p.GetGetMethod().GetParameters().Length == 0)
                        {
                            value = p.GetValue(obj, new object[0]);
                            dict[name.LispName()] = value;
                        }
                    }
                    else if (m is FieldInfo)
                    {
                        var f = (FieldInfo)m;
                        value = f.GetValue(obj);
                        dict[name.LispName()] = value;
                    }
                }
                catch
                {
                }
            }

            return(dict);
        }
Beispiel #10
0
        public PrototypeDictionary GetDictionary()
        {
            var dict = new PrototypeDictionary();

            for (var f = this; f != null; f = f.Link)
            {
                if (f.Names != null)
                {
                    for (var i = 0; i < f.Names.Count; ++i)
                    {
                        var n = f.Names[i];
                        var v = f.Values[i];

                        if (!n.IsReservedName && !dict.ContainsKey(n))
                        {
                            dict[n] = v;
                        }
                    }
                }
            }
            return(dict);
        }
Beispiel #11
0
        //[Lisp( "get-global-variables-dictionary" )]
        public static Prototype GetGlobalVariablesDictionary(string pattern)
        {
            var env = new PrototypeDictionary();
            var pat = (pattern ?? "").ToLower();

            foreach (var package in Packages.Values)
            {
                if (package.Name != "")
                {
                    foreach (Symbol sym in package.Dict.Values)
                    {
                        var name = sym.DiagnosticsName;

                        if (!sym.IsUndefined && (pattern == null || name.ToLower().IndexOf(pat) != -1))
                        {
                            env[name] = sym.Value;
                        }
                    }
                }
            }

            return(Prototype.FromDictionary(env));
        }