2005-05-01 11:48:36 +00:00
|
|
|
#include "Symbol.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
string SymbolGetKey (void [] ele, void [] data)
|
|
|
|
{
|
2011-01-09 10:41:24 +00:00
|
|
|
local Symbol []s = (Symbol[]) ele;
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
return [s stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SymbolFree (void [] ele, void [] data)
|
|
|
|
{
|
2011-01-09 10:41:24 +00:00
|
|
|
local Symbol []s = (Symbol[]) ele;
|
2005-05-01 11:48:36 +00:00
|
|
|
|
|
|
|
[s release];
|
|
|
|
}
|
|
|
|
|
|
|
|
hashtab_t symbols;
|
2011-01-09 10:41:24 +00:00
|
|
|
Symbol []lparen;
|
|
|
|
Symbol []rparen;
|
|
|
|
Symbol []quote;
|
|
|
|
Symbol []dot;
|
2005-05-06 23:25:06 +00:00
|
|
|
|
2011-01-09 10:41:24 +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
|
|
|
|
{
|
|
|
|
symbols = Hash_NewTable (1024, SymbolGetKey, SymbolFree, NIL);
|
|
|
|
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-01-09 10:41:24 +00:00
|
|
|
+ (Symbol[]) forString: (string) s
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
2011-01-09 10:41:24 +00:00
|
|
|
local Symbol []res;
|
2005-05-02 02:33:44 +00:00
|
|
|
|
|
|
|
if ((res = Hash_Find (symbols, s))) {
|
|
|
|
return res;
|
|
|
|
} else {
|
2011-01-09 10:41:24 +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-01-09 10:41:24 +00:00
|
|
|
+ (Symbol[]) leftParen
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return lparen;
|
|
|
|
}
|
|
|
|
|
2011-01-09 10:41:24 +00:00
|
|
|
+ (Symbol[]) rightParen
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return rparen;
|
|
|
|
}
|
|
|
|
|
2011-01-09 10:41:24 +00:00
|
|
|
+ (Symbol[]) quote
|
2005-05-01 11:48:36 +00:00
|
|
|
{
|
|
|
|
return quote;
|
|
|
|
}
|
|
|
|
|
2011-01-09 10:41:24 +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
|