Skip to content

Commit 8eec225

Browse files
committed
ignore symbol case
1 parent 00f6ff0 commit 8eec225

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

README.txt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
Simple scheme
1+
Simple Scheme
22

3-
Scheme is known as maxwell of computer science.
3+
Scheme is known as "Maxwell's Equations of Software"
44
I always want to understand how it works.
5-
So, I write an interpreter for its simple version.
6-
7-
Following special operators are supported:
8-
define, lambda, if, cond, let, quote, assign.
9-
10-
It also supports big number and tail recursion.
11-
12-
Most SICP exercise can be written with it.
13-
See example directory
14-
15-
5+
With the belief that the best way of understanding is writing,
6+
I use C++ to write an interpreter for a simplified Scheme version.
167

8+
Currently, following special operators are supported:
179

10+
if,cond,define,lambda,set!,set-car!,set-cdr!,cons,cdr,car,
11+
list,eq?,string?,string=?,number?,atom?,pair?,not,and,or,
12+
+,-,*,/,<,<=,>,>=,display,newline
1813

14+
A stop and copy garbage collector is implemented.
1915

16+
It is really fun to write an interpreter for the great language.

src/symbol.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static struct SymbolElt {
1212
SymbolElt* next;
1313
int len;
1414
char bytes[1];
15-
}* g_buckets[ATOM_BUCKETS_SIZE];
15+
}* g_buckets[SYMBOL_BUCKETS_SIZE];
1616

1717
static long g_scatter[256] = {
1818
1804289383,846930886,1681692777,1714636915,1957747793,424238335,719885386,1649760492,
@@ -75,15 +75,17 @@ const char* Symbol::New(const char* bytes, int len)
7575
// return existing one if found
7676
SymbolElt* p;
7777
for(p = g_buckets[h]; p; p = p->next)
78-
if (p->len == len && memcmp(bytes,p->bytes,len) == 0)
78+
if (p->len == len && strncasecmp(bytes,p->bytes,len) == 0)
7979
return p->bytes;
8080

8181
// alloc atom, p->bytes's length is len+1
8282
p = static_cast<SymbolElt*>(malloc(sizeof(SymbolElt) + len));
8383
assert(p);
8484
p->len = len;
85-
memcpy(p->bytes,bytes,len);
85+
for(int i = 0; i < len; i++)
86+
p->bytes[i] = toupper(bytes[i]);
8687
p->bytes[len] = '\0';
88+
8789

8890
// insert the new atom into buckets
8991
p->next = g_buckets[h];

src/tune.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// define parameters may impact performance
55

6-
const int ATOM_BUCKETS_SIZE = 4096;
6+
const int SYMBOL_BUCKETS_SIZE = 4096;
77

88
#endif
99

0 commit comments

Comments
 (0)