4 #include "base/cl_sysdep.h"
7 #include "cln/symbol.h"
12 #include "base/hash/cl_hashuniqweak.h"
16 inline const cl_string hashkey (const cl_symbol& sym)
18 return (cl_string)sym;
21 // A symbol points to a string, so to convert cl_string -> cl_symbol, we just
22 // take the pointer and put it into a cl_symbol.
23 inline cl_symbol::cl_symbol (struct hashuniq * null, const cl_string& s)
24 : cl_rcpointer (as_cl_private_thing(s)) { unused null; }
26 typedef cl_htuniqentry<cl_string,cl_symbol> cl_htentry_from_string_to_symbol;
28 typedef cl_heap_weak_hashtable_uniq<cl_string,cl_symbol> cl_heap_hashtable_from_string_to_symbol;
30 typedef _cl_hashtable_iterator<cl_htentry_from_string_to_symbol> cl_hashtable_from_string_to_symbol_iterator;
32 static void cl_hashtable_from_string_to_symbol_destructor (cl_heap* pointer)
34 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
35 (*(cl_heap_hashtable_from_string_to_symbol*)pointer).~cl_heap_weak_hashtable_uniq();
37 (*(cl_heap_hashtable_from_string_to_symbol*)pointer).~cl_heap_hashtable_from_string_to_symbol();
42 struct cl_ht_from_string_to_symbol : public cl_gcpointer {
44 cl_ht_from_string_to_symbol ();
45 cl_ht_from_string_to_symbol (const cl_ht_from_string_to_symbol&);
46 // Assignment operators.
47 cl_ht_from_string_to_symbol& operator= (const cl_ht_from_string_to_symbol&);
49 cl_hashtable_from_string_to_symbol_iterator iterator () const
50 { return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->iterator(); }
52 cl_symbol * get (const cl_string& s) const;
54 void put (const cl_string& s) const;
57 // These are not inline, because they tend to duplicate a lot of template code.
59 cl_ht_from_string_to_symbol::cl_ht_from_string_to_symbol ()
61 static const cl_class cl_class_hashtable_from_string_to_symbol = {
62 cl_hashtable_from_string_to_symbol_destructor,
65 var cl_heap_hashtable_from_string_to_symbol* ht = new cl_heap_hashtable_from_string_to_symbol ();
67 ht->type = &cl_class_hashtable_from_string_to_symbol;
71 cl_symbol * cl_ht_from_string_to_symbol::get (const cl_string& s) const
73 return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->get(s);
76 void cl_ht_from_string_to_symbol::put (const cl_string& s) const
78 ((cl_heap_hashtable_from_string_to_symbol*)pointer)->put(s);
81 // The global symbol table.
82 class global_symbol_table
85 static cl_ht_from_string_to_symbol* symbol_table;
87 inline cl_symbol* get(const cl_string& s)
89 return symbol_table->get(s);
92 inline void put(const cl_string& s)
97 global_symbol_table();
98 ~global_symbol_table();
101 int global_symbol_table::count = 0;
102 cl_ht_from_string_to_symbol* global_symbol_table::symbol_table;
104 global_symbol_table::global_symbol_table()
107 symbol_table = new cl_ht_from_string_to_symbol();
110 global_symbol_table::~global_symbol_table()
116 // Create or lookup a symbol from its name.
117 cl_symbol::cl_symbol (const cl_string& s)
119 static global_symbol_table symbol_table;
120 var cl_symbol * sym_in_table;
121 sym_in_table = symbol_table.get(s);
124 sym_in_table = symbol_table.get(s);
126 throw runtime_exception();
128 var cl_heap* p = sym_in_table->heappointer;
129 cl_inc_pointer_refcount(p);