Skip to content

Commit

Permalink
It self hosts! < 10 hours :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedjmike committed May 24, 2015
1 parent 2a674e2 commit 6516f14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ cc: cc.c
tests/%: tests/%.c cc
cc $<
gcc -m32 a.s -o $@
$@

selfhost: cc
cc cc.c
gcc -m32 a.s -o ccself
ccself
ccself tests/triangular.c
18 changes: 11 additions & 7 deletions cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,28 @@ int token_char = 3;
int token_str = 4;

void next_char () {
if (curch == '\n')
if (curch == 10)
curln++;

curch = fgetc(input);
}

void eat_char () {
buffer[buflength] = curch;
buffer = buffer+buflength;
buffer[0] = curch;
buffer = buffer-buflength;
buflength++;
next_char();
}

void next () {
while (curch == ' ' || curch == '\r' || curch == '\n' || curch == '\t')
while (curch == ' ' || curch == 13 || curch == 10 || curch == 9)
next_char();

if (curch == '#') {
next_char();

while (curch != '\n' && !feof(input))
while (curch != 10 && !feof(input))
next_char();

next();
Expand All @@ -79,7 +81,7 @@ void next () {
while (isdigit(curch) && !feof(input))
eat_char();

} else if (curch == '\'' || curch == '"') {
} else if (curch == 39 || curch == '"') {
if (curch == '"')
token = token_str;

Expand All @@ -89,7 +91,7 @@ void next () {
eat_char();

while (curch != buffer[0] && !feof(input)) {
if (curch == '\\')
if (curch == 92)
eat_char();

eat_char();
Expand All @@ -112,7 +114,9 @@ void next () {
} else
eat_char();

buffer[buflength] = '\0';
buffer = buffer+buflength;
buffer[0] = 0;
buffer = buffer-buflength;
buflength++;
}

Expand Down

0 comments on commit 6516f14

Please sign in to comment.