9 #include "cln/symbol.h"
14 #include "cl_hashuniqweak.h"
18 inline const cl_string hashkey (const cl_symbol& sym)
20 return (cl_string)sym;
23 // A symbol points to a string, so to convert cl_string -> cl_symbol, we just
24 // take the pointer and put it into a cl_symbol.
25 inline cl_symbol::cl_symbol (struct hashuniq * null, const cl_string& s)
26 : cl_rcpointer (as_cl_private_thing(s)) { unused null; }
28 typedef cl_htuniqentry<cl_string,cl_symbol> cl_htentry_from_string_to_symbol;
30 typedef cl_heap_weak_hashtable_uniq<cl_string,cl_symbol> cl_heap_hashtable_from_string_to_symbol;
32 typedef _cl_hashtable_iterator<cl_htentry_from_string_to_symbol> cl_hashtable_from_string_to_symbol_iterator;
34 static void cl_hashtable_from_string_to_symbol_destructor (cl_heap* pointer)
36 #if (defined(__mips__) || defined(__mips64__)) && !defined(__GNUC__) // workaround SGI CC bug
37 (*(cl_heap_hashtable_from_string_to_symbol*)pointer).~cl_heap_weak_hashtable_uniq();
39 (*(cl_heap_hashtable_from_string_to_symbol*)pointer).~cl_heap_hashtable_from_string_to_symbol();
43 cl_class cl_class_hashtable_from_string_to_symbol = {
44 cl_hashtable_from_string_to_symbol_destructor,
48 struct cl_ht_from_string_to_symbol : public cl_gcpointer {
50 cl_ht_from_string_to_symbol ();
51 cl_ht_from_string_to_symbol (const cl_ht_from_string_to_symbol&);
52 // Assignment operators.
53 cl_ht_from_string_to_symbol& operator= (const cl_ht_from_string_to_symbol&);
55 cl_hashtable_from_string_to_symbol_iterator iterator () const
56 { return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->iterator(); }
58 cl_symbol * get (const cl_string& s) const;
60 void put (const cl_string& s) const;
63 // These are not inline, because they tend to duplicate a lot of template code.
65 cl_ht_from_string_to_symbol::cl_ht_from_string_to_symbol ()
67 var cl_heap_hashtable_from_string_to_symbol* ht = new cl_heap_hashtable_from_string_to_symbol ();
69 ht->type = &cl_class_hashtable_from_string_to_symbol;
73 cl_symbol * cl_ht_from_string_to_symbol::get (const cl_string& s) const
75 return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->get(s);
78 void cl_ht_from_string_to_symbol::put (const cl_string& s) const
80 ((cl_heap_hashtable_from_string_to_symbol*)pointer)->put(s);
83 // The global symbol table.
84 static cl_ht_from_string_to_symbol symbol_table;
86 // Create or lookup a symbol from its name.
87 cl_symbol::cl_symbol (const cl_string& s)
89 var cl_symbol * sym_in_table;
90 sym_in_table = symbol_table.get(s);
93 sym_in_table = symbol_table.get(s);
95 throw runtime_exception();
97 var cl_heap* p = sym_in_table->heappointer;
98 cl_inc_pointer_refcount(p);
104 CL_PROVIDE_END(cl_symbol)