aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstrap/all.h1
-rwxr-xr-xbootstrap/cff1bin21520 -> 22816 bytes
-rw-r--r--bootstrap/cgen.c7
-rw-r--r--bootstrap/dump.c2
-rw-r--r--bootstrap/env.c4
-rw-r--r--bootstrap/obj1/main.cff.obin4288 -> 5360 bytes
-rw-r--r--bootstrap/obj1/parse.cff.obin0 -> 3864 bytes
-rw-r--r--bootstrap/parse.c8
-rw-r--r--src/common.hff12
-rw-r--r--src/libc.hff10
-rw-r--r--src/main.cff8
-rw-r--r--src/parse.cff5
-rw-r--r--src/parse.hff9
13 files changed, 57 insertions, 9 deletions
diff --git a/bootstrap/all.h b/bootstrap/all.h
index 3cadd4c..2996f62 100644
--- a/bootstrap/all.h
+++ b/bootstrap/all.h
@@ -76,6 +76,7 @@ enum toktype {
TKtype,
TKexpr,
TKlabel,
+ TKstrify,
TKeof,
};
diff --git a/bootstrap/cff1 b/bootstrap/cff1
index 7b0e748..6a4b6ff 100755
--- a/bootstrap/cff1
+++ b/bootstrap/cff1
Binary files differ
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c
index 3151edf..62a808d 100644
--- a/bootstrap/cgen.c
+++ b/bootstrap/cgen.c
@@ -240,7 +240,7 @@ genexpr(struct expr *ex) {
goto intlit;
break;
case Ezeroini:
- if (ty->t == TYarr || ty->t == TYstruct)
+ if (ty->t == TYarr || ty->t == TYstruct || ty->t == TYunion || ty->t == TYeunion || ty->t == TYslice)
pri("((%t){0})", ty);
else
pri("((%t)0)", ty);
@@ -699,12 +699,15 @@ defctype(const struct type *ty, void *_) {
*cname = xasprintf("__ty%s%d", ty->agg.name ? ty->agg.name : "", id++);
pri("typedef %s %s %s;\n", kind, *cname, *cname);
if (!ty->agg.fwd) {
+ for (int i = 0; i < ty->agg.flds.n; ++i) {
+ struct aggfield fld = ty->agg.flds.d[i];
+ defctype(fld.ty, NULL);
+ }
pri("%s %s {\n", kind, *cname);
if (!ty->agg.flds.n)
pri("char _;\n");
for (int i = 0; i < ty->agg.flds.n; ++i) {
struct aggfield fld = ty->agg.flds.d[i];
- defctype(ty->agg.flds.d[i].ty, NULL);
pri("%t %s;\n", fld.ty, fld.name);
}
pri("};\n");
diff --git a/bootstrap/dump.c b/bootstrap/dump.c
index 157b12f..3bd915f 100644
--- a/bootstrap/dump.c
+++ b/bootstrap/dump.c
@@ -159,6 +159,8 @@ tok2str(struct tok tok) {
return "<type parameter>";
} else if (tok.t == TKexpr) {
return "<const parameter>";
+ } else if (tok.t == TKstrify) {
+ return "#strify";
} else {
snprintf(buf, sizeof buf - 1, "`%c'", tok.t);
}
diff --git a/bootstrap/env.c b/bootstrap/env.c
index b3652fa..601b446 100644
--- a/bootstrap/env.c
+++ b/bootstrap/env.c
@@ -48,8 +48,7 @@ envput(struct env *env, const struct decl *decl) {
}
}
if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body && decl->fn.body) {
- d0->fn.body = decl->fn.body;
- return d0;
+ goto ok;
}
if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body)
return d0;
@@ -61,6 +60,7 @@ envput(struct env *env, const struct decl *decl) {
return NULL;
}
}
+ok:
decls = xcalloc(1, sizeof *decls);
decls->next = env->decls;
diff --git a/bootstrap/obj1/main.cff.o b/bootstrap/obj1/main.cff.o
index 7264f1c..2210165 100644
--- a/bootstrap/obj1/main.cff.o
+++ b/bootstrap/obj1/main.cff.o
Binary files differ
diff --git a/bootstrap/obj1/parse.cff.o b/bootstrap/obj1/parse.cff.o
new file mode 100644
index 0000000..87687b9
--- /dev/null
+++ b/bootstrap/obj1/parse.cff.o
Binary files differ
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 67ec66d..180ddea 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -381,6 +381,14 @@ lex(struct parser *P) {
} else if (!strncmp(s, "#'", 2)) {
tok.t = TKlabel;
tok.str = xstrdup(s);
+ } else if (!strcmp(s, "#FILE")) {
+ tok.t = TKstrlit;
+ tok.str = P->curfile;
+ tok.strlen = strlen(P->curfile);
+ } else if (!strcmp(s, "#LINE")) {
+ tok.t = TKintlit;
+ tok.ty = ty_uint;
+ tok.ilit.i = P->tokspan.line;
} else {
fatal(P, P->tokspan, "invalid #keyword");
}
diff --git a/src/common.hff b/src/common.hff
new file mode 100644
index 0000000..71e3be0
--- /dev/null
+++ b/src/common.hff
@@ -0,0 +1,12 @@
+import "libc.hff";
+
+defmacro assert {
+(ex,s) [ (do
+ if not (ex) {
+ fprintf(stderr, "%s:%d: assertion failed: ", #FILE, #LINE);
+ fprintf(stderr, "`%s'", (s));
+ fprintf(stderr, "\n");
+ abort();
+ }
+) ]
+}
diff --git a/src/libc.hff b/src/libc.hff
index 98a6f3c..f06f4dd 100644
--- a/src/libc.hff
+++ b/src/libc.hff
@@ -1,7 +1,11 @@
! stdio.h
struct FILE;
-extern static stdin FILE,
- stdout FILE,
- stderr FILE;
+extern static stdin *FILE,
+ stdout *FILE,
+ stderr *FILE;
extern fn printf(fmt *const u8, ...) void;
extern fn fprintf(fp *FILE, fmt *const u8, ...) void;
+
+! stdlib.h
+extern fn abort() void;
+extern fn exit(c int) void;
diff --git a/src/main.cff b/src/main.cff
index 1dbbbee..9392a7a 100644
--- a/src/main.cff
+++ b/src/main.cff
@@ -1,7 +1,11 @@
import "libc.hff";
+import "common.hff";
import "parse.hff";
extern fn main(argc int, argv **u8) int {
- let t Tok = { TokT:kw_or, { .i: 1 } };
- printf("%d\n", TokT:kw_or);
+ assert(argc > 1, "args?");
+
+ let p = Parser {};
+ parse(&p, argv[1]);
}
+
diff --git a/src/parse.cff b/src/parse.cff
new file mode 100644
index 0000000..35cccdb
--- /dev/null
+++ b/src/parse.cff
@@ -0,0 +1,5 @@
+import "parse.hff";
+
+extern fn parse(P *Parser, path *const u8) [#]Decl {
+ return {};
+}
diff --git a/src/parse.hff b/src/parse.hff
index 463dd26..9976df3 100644
--- a/src/parse.hff
+++ b/src/parse.hff
@@ -16,3 +16,12 @@ struct Tok {
i i64
},
}
+
+struct Decl {
+}
+
+struct Parser {
+
+}
+
+extern fn parse(P *Parser, path *const u8) [#]Decl;