ref: d932e34a30c72f31632d9b057334cd84b86c1646
parent: f4dba460e188f4f153dc857742701908f0928b46
author: Ori Bernstein <[email protected]>
date: Wed Aug 15 08:22:02 EDT 2012
tylike becomes mktylike.
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -236,8 +236,8 @@
switch (n->lit.littype) {
case Lchr: return mkty(n->line, Tychar); break;
case Lbool: return mkty(n->line, Tybool); break;
- case Lint: return tylike(mktyvar(n->line), Tyint); break;
- case Lflt: return tylike(mktyvar(n->line), Tyfloat32); break;
+ case Lint: return mktylike(n->line, Tyint); break;
+ case Lflt: return mktylike(n->line, Tyfloat32); break;
case Lstr: return mktyslice(n->line, mkty(n->line, Tybyte)); break;
case Lfunc: return n->lit.fnval->func.type; break;
case Lseq: return NULL; break;
@@ -743,7 +743,7 @@
lappend(&st->postcheck, &st->npostcheck, n);
break;
case Osize: /* sizeof @a -> size */
- settype(st, n, tylike(mktyvar(n->line), Tyuint));
+ settype(st, n, mktylike(n->line, Tyuint));
break;
case Ocall: /* (@a, @b, @c, ... -> @r)(@a,@b,@c, ... -> @r) -> @r */
unifycall(st, n);
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -346,7 +346,7 @@
Type *mktystruct(int line, Node **decls, size_t ndecls);
Type *mktyunion(int line, Ucon **decls, size_t ndecls);
Cstr *mkcstr(int line, char *name, Node **memb, size_t nmemb, Node **funcs, size_t nfuncs);
-Type *tylike(Type *t, Ty ty); /* constrains tyvar t like it was builtin ty */
+Type *mktylike(int line, Ty ty); /* constrains tyvar t like it was builtin ty */
int istysigned(Type *t);
/* type manipulation */
--- a/parse/type.c
+++ b/parse/type.c
@@ -22,6 +22,7 @@
Cstr **cstrtab;
size_t ncstrs;
+/* Built in type constraints */
static Cstr *tycstrs[Ntypes + 1][4];
Type *mkty(int line, Ty ty)
@@ -42,6 +43,10 @@
return t;
}
+/*
+ * Duplicates a type, so we can frob
+ * its internals later
+ */
Type *tydup(Type *t)
{
Type *r;
@@ -63,10 +68,16 @@
return r;
}
-Type *tylike(Type *t, Ty like)
+/*
+ * Creates a Tyvar with the same
+ * constrants as the 'like' type
+ */
+Type *mktylike(int line, Ty like)
{
+ Type *t;
int i;
+ t = mktyvar(line);
for (i = 0; tycstrs[like][i]; i++)
setcstr(t, tycstrs[like][i]);
return t;