summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--development.md11
-rw-r--r--main.c3
-rw-r--r--test.toc89
-rw-r--r--tests/use.toc36
-rw-r--r--tests/use_expected4
-rw-r--r--types.c2
6 files changed, 121 insertions, 24 deletions
diff --git a/development.md b/development.md
index 6021532..255c09a 100644
--- a/development.md
+++ b/development.md
@@ -11,20 +11,19 @@ start.
toc's memory management works using an allocator which never frees anything.
This is because most of toc's data is kept around until the end of the program anyways.
-Use the allocator for "permanent" allocations, and err\_malloc/calloc/realloc for temporary
+Use the allocator for "permanent" allocations, and err\_malloc/err\_calloc/err\_realloc for temporary
allocations (to avoid having it take up space for a long time).
-Because of this, memory leaks can happen if the compilation fails at any point, but they
+Memory leaks can happen if the compilation fails at any point, but they
should not happen if the compilation succeeds. Usually if there's an error
-which causes a memory leak, it will be very small.
+which causes a memory leak, the leak will be very small.
Functions which can fail (i.e. print an error message and stop) return a Status,
-which is a bool, but GCC warns about not using the return value.
+which is a bool, but GCC/clang warns about not using the return value.
+Almost all of toc's types are defined in types.h.
The fixed-width types U8/16/32/64 and I8/16/32/64 have been defined.
data\_structures.c contains a dynamic array implementation which is very useful.
-Many of the members of the types below are dynamic arrays.
-
### Notes
diff --git a/main.c b/main.c
index bc01e30..30c5de5 100644
--- a/main.c
+++ b/main.c
@@ -12,8 +12,7 @@ compile to a temp file, then move it if compilation succeeds
fix including something twice - just use the non-namespacey version if it exists or pick one namespace to use everywhere otherwise
&void
null
-simplify eval macros with val_to_u/i64
-#if should not create a block
+#if should not create a block if it's an EXPR_STMT
&&, ||
start making a standard library... (printf; stringbuilder would be nice to have)
improve type_to_str:
diff --git a/test.toc b/test.toc
index 010f7d5..ec062c2 100644
--- a/test.toc
+++ b/test.toc
@@ -1,22 +1,81 @@
-#include "std/io.toc";
+#include "std/io.toc", io;
+#include "std/mem.toc", mem;
-Point ::= struct {
- x, y : int;
+use mem;
+
+Point ::= struct {
+ x: int;
+ y: int;
+ a ::= 3;
}
Point3D ::= struct {
- use p : Point;
- z : int;
+ use point: Point;
+ z: int;
+
+}
+
+Point4D ::= struct {
+ use p3: Point3D;
+ w: int;
+}
+
+Foo ::= struct {
+ f: f32;
+}
+
+Bar ::= struct {
+ use foo: Foo;
+ use p4: Point4D;
+}
+
+
+
+make_point ::= fn (x_: int, y_: int) use p: Point {
+ x = x_+a;
+ y = y_+a;
+}
+
+make_bar ::= fn (x_ := 0, y_ := 0, z_ := 0, w_ := 0, f_ := 0.0) use b: Bar {
+ x = x_;
+ y = y_;
+ z = z_;
+ b.p4.w = w_;
+ b.f = f_;
}
main ::= fn() {
- use s: Point3D;
- x = 12;
- z = 18;
- y = -1238;
- puti(x);
- puti(y);
- puti(z);
- puti(p.x);
-}
-main();
+
+ use io;
+
+ {
+ use p: Point;
+ use io;
+ x = 5;
+ puti(x);
+ }
+
+
+
+ ps := news(Point, 5);
+ for p := &ps {
+ *p = make_point(3, 5);
+ }
+ for use p, i := &ps {
+ x += i;
+ y += 2*i;
+ }
+ for use p := ps {
+ writei(x);
+ writes(" ");
+ writei(y);
+ puts("");
+ }
+ dels(ps);
+ b := make_bar(5, 8, 13, 12);
+ puti(b.x);
+ puti(b.y);
+ puti(b.z);
+ puti(b.w);
+
+}
diff --git a/tests/use.toc b/tests/use.toc
index 98e9221..ec062c2 100644
--- a/tests/use.toc
+++ b/tests/use.toc
@@ -9,11 +9,41 @@ Point ::= struct {
a ::= 3;
}
+Point3D ::= struct {
+ use point: Point;
+ z: int;
+
+}
+
+Point4D ::= struct {
+ use p3: Point3D;
+ w: int;
+}
+
+Foo ::= struct {
+ f: f32;
+}
+
+Bar ::= struct {
+ use foo: Foo;
+ use p4: Point4D;
+}
+
+
+
make_point ::= fn (x_: int, y_: int) use p: Point {
x = x_+a;
y = y_+a;
}
+make_bar ::= fn (x_ := 0, y_ := 0, z_ := 0, w_ := 0, f_ := 0.0) use b: Bar {
+ x = x_;
+ y = y_;
+ z = z_;
+ b.p4.w = w_;
+ b.f = f_;
+}
+
main ::= fn() {
use io;
@@ -42,4 +72,10 @@ main ::= fn() {
puts("");
}
dels(ps);
+ b := make_bar(5, 8, 13, 12);
+ puti(b.x);
+ puti(b.y);
+ puti(b.z);
+ puti(b.w);
+
}
diff --git a/tests/use_expected b/tests/use_expected
index d47a933..0470d66 100644
--- a/tests/use_expected
+++ b/tests/use_expected
@@ -4,3 +4,7 @@
8 12
9 14
10 16
+5
+8
+13
+12
diff --git a/types.c b/types.c
index 2480924..e4178e6 100644
--- a/types.c
+++ b/types.c
@@ -114,7 +114,7 @@ static Status struct_add_used_struct(Typer *tr, StructDef *to, StructDef *add, D
if (uf) {
/* conflicting uses */
Declaration *first_use = uf->use_decl;
- err_print(first_use->where, "Conflicting used structs, while dealing with %s. %s was imported by this use statement...", struct_name, i);
+ err_print(first_use->where, "Conflicting used structs, while dealing with %s. %s was imported by this use statement...", struct_name, member_name);
info_print(use_where, "... and also by this use statement.");
} else {
/* declared a field, then used something which contains something of the same name */