예제 #1
0
        public void ContainsKeyOnExistingKeyIsTrue()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);

            Expect(m.containsKey(1));
            Expect(m.containsKey(2));
        }
예제 #2
0
        public void addAlias(Symbol alias, Namespace ns)
        {
            if (alias == null)
            {
                throw new ArgumentNullException("alias", "Expecting Symbol + Namespace");
            }
            if (ns == null)
            {
                throw new ArgumentNullException("ns", "Expecting Symbol + Namespace");
            }

            IPersistentMap map = Aliases;

            // race condition
            while (!map.containsKey(alias))
            {
                IPersistentMap newMap = map.assoc(alias, ns);
                _aliases.CompareAndSet(map, newMap);
                map = Aliases;
            }
            // you can rebind an alias, but only to the initially-aliased namespace
            if (!map.valAt(alias).Equals(ns))
            {
                throw new InvalidOperationException(String.Format("Alias {0} already exists in namespace {1}, aliasing {2}",
                                                                  alias, _name, map.valAt(alias)));
            }
        }
예제 #3
0
파일: FnExpr.cs 프로젝트: ryrency/Misc
 internal Expression GenLocal(GenContext context, LocalBinding lb)
 {
     if (context.Mode == CompilerMode.File && _closes.containsKey(lb))
     {
         Expression expr      = Expression.Field(_thisParam, lb.Name);
         Type       primtType = lb.PrimitiveType;
         if (primtType != null)
         {
             expr = Compiler.MaybeBox(Expression.Convert(expr, primtType));
         }
         return(expr);
     }
     else
     {
         return(lb.ParamExpression);
     }
 }
예제 #4
0
        public void ContainsKeyOnMissingKeyIsFalse()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);

            Expect(m.containsKey(3), False);
        }
예제 #5
0
        public void ContainsKeyNotConfusedByValue()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);

            Expect(m.containsKey("a"), False);
        }
예제 #6
0
        public void removeAlias(Symbol alias)
        {
            IPersistentMap map = Aliases;

            while (map.containsKey(alias))
            {
                IPersistentMap newMap = map.without(alias);
                _aliases.CompareAndSet(map, newMap);
                map = Aliases;
            }
        }
예제 #7
0
        public void CreateOnISeqReturnsMap()
        {
            object[]       items = new object[] { 1, "a", 2, "b" };
            ArrayList      a     = new ArrayList(items);
            ISeq           s     = PersistentList.create(a).seq();
            IPersistentMap m     = PersistentTreeMap.create(s);

            Expect(m.count(), EqualTo(2));
            Expect(m.valAt(1), EqualTo("a"));
            Expect(m.valAt(2), EqualTo("b"));
            Expect(m.containsKey(3), False);
        }
예제 #8
0
        public void CreateOnListReturnsMap()
        {
            object[]  items = new object[] { 1, "a", 2, "b" };
            ArrayList a     = new ArrayList(items);

            IPersistentMap m = PersistentHashMap.create1(a);

            Expect(m.count(), EqualTo(2));
            Expect(m.valAt(1), EqualTo("a"));
            Expect(m.valAt(2), EqualTo("b"));
            Expect(m.containsKey(3), False);
        }
예제 #9
0
        public void CreateOnISeqReturnsMap()
        {
            object[]       items = new object[] { 1, "a", 2, "b" };
            ArrayList      a     = new ArrayList(items);
            ISeq           s     = PersistentList.create(a).seq();
            IPersistentMap m     = PersistentHashMap.create(s);

            Expect(m.count()).To.Equal(2);
            Expect(m.valAt(1)).To.Equal("a");
            Expect(m.valAt(2)).To.Equal("b");
            Expect(m.containsKey(3)).To.Be.False();
        }
예제 #10
0
파일: FnExpr.cs 프로젝트: ryrency/Misc
        private static Type RegisterBaseClass(Type superType, Type baseType)
        {
            IPersistentMap map = _baseClassMapRef.Get();

            while (!map.containsKey(superType))
            {
                IPersistentMap newMap = map.assoc(superType, baseType);
                _baseClassMapRef.CompareAndSet(map, newMap);
                map = _baseClassMapRef.Get();
            }

            return(LookupBaseClass(superType));  // may not be the one we defined -- race condition
        }
예제 #11
0
        public void CreateOnDictionaryReturnsMap()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentTreeMap.create(d);

            Expect(m.count(), EqualTo(2));
            Expect(m.valAt(1), EqualTo("a"));
            Expect(m.valAt(2), EqualTo("b"));
            Expect(m.containsKey(3), False);
        }
예제 #12
0
        public void CreateOnDictionaryReturnsMap()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m = PersistentArrayMap.create(d);

            Expect(m.count()).To.Equal(2);
            Expect(m.valAt(1)).To.Equal("a");
            Expect(m.valAt(2)).To.Equal("b");
            Expect(m.containsKey(3)).To.Be.False();
        }
예제 #13
0
        public void AssocExModifiesOnNewKey()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m1 = PersistentArrayMap.create(d);
            IPersistentMap m2 = m1.assocEx(3, "c");

            Expect(m1.count(), EqualTo(2));
            Expect(m1.containsKey(3), False);
            Expect(m2.count(), EqualTo(3));
            Expect(m2.valAt(3), EqualTo("c"));
        }
예제 #14
0
        public void AssocAddsOnNewKey()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[1] = "a";
            d[2] = "b";

            IPersistentMap m1 = PersistentArrayMap.create(d);
            IPersistentMap m2 = m1.assoc(3, "c");

            Expect(m1.count()).To.Equal(2);
            Expect(m1.containsKey(3)).To.Be.False();
            Expect(m2.count()).To.Equal(3);
            Expect(m2.valAt(3)).To.Equal("c");
        }
예제 #15
0
        public void WithoutOnExistingKeyRemovesKey()
        {
            Dictionary <int, string> d = new Dictionary <int, string>();

            d[3] = "a";
            d[5] = "b";
            d[7] = "c";

            IPersistentMap m1 = PersistentArrayMap.create(d);
            IPersistentMap m2 = m1.without(5);

            Expect(m1.count(), EqualTo(3));
            Expect(m1.valAt(5), EqualTo("b"));
            Expect(m2.count(), EqualTo(2));
            Expect(m2.containsKey(5), False);
        }
예제 #16
0
        public void unmap(Symbol sym)
        {
            if (sym.Namespace != null)
            {
                throw new ArgumentException("Can't unintern a namespace-qualified symbol");
            }

            IPersistentMap map = Mappings;

            while (map.containsKey(sym))
            {
                IPersistentMap newMap = map.without(sym);
                _mappings.CompareAndSet(map, newMap);
                map = Mappings;
            }
        }
예제 #17
0
            protected override object Read(PushbackTextReader r, char c, object opts)
            {
                object o = read(r, true, null, true, opts);

                Symbol oSym = o as Symbol;

                if (oSym == null)
                {
                    throw new Exception("Invalid token: ##" + o);
                }
                if (!_specials.containsKey(oSym))
                {
                    throw new Exception("Unknown symbolic value: ##" + o);
                }

                return(_specials.valAt(oSym));
            }
예제 #18
0
 public void GetClojureFnMappingsWorks()
 {
     IProxy ip = _obj as IProxy;
     IPersistentMap map = ip.__getClojureFnMappings();
     Expect(map.count()).To.Equal(6);
     Expect(map.containsKey("m1"));
     Expect(map.containsKey("m2"));
     Expect(map.containsKey("m2s"));
     Expect(map.containsKey("m2v"));
     Expect(map.containsKey("m3"));
     Expect(map.containsKey("m4"));
 }
예제 #19
0
        private static void EmitMethods(TypeBuilder proxyTB,
                                        List <MethodSignature> sigs,
                                        Dictionary <string, List <MethodSignature> > overloads,
                                        Dictionary <string, FieldBuilder> varMap,
                                        IPersistentMap exposesMethods)
        {
            foreach (MethodSignature sig in sigs)
            {
                FieldBuilder regularFB  = varMap[sig.Name];
                FieldBuilder overloadFB = null;
                if (overloads.ContainsKey(sig.Name))
                {
                    overloadFB = varMap[OverloadName(sig)];
                }

                switch (sig.Source)
                {
                case "super":
                    EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig,
                                         delegate(CljILGen gen)
                    {
                        gen.EmitLoadArg(0);                                     // gen.Emit(OpCodes.Ldarg_0);
                        for (int i = 0; i < sig.ParamTypes.Length; i++)
                        {
                            gen.EmitLoadArg(i + 1);                             // gen.Emit(OpCodes.Ldarg, (i + 1));
                        }
                        gen.Emit(OpCodes.Call, sig.Method);                     // not gen.EmitCall(sig.Method) -- we need call versus callvirt
                    });
                    break;

                case "interface":
                    EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig,
                                         delegate(CljILGen gen)
                    {
                        EmitUnsupported(gen, sig.Name);
                    });
                    break;

                default:
                    EmitForwardingMethod(proxyTB, sig.IsStatic, regularFB, overloadFB, sig,
                                         delegate(CljILGen gen)
                    {
                        EmitUnsupported(gen, sig.Name);
                    });
                    break;
                }
            }

            if (exposesMethods != null)
            {
                foreach (MethodSignature sig in sigs)
                {
                    if (sig.Source == "super")
                    {
                        Symbol name = Symbol.intern(sig.Name);
                        if (exposesMethods.containsKey(name))
                        {
                            CreateSuperCall(proxyTB, (Symbol)exposesMethods.valAt(name), sig.Method);
                        }
                    }
                }
            }
        }
예제 #20
0
 /// <summary>
 /// Test if the set contains the key.
 /// </summary>
 /// <param name="key">The value to test for membership in the set.</param>
 /// <returns>True if the item is in the collection; false, otherwise.</returns>
 public bool contains(object key)
 {
     return(_impl.containsKey(key));
 }
예제 #21
0
 public static Object read(PushbackTextReader r, IPersistentMap opts)
 {
     return(read(r, !opts.containsKey(EOF), opts.valAt(EOF), false, opts));
 }
예제 #22
0
        private static void EmitMethods(TypeBuilder proxyTB, 
            List<MethodSignature> sigs,
            Dictionary<string,List<MethodSignature>> overloads,
            Dictionary<string,FieldBuilder> varMap,
            IPersistentMap exposesMethods)
        {
            foreach (MethodSignature sig in sigs)
            {
                FieldBuilder regularFB = varMap[sig.Name];
                FieldBuilder overloadFB = null;
                if (overloads.ContainsKey(sig.Name))
                    overloadFB = varMap[OverloadName(sig)];

                switch (sig.Source)
                {
                    case "super":
                        EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig,
                            delegate(ILGen gen)
                            {
                                gen.EmitLoadArg(0);                             // gen.Emit(OpCodes.Ldarg_0);
                                for (int i = 0; i < sig.ParamTypes.Length; i++)
                                    gen.EmitLoadArg(i + 1);                     // gen.Emit(OpCodes.Ldarg, (i + 1));
                                gen.Emit(OpCodes.Call, sig.Method);             // not gen.EmitCall(sig.Method) -- we need call versus callvirt
                            });
                        break;
                    case "interface":
                        EmitForwardingMethod(proxyTB, false, regularFB, overloadFB, sig,
                            delegate(ILGen gen)
                            {
                                EmitUnsupported(gen, sig.Name);
                            });
                        break;
                    default:
                        EmitForwardingMethod(proxyTB, sig.IsStatic, regularFB, overloadFB, sig,
                            delegate(ILGen gen)
                            {
                                EmitUnsupported(gen, sig.Name);
                            });
                        break;
                }
            }

            if (exposesMethods != null)
            {
                foreach (MethodSignature sig in sigs)
                {
                    if (sig.Source == "super")
                    {
                        Symbol name = Symbol.intern(sig.Name);
                        if (exposesMethods.containsKey(name))
                            CreateSuperCall(proxyTB, (Symbol)exposesMethods.valAt(name), sig.Method);
                    }
                }
            }
        }
예제 #23
0
 public static Object read(PushbackTextReader r, IPersistentMap opts)
 {
     return read(r, !opts.containsKey(EOF), opts.valAt(EOF), false, opts);
 }