summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-08-07 22:43:03 -0400
committerOri Bernstein <ori@eigenstate.org>2012-08-07 22:43:03 -0400
commitad1ad7e623b6a47ebf1e220c21462abafbe10e18 (patch)
tree248c8e236824ba8f008a4fdb970359e899646912
parentd7340522fdf6f9d3799546519de63db0483d6a17 (diff)
downloadmc-ad1ad7e623b6a47ebf1e220c21462abafbe10e18.tar.gz
Test arrays within structs.
Currently, broken.
-rw-r--r--parse/infer.c2
-rw-r--r--parse/parse.h2
-rw-r--r--parse/type.c9
-rw-r--r--test/structarray.myr12
-rw-r--r--test/tests1
5 files changed, 24 insertions, 2 deletions
diff --git a/parse/infer.c b/parse/infer.c
index cdcc895..3ce5c05 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -314,7 +314,7 @@ static int cstrcheck(Type *a, Type *b)
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)
diff --git a/parse/parse.h b/parse/parse.h
index 2b9f2bb..b64eacf 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -355,6 +355,8 @@ int hascstr(Type *t, Cstr *c);
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 */
diff --git a/parse/type.c b/parse/type.c
index d258075..1b6c02a 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -269,7 +269,7 @@ int hascstr(Type *t, Cstr *c)
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;
@@ -441,6 +441,13 @@ char *tyfmt(char *buf, size_t len, Type *t)
return buf;
}
+char *cstrstr(Type *t)
+{
+ char buf[1024];
+ cstrfmt(buf, 1024, t);
+ return strdup(buf);
+}
+
char *tystr(Type *t)
{
char buf[1024];
diff --git a/test/structarray.myr b/test/structarray.myr
new file mode 100644
index 0000000..682d631
--- /dev/null
+++ b/test/structarray.myr
@@ -0,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]
+}
diff --git a/test/tests b/test/tests
index 2378e79..83ef1b3 100644
--- a/test/tests
+++ b/test/tests
@@ -30,6 +30,7 @@ B struct1 E 12
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