commit f16ffecacbc703fb085a91c959a596d92ab106b6
parent df2da8ea8f851d535676ac20c0875c1509d046fe
Author: erai <erai@omiltem.net>
Date: Sat, 16 Mar 2024 11:39:43 -0400
Use cc2 as bootstrap
Diffstat:
8 files changed, 78 insertions(+), 27 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,2 @@
cc0
cc1
-cc2
diff --git a/bootstrap.sh b/bootstrap.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+set -ue
+
+# Environmental variables used to compile the bootstrap
+: ${CC:=gcc}
+: ${CFLAGS:=-Wall -Wextra -Wno-unused -pedantic -std=c99}
+
+# First compile the bootstrap
+${CC} ${CFLAGS} -o cc0 ./cc0.c || exit 1
+
+# Then use the bootstrap to compile the compiler
+timeout 1 sh -c ./cc0 < cc1.c > cc1 || { echo "cc0 failed"; exit 1; }
+chmod +x cc1
+
+# Then compile the compiler with itself
+timeout 1 sh -c ./cc1 < cc1.c > cc2 || { echo "cc1 failed"; exit 1; }
+chmod +x cc2
+
+# And check our work
+diff <(xxd cc1) <(xxd cc2)
+cmp cc1 cc2 || { echo "output mismatch"; exit 1; }
+exit 0
diff --git a/build.sh b/build.sh
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-set -ue
-
-# Environmental variables used to compile the bootstrap
-: ${CC:=gcc}
-: ${CFLAGS:=-Os -Wall -Wextra -Wno-unused -pedantic -std=c99}
-
-# First compile the bootstrap
-${CC} ${CFLAGS} -o cc0 ./cc0.c || exit 1
-
-# Then use the bootstrap to compile the compiler
-timeout 1 sh -c ./cc0 < cc1.c > cc1 || { echo "cc0 failed"; exit 1; }
-chmod +x cc1
-
-# Then compile the compiler with itself
-timeout 1 sh -c ./cc1 < cc1.c > cc2 || { echo "cc1 failed"; exit 1; }
-chmod +x cc2
-
-# And check our work
-diff <(xxd cc1) <(xxd cc2)
-cmp cc1 cc2 || { echo "output mismatch"; exit 1; }
-exit 0
diff --git a/cc1.c b/cc1.c
@@ -431,7 +431,7 @@ comp_setup(c: *compiler): void {
c.nc = getchar();
c.lineno = 1;
- c.colno = 1;
+ c.colno = 0;
c.tlen = 0;
c.tmax = 4096;
c.token = alloc(c, c.tmax);
@@ -2449,6 +2449,9 @@ compile_expr(c: *compiler, d: *decl, n: *node, rhs: int): void {
var v: *decl;
var kind: int;
+ c.lineno = n.lineno;
+ c.colno = 0;
+
kind = n.kind;
if (kind == N_STR) {
if (!rhs) {
@@ -3058,7 +3061,7 @@ compile_stmt(c: *compiler, d: *decl, n: *node, top: *label, out: *label): void {
return;
}
- c.lineno = c.lineno;
+ c.lineno = n.lineno;
c.colno = 0;
kind = n.kind;
diff --git a/cc2 b/cc2
Binary files differ.
diff --git a/cc3.l b/cc3.l
@@ -0,0 +1,49 @@
+comment = "//";
+whitespace = [ \r\n\t]*;
+ident = [a-zA-Z_][a-zA-Z0-9_]*;
+str = "\""([^"]|"\\".)*"\"";
+chr = "'"([^"]|"\\".)*"'";
+dec = [0-9]+;
+hex = "0x"[0-9a-fA-F]*;
+lpar = "(";
+rpar = ")";
+lbra = "{";
+rbra = "}";
+comma = ",";
+semi = ";";
+colon = ":";
+star = "*";
+equal = "=";
+eq = "==";
+and = "&";
+andthen = "&&";
+or = "|";
+orelse = "||";
+xor = "^";
+bang = "!";
+ne = "!=";
+lt = "<";
+lsh = "<<";
+le = "<=";
+gt = ">";
+rsh = ">>";
+ge = ">=";
+rsq = "[";
+lsq = "]";
+plus = "+";
+minus = "-";
+mod = "%";
+return = "return";
+break = "break";
+sizeof = "sizeof";
+if = "if";
+else = "else";
+loop = "loop";
+continue = "continue";
+var = "var";
+enum = "enum";
+struct = "struct";
+byte = "byte";
+int = "int";
+void = "void";
+invalid = .;
diff --git a/ccb b/ccb
Binary files differ.
diff --git a/watch.sh b/watch.sh
@@ -23,7 +23,7 @@ fi
) &
# Run build with pager
-./build.sh "$@" 2>&1 | less -Rc; rc=$?
+"$@" 2>&1 | less -Rc; rc=$?
stty sane
# Kill event process