ref: dd77ee3c80c3705bdd6f82af17ee9782cc4460c3
parent: 94e28af38c7cac02c5b592dbbb3d6205d37cb2f2
author: Ori Bernstein <[email protected]>
date: Sat Jun 30 14:56:56 EDT 2012
Default-type for floats.
--- a/parse/cstr.def
+++ b/parse/cstr.def
@@ -1,5 +1,6 @@
Tc(Tcnum, "tcnum") /* arith ops */
-Tc(Tcint, "tcint") /* bitwise ops */
+Tc(Tcint, "tcint") /* behaves like an int, defaults to int as fallback */
+Tc(Tcfloat, "tcfloat") /* behaves like a float, defaults to float as fallback */
Tc(Tctest, "tctest") /* if condition */
Tc(Tcidx, "tcidx") /* indexable */
Tc(Tcslice, "tcslice") /* sliceable */
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -728,16 +728,20 @@
* and default constraint selections */
static Type *tyfix(Node *ctx, Type *t)
{
- static Type *tyint;
+ static Type *tyint, *tyflt;
size_t i;
char buf[1024];
if (!tyint)
tyint = mkty(-1, Tyint);
+ if (!tyflt)
+ tyflt = mkty(-1, Tyfloat64);
t = tf(t);
if (t->type == Tyvar) {
- if (hascstr(t, cstrtab[Tcint]) || cstrcheck(t, tyint))
+ if (hascstr(t, cstrtab[Tcint]) && cstrcheck(t, tyint))
+ return tyint;
+ if (hascstr(t, cstrtab[Tcfloat]) && cstrcheck(t, tyflt))
return tyint;
} else {
if (t->type == Tyarray) {
--- a/parse/type.c
+++ b/parse/type.c
@@ -457,7 +457,9 @@
/* <floats> :: tcnum */
tycstrs[Tyfloat32][0] = cstrtab[Tcnum];
+ tycstrs[Tyfloat32][1] = cstrtab[Tcfloat];
tycstrs[Tyfloat64][0] = cstrtab[Tcnum];
+ tycstrs[Tyfloat64][1] = cstrtab[Tcfloat];
/* @a* :: tctest[0] = tcslice */
tycstrs[Typtr][0] = cstrtab[Tctest];