Inheritance: AFn, Named, IComparable, ISerializable, IHashEq
Exemple #1
0
        public object GetValue(clojure.lang.Keyword kw)
        {
            object val;

            dict.TryGetValue(kw, out val);
            return(val);
        }
 public MethodImplCache(IPersistentMap protocol, Keyword methodk, IDictionary map)
 {
     _protocol = protocol;
     _methodk = methodk;
     _shift = 0;
     _mask = 0;
     _table = null;
     _map = map;
 }
Exemple #3
0
 public MethodImplCache(IPersistentMap protocol, Keyword methodk, int shift, int mask, Object[] table)
 {
     _protocol = protocol;
     _methodk = methodk;
     _shift = shift;
     _mask = mask;
     _table = table;
     //_lastType = this;
 }
Exemple #4
0
        public static Keyword intern(Symbol sym)
        {
            Keyword k = null;
            WeakReference existingRef = _symKeyMap.Get(sym);
            if (existingRef == null)
            {
                if (sym.meta() != null)
                    sym = (Symbol)sym.withMeta(null);
                k = new Keyword(sym);

                WeakReference wr = new WeakReference(k);
                wr.Target = k;
                existingRef = _symKeyMap.PutIfAbsent(sym, wr);
            }
            if (existingRef == null)
                return k;
            Keyword existingk = (Keyword)existingRef.Target;
            if (existingk != null)
                return existingk;
            // entry died in the interim, do over
            // let's not get confused, remove it.  (else infinite loop).
            _symKeyMap.Remove(sym);
            return intern(sym);
        }
Exemple #5
0
 public bool Remove(clojure.lang.Keyword kw)
 {
     return(dict.Remove(kw));
 }
       // //these are not volatile by design
       // private object _lastType;

       //// core_deftype.clj compatibility
       // public object lastClass
       // {
       //     get { return _lastType; }
       //     set { _lastType = value; }  
       // }
       // private IFn _lastImpl;

       // // core_deftype.clj compatibility 
       // public IFn lastImpl
       // {
       //     get { return _lastImpl; }
       //     set { _lastImpl = value; }
        //}

       #endregion

       #region C-tors

        public MethodImplCache(IPersistentMap protocol, Keyword methodk)
            : this(protocol, methodk, 0, 0, RT.EmptyObjectArray)
        {
        }
Exemple #7
0
            public override object invoke(object reader, object colon, object opts)
            {
                PushbackTextReader r = reader as PushbackTextReader;

                // Read ns symbol
                object osym = read(r, true, null, false, opts);
                Symbol sym  = osym as Symbol;

                if (sym == null || sym.Namespace != null)
                {
                    throw new Exception("Namespaced map must specify a valid namespace: " + osym);
                }
                string ns = sym.Name;

                // Read map
                int nextChar = r.Read();

                while (isWhitespace(nextChar))
                {
                    nextChar = r.Read();
                }
                if ('{' != nextChar)
                {
                    throw new Exception("Namespaced map must specify a map");
                }
                List <object> kvs = ReadDelimitedList('}', r, true, opts);

                if ((kvs.Count & 1) == 1)
                {
                    throw new Exception("Namespaced map literal must contain an even number of forms");
                }

                // Construct output map
                object[] a = new object[kvs.Count];
                // IPersistentMap m = RT.map();
                using (var iterator = kvs.GetEnumerator())
                {
                    for (int i = 0; iterator.MoveNext(); i += 2)
                    {
                        var key = iterator.Current;
                        iterator.MoveNext();
                        var val = iterator.Current;

                        Keyword kw = key as Keyword;
                        if (kw != null)
                        {
                            if (kw.Namespace == null)
                            {
                                key = Keyword.intern(ns, kw.Name);
                            }
                            else if (kw.Namespace.Equals("_"))
                            {
                                key = Keyword.intern(null, kw.Name);
                            }
                        }
                        else
                        {
                            Symbol s = key as Symbol;
                            if (s != null)
                            {
                                if (s.Namespace == null)
                                {
                                    key = Symbol.intern(ns, s.Name);
                                }
                                else if (s.Namespace.Equals("_"))
                                {
                                    key = Symbol.intern(null, s.Name);
                                }
                            }
                        }
                        a[i]     = key;
                        a[i + 1] = val;
                    }
                }
                return(RT.map(a));
            }
Exemple #8
0
 public void Add(clojure.lang.Keyword kw, object obj)
 {
     dict.Add(kw, obj);
 }
Exemple #9
0
        private static Expression GenerateKeywordExpr(Keyword keyword)
        {
            // in the Java version:
            //if (!KEYWORDS.isBound())
            //    return new KeywordExpr(keyword);
            //IPersistentMap keywordsMap = (IPersistentMap)KEYWORDS.get();
            //Object id = RT.get(keywordsMap, keyword);
            //if (id == null)
            //{
            //    KEYWORDS.set(RT.assoc(keywordsMap, keyword, registerConstant(keyword)));
            //}
            //return new KeywordExpr(keyword);

            return Expression.Constant(keyword);
        }
Exemple #10
0
 // not trying to implement clojure interfaces yet, this is all internal stuff
 public bool ContainsKey(clojure.lang.Keyword kw)
 {
     return(dict.ContainsKey(kw));
 }
Exemple #11
0
 static bool GetLocation(IPersistentMap spanMap, Keyword key, out int val)
 {
     object oval = spanMap.valAt(key);
     if (oval != null && oval is int)
     {
         val = (int)oval;
         return true;
     }
     val = -1;
     return false;
 }
Exemple #12
0
 ///// <summary>
 ///// Clear the agent's errors.
 ///// </summary>
 ///// <remarks>Lowercase-name and  for core.clj compatibility.</remarks>
 //public void clearErrors()
 //{
 //    _errors = null;
 //}
 public void setErrorMode(Keyword k)
 {
     _errorMode = k;
 }
Exemple #13
0
 public MethodImplCache(IPersistentMap protocol, Keyword methodk)
     : this(protocol, methodk, 0, 0, RT.EMPTY_OBJECT_ARRAY)
 {
 }
 /// <summary>
 /// Create (or find existing) keyword with given symbol's namespace/name.
 /// </summary>
 /// <param name="sym">The symbol giving the keyword's namespace/name.</param>
 /// <returns>A keyword</returns>
 public static Keyword intern(Symbol sym)
 {
     // TODO: Analyze this code for improvements
     Keyword k = new Keyword(sym);
     //Keyword existing = _symKeyMap.PutIfAbsent(sym, k);
     //return existing == null ? k : existing;
     WeakReference wr = new WeakReference(k);
     wr.Target = k;
     WeakReference existingRef = _symKeyMap.PutIfAbsent(sym, wr);
     if (existingRef == null)
         return k;
     Keyword existingk = (Keyword)existingRef.Target;
     if (existingk != null)
         return existingk;
     // entry died in the interim, do over
     // let's not get confused, remove it.  (else infinite loop).
     _symKeyMap.Remove(sym);
     return intern(sym);
 }
Exemple #15
0
        static object matchSymbol(string token, int lastSlashIndex)
        {
            // no :: except at beginning
            if (token.IndexOf("::", 1) != -1)
            {
                return(null);
            }

            string nsStr;
            string nameStr;

            if (lastSlashIndex == -1)
            {
                nsStr   = null;
                nameStr = token;
            }
            else
            {
                nsStr   = token.Substring(0, lastSlashIndex);
                nameStr = token.Substring(lastSlashIndex + 1);
            }

            // Must begin with non-digit, or ':' + non-digit if there is a namespace
            Match nameMatch = nsStr != null?nameSymbolPat.Match(nameStr) : nsSymbolPat.Match(nameStr);

            if (!nameMatch.Success)
            {
                return(null);
            }

            // no trailing :
            if (nameStr.EndsWith(":"))
            {
                return(null);
            }

            if (nsStr != null)
            {
                // Must begin with non-digit or ':' + non-digit
                Match nsMatch = nsSymbolPat.Match(nsStr);
                if (!nsMatch.Success)
                {
                    return(null);
                }

                // no trailing :/ on ns
                if (nsStr != null && nsStr.EndsWith(":/"))
                {
                    return(null);
                }
            }

            if (token.StartsWith("::"))
            {
                return(null);
            }

            bool   isKeyword = token[0] == ':';
            Symbol sym       = Symbol.intern(token.Substring(isKeyword ? 1 : 0));

            if (isKeyword)
            {
                return(Keyword.intern(sym));
            }
            return(sym);
        }
 public SimpleThunk(Type type, Keyword kw)
 {
     _type = type;
     _kw   = kw;
 }
 public KeywordLookupSite(Keyword k)
 {
     _k = k;
 }
Exemple #18
0
 public void setErrorMode(Keyword k)
 {
     _errorMode = k;
 }
Exemple #19
0
 public object GetRealObject(StreamingContext context)
 {
     return(Keyword.intern(_sym));
 }
        // //these are not volatile by design
        // private object _lastType;

        //// core_deftype.clj compatibility
        // public object lastClass
        // {
        //     get { return _lastType; }
        //     set { _lastType = value; }
        // }
        // private IFn _lastImpl;

        // // core_deftype.clj compatibility
        // public IFn lastImpl
        // {
        //     get { return _lastImpl; }
        //     set { _lastImpl = value; }
        //}

        #endregion

        #region C-tors

        public MethodImplCache(Symbol sym, IPersistentMap protocol, Keyword methodk)
            : this(sym, protocol, methodk, 0, 0, RT.EmptyObjectArray)
        {
        }
Exemple #21
0
 /// <summary>
 /// Create (or find existing) keyword with given symbol's namespace/name.
 /// </summary>
 /// <param name="sym">The symbol giving the keyword's namespace/name.</param>
 /// <returns>A keyword</returns>
 public static Keyword intern(Symbol sym)
 {
     Keyword k = new Keyword(sym);
     Keyword existing = _symKeyMap.PutIfAbsent(sym, k);
     return existing == null ? k : existing;
 }
Exemple #22
0
        internal static int RegisterKeywordCallsite(Keyword keyword)
        {
            if (!KeywordCallsitesVar.isBound)
                throw new InvalidOperationException("KEYWORD_CALLSITES is not bound");

            IPersistentVector keywordCallsites = (IPersistentVector)KeywordCallsitesVar.deref();
            keywordCallsites = keywordCallsites.cons(keyword);
            KeywordCallsitesVar.set(keywordCallsites);
            return keywordCallsites.count() - 1;
        }
Exemple #23
0
 public KeywordLookupSite(int n, Keyword k)
 {
     _n = n;
     _k = k;
 }
Exemple #24
0
 public static object GetCompilerOption(Keyword k)
 {
     return RT.get(CompilerOptionsVar.deref(), k);
 }
Exemple #25
0
 public SimpleThunk(Type type, Keyword kw)
 {
     _type = type;
     _kw = kw;
 }
Exemple #26
0
        internal static KeywordExpr RegisterKeyword(Keyword keyword)
        {
            if (!KEYWORDS.IsBound)
                return new KeywordExpr(keyword);

            IPersistentMap keywordsMap = (IPersistentMap)KEYWORDS.deref();
            object id = RT.get(keywordsMap, keyword);
            if (id == null)
                KEYWORDS.set(RT.assoc(keywordsMap, keyword, RegisterConstant(keyword)));
            return new KeywordExpr(keyword);
        }
 public KeywordLookupSite(Keyword k)
 {
     _k = k;
 }