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)) { cl_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 (*(cl_heap_hashtable_from_string_to_symbol*)pointer).~cl_heap_hashtable_from_string_to_symbol();
38 struct cl_ht_from_string_to_symbol : public cl_gcpointer {
40 cl_ht_from_string_to_symbol ();
41 cl_ht_from_string_to_symbol (const cl_ht_from_string_to_symbol&);
42 // Assignment operators.
43 cl_ht_from_string_to_symbol& operator= (const cl_ht_from_string_to_symbol&);
45 cl_hashtable_from_string_to_symbol_iterator iterator () const
46 { return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->iterator(); }
48 cl_symbol * get (const cl_string& s) const;
50 void put (const cl_string& s) const;
53 // These are not inline, because they tend to duplicate a lot of template code.
55 cl_ht_from_string_to_symbol::cl_ht_from_string_to_symbol ()
57 static const cl_class cl_class_hashtable_from_string_to_symbol = {
58 cl_hashtable_from_string_to_symbol_destructor,
61 var cl_heap_hashtable_from_string_to_symbol* ht = new cl_heap_hashtable_from_string_to_symbol ();
63 ht->type = &cl_class_hashtable_from_string_to_symbol;
67 cl_symbol * cl_ht_from_string_to_symbol::get (const cl_string& s) const
69 return ((cl_heap_hashtable_from_string_to_symbol*)pointer)->get(s);
72 void cl_ht_from_string_to_symbol::put (const cl_string& s) const
74 ((cl_heap_hashtable_from_string_to_symbol*)pointer)->put(s);
77 // The global symbol table.
78 class global_symbol_table
81 static cl_ht_from_string_to_symbol* symbol_table;
83 inline cl_symbol* get(const cl_string& s)
85 return symbol_table->get(s);
88 inline void put(const cl_string& s)
93 global_symbol_table();
94 ~global_symbol_table();
97 int global_symbol_table::count = 0;
98 cl_ht_from_string_to_symbol* global_symbol_table::symbol_table;
100 global_symbol_table::global_symbol_table()
103 symbol_table = new cl_ht_from_string_to_symbol();
106 global_symbol_table::~global_symbol_table()
112 // Create or lookup a symbol from its name.
113 cl_symbol::cl_symbol (const cl_string& s)
115 static global_symbol_table symbol_table;
116 var cl_symbol * sym_in_table;
117 sym_in_table = symbol_table.get(s);
120 sym_in_table = symbol_table.get(s);
122 throw runtime_exception();
124 var cl_heap* p = sym_in_table->heappointer;
125 cl_inc_pointer_refcount(p);