quakeforge/ruamoko/scheme/Symbol.r
Brian Koropoff 281b683e14 Initial commit of a future partial implementation of the R5RS Scheme
standard, implemented in Ruamoko.  Currently works for a few simple
"Hello, world!" programs.
2005-05-01 11:48:36 +00:00

74 lines
1.1 KiB
R

#include "Symbol.h"
#include "hash.h"
#include "defs.h"
string SymbolGetKey (void [] ele, void [] data)
{
local Symbol s = (Symbol) ele;
return [s stringValue];
}
void SymbolFree (void [] ele, void [] data)
{
local Symbol s = (Symbol) ele;
[s release];
}
hashtab_t symbols;
Symbol lparen;
Symbol rparen;
Symbol quote;
@implementation Symbol
+ (void) initialize
{
symbols = Hash_NewTable (1024, SymbolGetKey, SymbolFree, NIL);
lparen = [Symbol forString: "("];
rparen = [Symbol forString: ")"];
quote = [Symbol forString: "'"];
}
+ (Symbol) forString: (string) s
{
return (Symbol) [self newFromString: s];
}
+ (Symbol) leftParen
{
return lparen;
}
+ (Symbol) rightParen
{
return rparen;
}
+ (Symbol) quote
{
return quote;
}
- (id) initWithString: (string) s
{
local Symbol res;
[super initWithString: s];
if ((res = Hash_Find (symbols, s))) {
[self release];
return res;
} else {
Hash_Add (symbols, self);
return self;
}
}
- (string) printForm
{
return [self stringValue];
}
@end