Inheritance: clojure.lang.AReference, ISerializable
Beispiel #1
0
 public static Var intern(Namespace ns, Symbol sym)
 {
     return ns.intern(sym);
 }
Beispiel #2
0
 public static Var intern(Namespace ns, Symbol sym, object root)
 {
     return intern(ns, sym, root, true);
 }
Beispiel #3
0
 public static Var intern(Namespace ns, Symbol sym, object root, bool replaceRoot)
 {
     Var dvout = ns.intern(sym);
     if (!dvout.hasRoot() || replaceRoot)
         dvout.bindRoot(root);
     return dvout;
 }
Beispiel #4
0
 /// <summary>
 /// Construct a var in a given namespace with a given name.
 /// </summary>
 /// <param name="ns">The namespace.</param>
 /// <param name="sym">The var.</param>
 internal Var(Namespace ns, Symbol sym)
 {
     _ns = ns;
     _sym = sym;
     _threadBound = new AtomicBoolean(false);
     _root = new Unbound(this);
     setMeta(PersistentHashMap.EMPTY);
 }
Beispiel #5
0
 /// <summary>
 /// Construct a var in a given namespace with a given name and root value.
 /// </summary>
 /// <param name="ns">The namespace.</param>
 /// <param name="sym">The var.</param>
 /// <param name="root">The root value.</param>
 Var(Namespace ns, Symbol sym, object root)
     : this(ns, sym)
 {
     _root = root;
     ++_rev;
 }
Beispiel #6
0
 public static Namespace namespaceFor(Namespace inns, Symbol sym)
 {
     //note, presumes non-nil sym.ns
     // first check against currentNS' aliases...
     Symbol nsSym = Symbol.create(sym.Namespace);
     Namespace ns = inns.LookupAlias(nsSym);
     if (ns == null)
     {
         // ...otherwise check the Namespaces map.
         ns = Namespace.find(nsSym);
     }
     return ns;
 }
Beispiel #7
0
 VarSerializationHelper(SerializationInfo info, StreamingContext context)
 {
     _ns  = (Namespace)info.GetValue("_ns", typeof(Namespace));
     _sym = (Symbol)info.GetValue("_sym", typeof(Symbol));
 }
Beispiel #8
0
 /// <summary>
 /// Find or create a namespace named by the symbol.
 /// </summary>
 /// <param name="name">The symbol naming the namespace.</param>
 /// <returns>An existing or new namespace</returns>
 public static Namespace findOrCreate(Symbol name)
 {
     Namespace ns = _namespaces.Get(name);
     if (ns != null)
         return ns;
     Namespace newns = new Namespace(name);
     ns = _namespaces.PutIfAbsent(name, newns);
     return ns == null ? newns : ns;
 }
Beispiel #9
0
        /// <summary>
        /// Add an alias for a namespace.
        /// </summary>
        /// <param name="alias">The alias for the namespace.</param>
        /// <param name="ns">The namespace being aliased.</param>
        /// <remarks>Lowercase name for core.clj compatibility</remarks>
        public void addAlias(Symbol alias, Namespace ns)
        {
            if (alias == null || ns == null)
                throw new NullReferenceException("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)));
        }
Beispiel #10
0
        public static Var intern(Symbol nsName, Symbol sym)
        {
            Namespace ns = Namespace.findOrCreate(nsName);

            return(intern(ns, sym));
        }
Beispiel #11
0
 /// <summary>
 /// Construct a var in a given namespace with a given name.
 /// </summary>
 /// <param name="ns">The namespace.</param>
 /// <param name="sym">The var.</param>
 internal Var(Namespace ns, Symbol sym)
 {
     _ns = ns;
     _sym = sym;
     _count = new AtomicInteger();
     _root = _rootUnboundValue;
     setMeta(PersistentHashMap.EMPTY);
 }
Beispiel #12
0
 public static Var intern(Namespace ns, Symbol sym, object root)
 {
     return(intern(ns, sym, root, true));
 }
Beispiel #13
0
 /// <summary>
 /// Construct a var in a given namespace with a given name and root value.
 /// </summary>
 /// <param name="ns">The namespace.</param>
 /// <param name="sym">The var.</param>
 /// <param name="root">The root value.</param>
 Var(Namespace ns, Symbol sym, object root)
     : this(ns, sym)
 {
     _root = root;
     ++_rev;
 }
Beispiel #14
0
 public static Var intern(Namespace ns, Symbol sym)
 {
     return(ns.intern(sym));
 }
Beispiel #15
0
        private static object ResolveIn(Namespace n, Symbol symbol, bool allowPrivate)
        {
            // note: ns-qualified vars must already exist
            if (symbol.Namespace != null)
            {
                Namespace ns = NamespaceFor(n, symbol);
                if (ns == null)
                    throw new Exception("No such namespace: " + symbol.Namespace);

                Var v = ns.FindInternedVar(Symbol.create(symbol.Name));
                if (v == null)
                    throw new Exception("No such var: " + symbol);
                else if (v.Namespace != CurrentNamespace && !v.IsPublic && !allowPrivate)
                    throw new InvalidOperationException(string.Format("var: {0} is not public", symbol));
                return v;
            }
            else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[0] == '[')
                return RT.classForName(symbol.Name);
            else if (symbol.Equals(NS))
                return RT.NS_VAR;
            else if (symbol.Equals(IN_NS))
                return RT.IN_NS_VAR;
            else
            {
                object o = n.GetMapping(symbol);
                if (o == null)
                {
                    if (RT.booleanCast(RT.ALLOW_UNRESOLVED_VARS.deref()))
                        return symbol;
                    else
                        throw new Exception(string.Format("Unable to resolve symbol: {0} in this context", symbol));
                }
                return o;
            }
        }
Beispiel #16
0
        private static object ResolveIn(Namespace n, Symbol symbol, bool allowPrivate)
        {
            // note: ns-qualified vars must already exist
            if (symbol.Namespace != null)
            {
                Namespace ns = namespaceFor(n, symbol);
                if (ns == null)
                    throw new InvalidOperationException("No such namespace: " + symbol.Namespace);

                Var v = ns.FindInternedVar(Symbol.intern(symbol.Name));
                if (v == null)
                    throw new InvalidOperationException("No such var: " + symbol);
                else if (v.Namespace != CurrentNamespace && !v.isPublic && !allowPrivate)
                    throw new InvalidOperationException(string.Format("var: {0} is not public", symbol));
                return v;
            }
            else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[symbol.Name.Length - 1] == ']')
                return RT.classForNameE(symbol.Name);
            else if (symbol.Equals(NsSym))
                return RT.NSVar;
            else if (symbol.Equals(InNsSym))
                return RT.InNSVar;
            else
            {
                if (Util.equals(symbol, CompileStubSymVar.get()))
                    return CompileStubClassVar.get();

                object o = n.GetMapping(symbol);
                if (o == null)
                {
                    if (RT.booleanCast(RT.AllowUnresolvedVarsVar.deref()))
                        return symbol;
                    else
                        throw new InvalidOperationException(string.Format("Unable to resolve symbol: {0} in this context", symbol));
                }
                return o;
            }
        }
Beispiel #17
0
        // core.clj compatibility
        public static object maybeResolveIn(Namespace n, Symbol symbol)
        {
            // note: ns-qualified vars must already exist
            if (symbol.Namespace != null)
            {
                Namespace ns = NamespaceFor(n, symbol);
                if (ns == null)
                    return null;

                Var v = ns.FindInternedVar(Symbol.create(symbol.Name));
                if (v == null)
                    return null;
                 return v;
            }
            else if (symbol.Name.IndexOf('.') > 0 || symbol.Name[0] == '[')
                return RT.classForName(symbol.Name);
            else if (symbol.Equals(NS))
                return RT.NS_VAR;
            else if (symbol.Equals(IN_NS))
                return RT.IN_NS_VAR;
            else
            {
                object o = n.GetMapping(symbol);
                return o;
            }
        }
Beispiel #18
0
        public static object maybeResolveIn(Namespace n, Symbol symbol)
        {
            // note: ns-qualified vars must already exist
            if (symbol.Namespace != null)
            {
                Namespace ns = namespaceFor(n, symbol);
                if (ns == null)
                    return null;

                Var v = ns.FindInternedVar(Symbol.intern(symbol.Name));
                if (v == null)
                    return null;
                return v;
            }
            else if (symbol.Name.IndexOf('.') > 0 && !symbol.Name.EndsWith(".")
                || symbol.Name[symbol.Name.Length - 1] == ']')              /// JAVA: symbol.Name[0] == '[')
                return RT.classForNameE(symbol.Name);
            else if (symbol.Equals(NsSym))
                return RT.NSVar;
            else if (symbol.Equals(InNsSym))
                return RT.InNSVar;
            else
            {
                object o = n.GetMapping(symbol);
                return o;
            }
        }
Beispiel #19
0
 public static Namespace NamespaceFor(Namespace n, Symbol symbol)
 {
     // Note: presumes non-nil sym.ns
     // first check against CurrentNamespace's aliases
     Symbol nsSym = Symbol.create(symbol.Namespace);
     Namespace ns = n.LookupAlias(nsSym);
     if (ns == null)
         // otherwise, check the namespaces map
         ns = Namespace.find(nsSym);
     return ns;
 }
Beispiel #20
0
#pragma warning restore 649

            #region IObjectReference Members

            public object GetRealObject(StreamingContext context)
            {
                return(Namespace.findOrCreate(_name));
            }