diff options
-rw-r--r-- | eval.c | 24 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | parse.c | 3 | ||||
-rw-r--r-- | test.toc | 10 |
4 files changed, 26 insertions, 14 deletions
@@ -1155,15 +1155,23 @@ static bool eval_decl(Evaluator *ev, Declaration *d) { long index = 0; arr_foreach(d->idents, Identifier, i) { IdentDecl *id = ident_decl(*i); - if (has_expr && d->type.kind == TYPE_TUPLE) { - val_copy(d->flags & DECL_FLAG_CONST ? ev : NULL, &id->val, &val.tuple[index], &d->type.tuple[index]); - index++; - } else if (!has_expr && d->type.kind == TYPE_ARR) { - /* "stack" array */ - id->val.arr = err_calloc(d->type.arr.n, compiler_sizeof(d->type.arr.of)); - } else { - val_copy(d->flags & DECL_FLAG_CONST ? ev : NULL, &id->val, &val, &d->type); + Type *type = d->type.kind == TYPE_TUPLE ? &d->type.tuple[index] : &d->type; + Value *thisval = NULL; + if (has_expr) + thisval = d->type.kind == TYPE_TUPLE ? &val.tuple[index] : &val; + Type *inner_type = type; + while (inner_type->kind == TYPE_USER) + inner_type = ident_typeval(type->user.name); + if (inner_type->kind == TYPE_STRUCT) { + puts("Allocating space for struct"); + id->val.struc = err_calloc(1, compiler_sizeof(inner_type)); + } else if (inner_type->kind == TYPE_ARR) { + id->val.arr = err_calloc(inner_type->arr.n, compiler_sizeof(inner_type->arr.of)); } + + if (has_expr) + val_copy(d->flags & DECL_FLAG_CONST ? ev : NULL, &id->val, thisval, type); + index++; id->flags |= IDECL_FLAG_HAS_VAL; } if (has_expr && d->expr.kind == EXPR_TUPLE) { @@ -1,8 +1,5 @@ /* TODO: -dot at run time -dot at compile time -dot + string . lvalue using dot with pointers length of slice/arr with .len @@ -619,13 +619,14 @@ static bool parser_is_definitely_type(Parser *p, Token **end) { t->token++; if (token_is_kw(t->token, KW_LBRACE)) goto end; /* void fn expr */ Type return_type; + bool prev = t->token->where.ctx->enabled; t->token->where.ctx->enabled = false; if (!parse_type(p, &return_type)) { /* couldn't parse a return type. void fn type */ ret = true; goto end; } - + t->token->where.ctx->enabled = prev; if (token_is_kw(t->token, KW_LBRACE)) { /* non-void fn expr */ goto end; @@ -7,7 +7,7 @@ Point @= struct { x_coordinate, y_coordinate : int; }; -main @= fn() { +somefn @= fn() int { p:Point; x := p.({ t @= int; @@ -18,5 +18,11 @@ main @= fn() { "y_coordinate" } }); - puti(x); + x +}; + +main @= fn() { + X @= somefn(); + puti(X); + puti(somefn()); }; |