quakeforge/ruamoko/scheme/Symbol.r

91 lines
1.3 KiB
R
Raw Normal View History

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