Commit e683fb7a authored by Ken Thompson's avatar Ken Thompson

bug104

R=r
OCL=21082
CL=21082
parent 9dfb2ea7
...@@ -34,7 +34,7 @@ truncfltlit(Mpflt *fv, Type *t) ...@@ -34,7 +34,7 @@ truncfltlit(Mpflt *fv, Type *t)
} }
void void
convlit(Node *n, Type *t) convlit1(Node *n, Type *t, int conv)
{ {
int et, wt; int et, wt;
...@@ -92,21 +92,6 @@ convlit(Node *n, Type *t) ...@@ -92,21 +92,6 @@ convlit(Node *n, Type *t)
defaultlit(n); defaultlit(n);
return; return;
} }
if(isptrto(t, TSTRING)) {
Rune rune;
int l;
String *s;
rune = mpgetfix(n->val.u.xval);
l = runelen(rune);
s = mal(sizeof(*s)+l);
s->len = l;
runetochar((char*)(s->s), &rune);
n->val.u.sval = s;
n->val.ctype = CTSTR;
break;
}
if(isint[et]) { if(isint[et]) {
// int to int // int to int
if(mpcmpfixfix(n->val.u.xval, minintval[et]) < 0) if(mpcmpfixfix(n->val.u.xval, minintval[et]) < 0)
...@@ -132,6 +117,25 @@ convlit(Node *n, Type *t) ...@@ -132,6 +117,25 @@ convlit(Node *n, Type *t)
truncfltlit(fv, t); truncfltlit(fv, t);
break; break;
} }
if(!conv)
goto bad1;
// only done as string(CONST)
if(isptrto(t, TSTRING)) {
Rune rune;
int l;
String *s;
rune = mpgetfix(n->val.u.xval);
l = runelen(rune);
s = mal(sizeof(*s)+l);
s->len = l;
runetochar((char*)(s->s), &rune);
n->val.u.sval = s;
n->val.ctype = CTSTR;
break;
}
goto bad1; goto bad1;
case Wlitfloat: case Wlitfloat:
...@@ -186,6 +190,12 @@ bad3: ...@@ -186,6 +190,12 @@ bad3:
return; return;
} }
void
convlit(Node *n, Type *t)
{
convlit1(n, t, 0);
}
void void
evconst(Node *n) evconst(Node *n)
{ {
......
...@@ -822,6 +822,7 @@ Node* old2new(Node*, Type*); ...@@ -822,6 +822,7 @@ Node* old2new(Node*, Type*);
/* /*
* const.c * const.c
*/ */
void convlit1(Node*, Type*, int);
void convlit(Node*, Type*); void convlit(Node*, Type*);
void evconst(Node*); void evconst(Node*);
int cmpslit(Node *l, Node *r); int cmpslit(Node *l, Node *r);
......
...@@ -560,7 +560,7 @@ loop: ...@@ -560,7 +560,7 @@ loop:
goto ret; goto ret;
if(!iscomposite(t)) if(!iscomposite(t))
convlit(l, t); convlit1(l, t, 1);
// nil conversion // nil conversion
if(eqtype(t, l->type, 0)) { if(eqtype(t, l->type, 0)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment