summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-10-15 16:54:18 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2019-10-15 16:54:18 -0400
commit453724df34aad2bf65f3933f6677f32ec264d08f (patch)
tree43d4379f00102b2ba0dd5b7747d89ef79eff5c2e
parentbfc2bb671f900eb37d57707391bf22e5ed8c07f7 (diff)
multiple return values; more tuples
-rw-r--r--cgen.c26
-rw-r--r--main.c2
-rw-r--r--out.c5
3 files changed, 16 insertions, 17 deletions
diff --git a/cgen.c b/cgen.c
index 384cff9..04c7317 100644
--- a/cgen.c
+++ b/cgen.c
@@ -1,6 +1,7 @@
static bool cgen_stmt(CGenerator *g, Statement *s);
static bool cgen_block(CGenerator *g, Block *b);
static bool cgen_expr(CGenerator *g, Expression *e);
+static bool cgen_set_tuple(CGenerator *g, Expression *exprs, Identifier *idents, Expression *to);
static bool cgen_type_pre(CGenerator *g, Type *t, Location where);
static bool cgen_type_post(CGenerator *g, Type *t, Location where);
static bool cgen_decl(CGenerator *g, Declaration *d);
@@ -340,18 +341,9 @@ static bool cgen_set(CGenerator *g, Expression *set_expr, const char *set_str, E
case TYPE_TUPLE:
assert(set_expr);
assert(to_expr);
- switch (to_expr->kind) {
- case EXPR_TUPLE:
- for (size_t i = 0; i < arr_len(to_expr->tuple); i++) {
- cgen_set(g, &set_expr->tuple[i], NULL, &to_expr->tuple[i], NULL);
- }
- break;
- case EXPR_CALL:
- /* TODO */
- break;
- default:
- assert(0); break;
- }
+ assert(set_expr->kind == EXPR_TUPLE);
+ if (!cgen_set_tuple(g, set_expr->tuple, NULL, to_expr))
+ return false;
break;
case TYPE_VOID:
assert(0);
@@ -636,11 +628,13 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
} else if (d->flags & DECL_FLAG_CONST) {
/* TODO */
} else {
- arr_foreach(d->idents, Identifier, i) {
- if (!cgen_type_pre(g, &d->type, d->where)) return false;
+ for (size_t idx = 0; idx < arr_len(d->idents); idx++) {
+ Identifier *i = &d->idents[idx];
+ Type *t = d->type.kind == TYPE_TUPLE ? &d->type.tuple[idx] : &d->type;
+ if (!cgen_type_pre(g, t, d->where)) return false;
cgen_write(g, " ");
cgen_ident(g, *i);
- if (!cgen_type_post(g, &d->type, d->where)) return false;
+ if (!cgen_type_post(g, t, d->where)) return false;
if (g->block == NULL && (d->flags & DECL_FLAG_HAS_EXPR)) {
cgen_write(g, " = ");
/* directly initialize iff we are in global scope */
@@ -648,7 +642,7 @@ static bool cgen_decl(CGenerator *g, Declaration *d) {
return false;
} else if (!(d->flags & DECL_FLAG_HAS_EXPR)) {
cgen_write(g, " = ");
- cgen_zero_value(g, &d->type);
+ cgen_zero_value(g, t);
}
cgen_write(g, "; ");
diff --git a/main.c b/main.c
index 7d79be4..d6e40d9 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@ re-do cgen
make sure initializers for global variables are compile-time constants
any odd number of "s for a string
modifiable strings:
-s := {"sakjdfhkjh ksjdahfkjsd ahs ahdf hsdaf khsadkjfh"};
+s := ["sakjdfhkjh ksjdahfkjsd ahs ahdf hsdaf khsadkjfh"];
*/
#include "toc.c"
diff --git a/out.c b/out.c
index 1612526..5a91b99 100644
--- a/out.c
+++ b/out.c
@@ -38,3 +38,8 @@ void mktup(i64 a, i64 b, i64(*ret0__), i64(*ret1__)) {
void main__(void) {
{
+ i64 a; i64 b; mktup(10, 20, &a, &b);
+
+}}
+
+