diff options
-rwxr-xr-x | a.out | bin | 0 -> 16800 bytes | |||
-rw-r--r-- | eval.c | 5 | ||||
-rw-r--r-- | out.c | 17 | ||||
-rw-r--r-- | out.h | 2 | ||||
-rw-r--r-- | test.toc | 12 | ||||
-rw-r--r-- | toc.c | 1 | ||||
-rw-r--r-- | util/where.c | 3 |
7 files changed, 26 insertions, 14 deletions
Binary files differ @@ -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."); @@ -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(""); ; @@ -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); @@ -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(\"\"); "); @@ -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; +} |