2005-05-01 11:48:36 +00:00
|
|
|
#include "Symbol.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
string SymbolGetKey (void *ele, void *data)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2011-02-14 13:39:43 +00:00
|
|
|
local Symbol *s = (Symbol*) ele;
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
return [s stringValue];
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
void SymbolFree (void *ele, void *data)
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2011-02-14 13:39:43 +00:00
|
|
|
local Symbol *s = (Symbol*) ele;
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
[s release];
|
|
|
|
}
|
|
|
|
|
|
|
|
hashtab_t symbols;
|
2011-02-14 13:39:43 +00:00
|
|
|
Symbol *lparen;
|
|
|
|
Symbol *rparen;
|
|
|
|
Symbol *quote;
|
|
|
|
Symbol *dot;
|
2005-05-06 23:25:06 +00:00
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
Symbol *symbol (string str)
|
2005-05-06 23:25:06 +00:00
|
|
|
{
|
|
|
|
return [Symbol forString: str];
|
|
|
|
}
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
@implementation Symbol
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2011-01-14 03:07:40 +00:00
|
|
|
symbols = Hash_NewTable (1024, SymbolGetKey, SymbolFree, nil);
|
2005-05-01 11:48:36 +00:00
|
|
|
lparen = [Symbol forString: "("];
|
|
|
|
rparen = [Symbol forString: ")"];
|
|
|
|
quote = [Symbol forString: "'"];
|
2005-05-06 23:25:06 +00:00
|
|
|
dot = symbol(".");
|
2005-05-08 10:37:57 +00:00
|
|
|
[lparen retain];
|
|
|
|
[rparen retain];
|
|
|
|
[quote retain];
|
|
|
|
[dot retain];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (Symbol*) forString: (string) s
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2011-02-14 13:39:43 +00:00
|
|
|
local Symbol *res;
|
2005-05-02 02:33:44 +00:00
|
|
|
|
|
|
|
if ((res = Hash_Find (symbols, s))) {
|
|
|
|
return res;
|
|
|
|
} else {
|
2011-02-14 13:39:43 +00:00
|
|
|
res = (Symbol*) [self newFromString: s];
|
2005-05-02 02:33:44 +00:00
|
|
|
Hash_Add (symbols, res);
|
|
|
|
return res;
|
|
|
|
}
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (Symbol*) leftParen
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return lparen;
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (Symbol*) rightParen
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return rparen;
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (Symbol*) quote
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return quote;
|
|
|
|
}
|
|
|
|
|
2011-02-14 13:39:43 +00:00
|
|
|
+ (Symbol*) dot
|
2005-05-06 23:25:06 +00:00
|
|
|
{
|
|
|
|
return dot;
|
|
|
|
}
|
|
|
|
|
2005-05-02 02:33:44 +00:00
|
|
|
- (string) printForm
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-02 02:33:44 +00:00
|
|
|
return value;
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
2005-05-02 02:33:44 +00:00
|
|
|
- (void) dealloc
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2005-05-02 02:33:44 +00:00
|
|
|
if (Hash_Find (symbols, value) == self) {
|
|
|
|
Hash_Del (symbols, value);
|
|
|
|
}
|
|
|
|
[super dealloc];
|
2005-05-01 11:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|