summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c2
-rw-r--r--test.toc51
-rw-r--r--types.c8
3 files changed, 15 insertions, 46 deletions
diff --git a/main.c b/main.c
index a46460f..15d8862 100644
--- a/main.c
+++ b/main.c
@@ -13,7 +13,7 @@ cgen_recurse_subtypes should go inside struct params. maybe it could also go int
get rid of UNARY_LEN?
detect circular declarations (A ::= B; B ::= A)
either detect circular #includes or set a #include depth limit (maybe sometimes you want finite circular includes with #if)
-initialization functions (maybe #init(-50), where -50 is the priority and <0 is reserved for standard library)
+initialization statements (maybe #init(-50), where -50 is the priority and <0 is reserved for standard library)
if we do #include "foo.toc", bar; and foo.toc fails, bar should be declared as TYPE_UNKNOWN (right now it's undeclared)
improve type_to_str:
Foo ::= struct(t::Type) {}
diff --git a/test.toc b/test.toc
index cdeb73f..53a092c 100644
--- a/test.toc
+++ b/test.toc
@@ -1,47 +1,14 @@
-#include "tests/std/io.toc", io;
-#include "std/mem.toc";
-
-main ::= fn() {
- nums := news(int, 10);
- for x, i := &nums {
- *x = i*i;
- }
- l := slice_to_ll(nums);
- p := &l;
- while p {
- io.puti(p.head);
- p = p.tail;
- }
- f: Foo;
- f.k = -173;
- f.b = new(Bar);
- f.b.f.b = new(Bar);
- f.b.f.b.f.k = 9;
- io.puti(f.k);
- io.puti(f.b.f.k);
- io.puti(f.b.f.b.f.k);
-}
-
-slice_to_ll ::= fn(t::=, slice: []t) use ll: LinkedList(t) {
- head = slice[0];
- if slice.len == 1 {
- tail = null;
+Point ::= struct {
+ #if 1 {
+ #include "point.toc";
} else {
- tail = new(LinkedList(t));
- *tail = slice_to_ll(slice[1:]);
+ z: int;
}
}
-LinkedList ::= struct (of :: Type) {
- head: of;
- tail: &LinkedList(of);
-}
-
-Foo ::= struct {
- k: int;
- b: &Bar;
-}
-
-Bar ::= struct {
- f: Foo;
+main ::= fn() {
+ p : Point;
+ p.x;
+ p.y;
+ p.z;
}
diff --git a/types.c b/types.c
index da7efcb..e65207e 100644
--- a/types.c
+++ b/types.c
@@ -3881,7 +3881,7 @@ static Status types_stmt(Typer *tr, Statement *s) {
err_print(s->where, "Redeclaration of identifier %s.", istr);
info_print(ident_decl_location(i), "Previous declaration was here.");
free(istr);
- goto inc_fail;
+ return false; /* NOT goto inc_fail; */
}
}
i->decl = d;
@@ -3895,8 +3895,10 @@ static Status types_stmt(Typer *tr, Statement *s) {
}
break;
inc_fail:
- tr->nms = prev_nms;
- typer_block_exit(tr);
+ if (inc_nms) {
+ tr->nms = prev_nms;
+ typer_block_exit(tr);
+ }
return false;
}
case STMT_MESSAGE: {