diff options
-rw-r--r-- | test.toc | 16 | ||||
-rw-r--r-- | types.c | 22 | ||||
-rw-r--r-- | types.h | 8 |
3 files changed, 43 insertions, 3 deletions
@@ -1,6 +1,22 @@ +/* + #include "std/io.toc", io; + + main ::= fn() { io.file_writes(&io.std_out, "hello!\n"); io.file_flush(&io.std_out); } + +*/ + + +#include "tests/std/io.toc", io; +a, b := 5; +main ::= fn() { + a = 6; + io.puti(a); + io.puti(b); +} +main(); @@ -3417,6 +3417,9 @@ static Status types_decl(Typer *tr, Declaration *d) { goto ret; } } + + size_t n_idents; n_idents = arr_len(d->idents); + if (d->flags & DECL_HAS_EXPR) { if (!types_expr(tr, &d->expr)) { success = false; @@ -3452,11 +3455,28 @@ static Status types_decl(Typer *tr, Declaration *d) { } copy_val(tr->allocr, &d->val, val, dtype); d->flags |= DECL_FOUND_VAL; + if (!(d->flags & DECL_IS_CONST)) { + /* + create a value stack for this declaration so that it can be modified by compile time execution, + but not permanently (i.e. output will still have old value) + */ + + Value *copy = typer_malloc(tr, sizeof *copy); + if (n_idents > 1 && dtype->kind != TYPE_TUPLE) { + /* actually, make n_idents copies of the value, and put them in a tuple. */ + Value *tuple = copy->tuple = typer_malloc(tr, n_idents * sizeof *copy); + for (size_t i = 0; i < n_idents; ++i) { + copy_val(tr->allocr, &tuple[i], val, dtype); + } + } else { + copy_val(tr->allocr, copy, val, dtype); + } + typer_arr_add(tr, d->val_stack, copy); + } } } } - size_t n_idents; n_idents = arr_len(d->idents); if (type_is_compileonly(dtype)) { if (!(d->flags & DECL_IS_CONST)) { @@ -882,8 +882,12 @@ typedef struct Declaration { }; Value val; /* only for constant decls, non-constant globals, and varargs. */ - /* for eval, for non-constant local decls: */ - /* the pointers to values need to be fixed, which is why this isn't just Value *. */ + /* + for eval, for non-constant local decls + the pointers to values need to be fixed, which is why this isn't just Value *. + no, this can't be a union with val, because of global variables and possibly + other things (varargs maybe?) + */ Value **val_stack; } Declaration; typedef Declaration *DeclarationPtr; |