summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--copy.c19
-rw-r--r--main.c2
-rw-r--r--test.toc41
-rw-r--r--types.c3
4 files changed, 50 insertions, 15 deletions
diff --git a/copy.c b/copy.c
index 3c60c25..c102eb6 100644
--- a/copy.c
+++ b/copy.c
@@ -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;
}
}
diff --git a/main.c b/main.c
index aaac4f5..7f078d8 100644
--- a/main.c
+++ b/main.c
@@ -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)
diff --git a/test.toc b/test.toc
index 4ab4dc8..d56944a 100644
--- a/test.toc
+++ b/test.toc
@@ -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
diff --git a/types.c b/types.c
index 4e0b49c..56adeb8 100644
--- a/types.c
+++ b/types.c
@@ -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};