summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xa.outbin0 -> 16800 bytes
-rw-r--r--eval.c5
-rw-r--r--out.c17
-rw-r--r--out.h2
-rw-r--r--test.toc12
-rw-r--r--toc.c1
-rw-r--r--util/where.c3
7 files changed, 26 insertions, 14 deletions
diff --git a/a.out b/a.out
new file mode 100755
index 0000000..c8b4185
--- /dev/null
+++ b/a.out
Binary files differ
diff --git a/eval.c b/eval.c
index 48534d6..bbefde5 100644
--- a/eval.c
+++ b/eval.c
@@ -74,6 +74,11 @@ static bool eval_expr_as_int(Expression *e, Integer *i) {
return false;
}
Declaration *d = id_decl->decl;
+ if (is_after(d->where, e->where)) {
+ err_print(e->where, "Use of constant before its declaration.");
+ info_print(d->where, "Declaration will be here.");
+ return false;
+ }
if (!(d->flags & DECL_FLAG_CONST)) {
err_print(e->where, "Use of non-constant identifier in a constant expression.");
info_print(d->where, "Declaration was here.");
diff --git a/out.c b/out.c
index cd8f28b..de7dad8 100644
--- a/out.c
+++ b/out.c
@@ -1,19 +1,20 @@
#include "out.h"
/* toc */
+int64_t N = 10;
#include <stdio.h>
-void foo(int64_t (*out__)[3][3]) {
- int64_t av___0[3][3] = {{0}};
- int64_t (*x)[3] = av___0;
- memcpy(*out__, x, 9 * sizeof(int64_t )); return;
+void foo(int64_t (*out__)[10][10]) {
+ int64_t av___0[10][10] = {{0}};
+ int64_t (*x)[10] = av___0;
+ memcpy(*out__, x, 100 * sizeof(int64_t )); return;
}
void main__(void) {
- int64_t av___1[3][3];
+ int64_t av___1[10][10];
foo(&av___1);
- int64_t (*x)[3] = av___1;
+ int64_t (*x)[10] = av___1;
-for (int i = 0; i < 3; i++)
- for (int j = 0; j < 3; j++)
+for (int i = 0; i < 10; i++)
+ for (int j = 0; j < 10; j++)
printf("%ld", x[i][j]);
puts("");
;
diff --git a/out.h b/out.h
index a8d55c8..7b1844e 100644
--- a/out.h
+++ b/out.h
@@ -1,5 +1,5 @@
#include <stddef.h>
#include <stdint.h>
#include <string.h>
-void foo(int64_t (*out__)[3][3]);
+void foo(int64_t (*out__)[10][10]);
void main__(void);
diff --git a/test.toc b/test.toc
index 5c5b9fc..f3ebac3 100644
--- a/test.toc
+++ b/test.toc
@@ -1,13 +1,15 @@
#C("#include <stdio.h>\n");
-foo @= fn() [3][3]int {
- x : [3][3]int;
+N @= 10;
+
+foo @= fn() [N][N]int {
+ x : [N][N]int;
x
};
main @= fn() {
- x : [3][3]int = foo();
+ x : [N][N]int = foo();
#C("
-for (int i = 0; i < 3; i++)
- for (int j = 0; j < 3; j++)
+for (int i = 0; i < 10; i++)
+ for (int j = 0; j < 10; j++)
printf(\"%ld\", x[i][j]);
puts(\"\");
");
diff --git a/toc.c b/toc.c
index fb9864c..b36c5fa 100644
--- a/toc.c
+++ b/toc.c
@@ -22,6 +22,7 @@ typedef long double Floating; /* OPTIM: Switch to double */
#include "util/str.c"
#include "identifiers.c"
#include "tokenizer.c"
+#include "util/where.c"
#include "parse.c"
#include "eval.c"
#include "types.c"
diff --git a/util/where.c b/util/where.c
new file mode 100644
index 0000000..4ac786d
--- /dev/null
+++ b/util/where.c
@@ -0,0 +1,3 @@
+bool is_after(Location a, Location b) { /* a is after b? */
+ return a.code > b.code;
+}