ref: ad1ad7e623b6a47ebf1e220c21462abafbe10e18
parent: d7340522fdf6f9d3799546519de63db0483d6a17
author: Ori Bernstein <[email protected]>
date: Tue Aug 7 18:43:03 EDT 2012
Test arrays within structs. Currently, broken.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -314,7 +314,7 @@
return bscount(a->cstrs) == 0;
/* if a->cstrs is a subset of b->cstrs, all of
* a's constraints are satisfied by b. */
- return bsissubset(b->cstrs, a->cstrs);
+ return bsissubset(a->cstrs, b->cstrs);
}
static void mergecstrs(Inferstate *st, Node *ctx, Type *a, Type *b)
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -355,6 +355,8 @@
int cstreq(Type *t, Cstr **cstrs, size_t len);
int setcstr(Type *t, Cstr *c);
char *tyfmt(char *buf, size_t len, Type *t);
+int cstrfmt(char *buf, size_t len, Type *t);
+char *cstrstr(Type *t);
char *tystr(Type *t);
/* node creation */
--- a/parse/type.c
+++ b/parse/type.c
@@ -269,7 +269,7 @@
return t->cstrs && bshas(t->cstrs, c->cid);
}
-static int cstrfmt(char *buf, size_t len, Type *t)
+int cstrfmt(char *buf, size_t len, Type *t)
{
size_t i;
char *p;
@@ -439,6 +439,13 @@
{
tybfmt(buf, len, t);
return buf;
+}
+
+char *cstrstr(Type *t)
+{
+ char buf[1024];
+ cstrfmt(buf, 1024, t);
+ return strdup(buf);
}
char *tystr(Type *t)
--- /dev/null
+++ b/test/structarray.myr
@@ -1,0 +1,12 @@
+type t = struct
+ a : int[42]
+;;
+
+const main = {
+ var v : t
+
+ v.a[0] = 12
+ v.a[1] = 20
+
+ -> 2*v.a[0] + v.a[1]
+}
--- a/test/tests
+++ b/test/tests
@@ -30,6 +30,7 @@
B struct E 42
B structptr E 42
B structasn E 42
+B structarray E 42
B structret E 42
B array E 7
B arrayaddr E 42