diff options
-rw-r--r-- | copy.c | 19 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | test.toc | 41 | ||||
-rw-r--r-- | types.c | 3 |
4 files changed, 50 insertions, 15 deletions
@@ -81,6 +81,12 @@ static void copy_struct(Copier *c, StructDef *out, StructDef *in) { size_t nfields = arr_len(in->fields); out->fields = NULL; + out->scope = in->scope; + idents_create(&out->scope.idents, c->allocr, &out->scope); + + Block *prev = c->block; + c->block = &out->scope; + arr_set_lena(&out->fields, nfields, c->allocr); for (size_t i = 0; i < nfields; ++i) { Field *fout = &out->fields[i]; @@ -94,6 +100,7 @@ static void copy_struct(Copier *c, StructDef *out, StructDef *in) { for (size_t i = 0; i < nparams; ++i) { copy_decl(c, &out->params[i], &in->params[i]); } + c->block = prev; } /* works on unresolved and resolved types (for inference) */ @@ -347,11 +354,15 @@ static void copy_decl(Copier *c, Declaration *out, Declaration *in) { } if (in->flags & DECL_ANNOTATES_TYPE) copy_type(c, &out->type, &in->type); - arr_foreach(out->idents, Identifier, ident) { + out->idents = NULL; + size_t nidents = arr_len(in->idents); + arr_set_lena(&out->idents, nidents, c->allocr); + for (size_t i = 0; i < nidents; ++i) { + out->idents[i] = in->idents[i]; assert(c->block); - copier_ident_translate(c, ident); - (*ident)->decl_kind = IDECL_DECL; - (*ident)->decl = out; + copier_ident_translate(c, &out->idents[i]); + out->idents[i]->decl_kind = IDECL_DECL; + out->idents[i]->decl = out; } } @@ -19,8 +19,8 @@ /* TODO: struct parameters -- allow accessing parameters with . - make sure inference works with struct params +- allow accessing parameters with . - should argument set twice error be in call_arg_param_order? --- see infer.c "is resolved_to necessary" (now that ident system has changed) @@ -1,14 +1,41 @@ io ::= nms { - #include "std/io.toc"; +#include "std/io.toc"; }; -Arr ::= struct(x::Type) { - data: []x; +LinkedList ::= struct(t::Type) { + head : t; + tail : &LinkedList(t); +}; + +arr_to_ll ::= fn(t::Type, data: []t) l : LinkedList(t) { + if data.len == 1 { + l.head = data[0]; + l.tail = 0 as &LinkedList(t); + } else { + l.head = data[0]; + l.tail = new(LinkedList(t)); + *l.tail = arr_to_ll(t, data[1:]); + } +}; + +do_thing ::= fn() int { + + a := new(int, 3); + a[0] = 10; + a[1] = 20; + a[2] = 30; + x := arr_to_ll(int, a); + p := &x; + i := 0; + while p { + io.puti(p.head); + p = p.tail; + i += 1; + } + i }; main ::= fn() { - x:Arr(int); - x.data = new(int, 10); - x.data[0] = 17; - io.puti(x.data[0]); + x ::= do_thing(); + do_thing(); };
\ No newline at end of file @@ -1486,9 +1486,6 @@ static bool types_expr(Typer *tr, Expression *e) { return false; } - for (size_t i = 0; i < nparams; ++i) - print_val(arg_vals[i], arg_types + i); - HashTable *table = &base->struc->instances; bool already_exists; Value args_val = {0}; |