From f5f4b585affd50f1f3fb449ba4e891a013e20605 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Fri, 30 Aug 2019 18:24:31 -0400 Subject: improved tuple assignment --- cgen.c | 9 +++++++-- out.c | 2 +- parse.c | 1 - test.toc | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cgen.c b/cgen.c index e5d85c1..77155ac 100644 --- a/cgen.c +++ b/cgen.c @@ -108,11 +108,16 @@ static bool cgen_decl(CGenerator *g, Declaration *d) { /* because , is left-associative, we want to go backwards */ arr_foreach_reverse(&d->idents, Identifier, ident) { Type *type; - if (d->type.kind == TYPE_TUPLE) { + if (d->idents.len > 1) { /* it's a tuple! */ type = &(((Type*)d->type.tuple.data)[--i]); } else { type = &d->type; + if (type->kind == TYPE_TUPLE) { + /* TODO */ + err_print(d->where, "Direct declaration of tuples is not supported yet."); + return false; + } } cgen_type_pre(g, type); if (d->flags & DECL_FLAG_CONST) { /* TODO: remove this */ @@ -127,7 +132,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) { if (d->flags & DECL_FLAG_HAS_EXPR) { cgen_write_space(g); - if (d->type.kind == TYPE_TUPLE) { + if (d->idents.len > 1) { if (expr->kind == EXPR_BINARY_OP && expr->binary.op == BINARY_COMMA) { if (!cgen_expr(g, expr->binary.rhs)) return false; expr = expr->binary.lhs; /* ((3,4),5),6 => (3,4),5 */ diff --git a/out.c b/out.c index 5c95e07..36d37d0 100644 --- a/out.c +++ b/out.c @@ -2,7 +2,7 @@ /* toc */ void main__(void) { - int64_t salkdfj = 123; float something = 6.320000; int64_t baz = 5; int64_t bar = 4; int64_t foo = 3; + int64_t salkdfj = 0; float something = 0; int64_t baz = 0; int64_t bar = 0; int64_t foo = 0; } int main(void) { diff --git a/parse.c b/parse.c index 5a85165..4bb3127 100644 --- a/parse.c +++ b/parse.c @@ -968,7 +968,6 @@ static bool parse_single_type_in_decl(Parser *p, Declaration *d) { tokr_err(t, "You must specify either all types or no types in a single declaration."); return false; } - printf("%lu\n",n_idents_with_this_type); if (annotates_type) { d->flags |= DECL_FLAG_ANNOTATES_TYPE; Type type; diff --git a/test.toc b/test.toc index 42768de..72dced0 100644 --- a/test.toc +++ b/test.toc @@ -1,3 +1,3 @@ main @= fn() { - foo, bar, baz : int, something : float, salkdfj : int = 3, 4, 5, 6.32, 123; + foo, bar, baz : int, something : float, salkdfj : int; }; -- cgit v1.2.3