Commit 4d6d4e7f authored by Ken Thompson's avatar Ken Thompson

random little bugs

SVN=126049
parent 417a971f
...@@ -140,12 +140,16 @@ evconst(Node *n) ...@@ -140,12 +140,16 @@ evconst(Node *n)
} }
if(wl != wr) { if(wl != wr) {
if(wl == Wlitfloat && wr == Wlitint) if(wl == Wlitfloat && wr == Wlitint) {
convlit(n->right, n->left->type); nr->val.dval = nr->val.vval;
else nr->val.ctype = CTFLT;
if(wl == Wlitint && wr == Wlitfloat) wr = whatis(nr);
convlit(n->left, n->right->type); } else
else { if(wl == Wlitint && wr == Wlitfloat) {
nl->val.dval = nl->val.vval;
nl->val.ctype = CTFLT;
wl = whatis(nl);
} else {
yyerror("illegal combination of literals %d %d", nl->etype, nr->etype); yyerror("illegal combination of literals %d %d", nl->etype, nr->etype);
return; return;
} }
......
...@@ -71,7 +71,7 @@ loop: ...@@ -71,7 +71,7 @@ loop:
if(e->op != OLITERAL) { if(e->op != OLITERAL) {
yyerror("expression must be a constant"); yyerror("expression must be a constant");
goto loop; return;
} }
s = n->sym; s = n->sym;
......
...@@ -117,8 +117,10 @@ dumpexportvar(Sym *s) ...@@ -117,8 +117,10 @@ dumpexportvar(Sym *s)
s->exported = 1; s->exported = 1;
n = s->oname; n = s->oname;
if(n == N || n->type == T) if(n == N || n->type == T) {
fatal("dumpexportvar: oname nil: %S\n", s); yyerror("variable exported but not defined: %S\n", s);
return;
}
t = n->type; t = n->type;
reexport(t); reexport(t);
...@@ -141,8 +143,11 @@ dumpexporttype(Sym *s) ...@@ -141,8 +143,11 @@ dumpexporttype(Sym *s)
s->exported = 1; s->exported = 1;
t = s->otype; t = s->otype;
if(t == T) if(t == T) {
fatal("dumpexporttype: otype nil: %S\n", s); yyerror("type exported but not defined: %S\n", s);
return;
}
if(t->sym != s) if(t->sym != s)
fatal("dumpexporttype: cross reference: %S\n", s); fatal("dumpexporttype: cross reference: %S\n", s);
......
...@@ -83,7 +83,8 @@ mainlex(int argc, char *argv[]) ...@@ -83,7 +83,8 @@ mainlex(int argc, char *argv[])
yyparse(); yyparse();
linehist(nil, 0); linehist(nil, 0);
Bterm(curio.bin); if(curio.bin != nil)
Bterm(curio.bin);
if(nerrors) if(nerrors)
errorexit(); errorexit();
......
...@@ -427,11 +427,11 @@ loop: ...@@ -427,11 +427,11 @@ loop:
walktype(n->right, Erv); walktype(n->right, Erv);
if(n->left == N || n->right == N) if(n->left == N || n->right == N)
goto ret; goto ret;
convlit(n->left, n->right->type);
convlit(n->right, n->left->type);
evconst(n); evconst(n);
if(n->op == OLITERAL) if(n->op == OLITERAL)
goto ret; goto ret;
convlit(n->left, n->right->type);
convlit(n->right, n->left->type);
if(n->left->type == T || n->right->type == T) if(n->left->type == T || n->right->type == T)
goto ret; goto ret;
if(!ascompat(n->left->type, n->right->type)) if(!ascompat(n->left->type, n->right->type))
...@@ -503,6 +503,24 @@ loop: ...@@ -503,6 +503,24 @@ loop:
if(t == T) if(t == T)
goto ret; goto ret;
// BOTCH - convert each index opcode
// to look like this and get rid of OINDEXPTR
if(isptr[t->etype])
if(isptrto(t, TSTRING) || isptrto(t->type, TSTRING)) {
// right side must be an int
if(top != Erv)
goto nottop;
if(n->right->type == T) {
convlit(n->right, types[TINT32]);
if(n->right->type == T)
goto ret;
}
if(!isint[n->right->type->etype])
goto badt;
*n = *stringop(n, top);
goto ret;
}
// left side is indirect // left side is indirect
if(isptr[t->etype]) { if(isptr[t->etype]) {
t = t->type; t = t->type;
...@@ -530,20 +548,6 @@ loop: ...@@ -530,20 +548,6 @@ loop:
*n = *mapop(n, top); *n = *mapop(n, top);
break; break;
case TSTRING:
// right side must be an int
if(top != Erv)
goto nottop;
if(n->right->type == T) {
convlit(n->right, types[TINT32]);
if(n->right->type == T)
break;
}
if(!isint[n->right->type->etype])
goto badt;
*n = *stringop(n, top);
break;
case TARRAY: case TARRAY:
case TDARRAY: case TDARRAY:
// right side must be an int // right side must be an int
...@@ -989,7 +993,7 @@ ascompatee(int op, Node **nl, Node **nr) ...@@ -989,7 +993,7 @@ ascompatee(int op, Node **nl, Node **nr)
loop: loop:
if(l == N || r == N) { if(l == N || r == N) {
if(l != r) if(l != r)
yyerror("error in shape across assignment"); yyerror("error in shape across %O", op);
return rev(nn); return rev(nn);
} }
...@@ -1030,7 +1034,7 @@ ascompatet(int op, Node **nl, Type **nr, int fp) ...@@ -1030,7 +1034,7 @@ ascompatet(int op, Node **nl, Type **nr, int fp)
loop: loop:
if(l == N || r == T) { if(l == N || r == T) {
if(l != N || r != T) if(l != N || r != T)
yyerror("error in shape across assignment"); yyerror("error in shape across %O", op);
return rev(nn); return rev(nn);
} }
...@@ -1072,7 +1076,7 @@ ascompatte(int op, Type **nl, Node **nr, int fp) ...@@ -1072,7 +1076,7 @@ ascompatte(int op, Type **nl, Node **nr, int fp)
loop: loop:
if(l == T || r == N) { if(l == T || r == N) {
if(l != T || r != N) if(l != T || r != N)
yyerror("error in shape across assignment"); yyerror("error in shape across %O", op);
return rev(nn); return rev(nn);
} }
convlit(r, l->type); convlit(r, l->type);
...@@ -1293,11 +1297,17 @@ stringop(Node *n, int top) ...@@ -1293,11 +1297,17 @@ stringop(Node *n, int top)
r = nod(OCALL, on, r); r = nod(OCALL, on, r);
break; break;
case OINDEXPTR: case OINDEX:
// sys_indexstring(s, i) // sys_indexstring(s, i)
c = n->left;
if(isptrto(c->type->type, TSTRING)) {
// lhs is string or *string
c = nod(OIND, c, N);
c->type = c->left->type->type;
}
r = nod(OCONV, n->right, N); r = nod(OCONV, n->right, N);
r->type = types[TINT32]; r->type = types[TINT32];
r = nod(OLIST, n->left, r); r = nod(OLIST, c, r);
on = syslook("indexstring", 0); on = syslook("indexstring", 0);
r = nod(OCALL, on, r); r = nod(OCALL, on, r);
break; break;
......
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