Commit 13485be9 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/internal/gc: convert Val.U to interface{}

This CL was generated by updating Val in go.go
and then running:

sed -i "" 's/\.U\.[SBXFC]val = /.U = /' *.go
sed -i "" 's/\.U\.Sval/.U.\(string\)/g' *.go *.y
sed -i "" 's/\.U\.Bval/.U.\(bool\)/g' *.go *.y
sed -i "" 's/\.U\.Xval/.U.\(\*Mpint\)/g' *.go *.y
sed -i "" 's/\.U\.Fval/.U.\(\*Mpflt\)/g' *.go *.y
sed -i "" 's/\.U\.Cval/.U.\(\*Mpcplx\)/g' *.go *.y

No functional changes. Passes toolstash -cmp.

This reduces the size of gc.Node from 424 to 392 bytes.
This in turn reduces the permanent (pprof -inuse_space)
memory usage while compiling the test/rotate?.go tests:

test	old(MB)	new(MB)	change
rotate0	379.49	364.78	-3.87%
rotate1	373.42	359.07	-3.84%
rotate2	381.17	366.24	-3.91%
rotate3	374.30	359.95	-3.83%

CL 8445 was similar to this; gri asked that Val's implementation
be hidden first. CLs 8912, 9263, and 9267 have at least
isolated the changes to the cmd/internal/gc package.

Updates #9933.

Change-Id: I83ddfe003d48e0a73c92e819edd3b5e620023084
Reviewed-on: https://go-review.googlesource.com/10059Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent 3c06cff7
......@@ -542,7 +542,7 @@ func cgen_wb(n, res *Node, wb bool) {
var n1 Node
Regalloc(&n1, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, n1.Type), nil, &n1)
Datastring(nl.Val.U.Sval, &p1.From)
Datastring(nl.Val.U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gmove(&n1, res)
Regfree(&n1)
......@@ -1030,7 +1030,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index")
}
v := uint64(Mpgetfix(nr.Val.U.Xval))
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
var n2 Node
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
......@@ -1066,7 +1066,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Debug['B'] == 0 && !n.Bounded {
// check bounds
if Isconst(nl, CTSTR) {
Nodconst(&n4, Types[TUINT32], int64(len(nl.Val.U.Sval)))
Nodconst(&n4, Types[TUINT32], int64(len(nl.Val.U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
n1 = n3
n1.Op = OINDREG
......@@ -1091,7 +1091,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, Types[Tptr]), nil, &n3)
Datastring(nl.Val.U.Sval, &p1.From)
Datastring(nl.Val.U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
n1 = n3
......@@ -1182,7 +1182,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index") // front end should handle
}
v := uint64(Mpgetfix(nr.Val.U.Xval))
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
nlen := n3
......@@ -1227,7 +1227,7 @@ func Agenr(n *Node, a *Node, res *Node) {
var nlen Node
if Isconst(nl, CTSTR) {
Nodconst(&nlen, t, int64(len(nl.Val.U.Sval)))
Nodconst(&nlen, t, int64(len(nl.Val.U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
nlen = n3
nlen.Type = t
......@@ -1247,7 +1247,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, Types[Tptr]), nil, &n3)
Datastring(nl.Val.U.Sval, &p1.From)
Datastring(nl.Val.U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gins(Thearch.Optoas(OADD, n3.Type), &n2, &n3)
goto indexdone1
......@@ -1372,7 +1372,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Fatal("constant string constant index") // front end should handle
}
v := uint64(Mpgetfix(nr.Val.U.Xval))
v := uint64(Mpgetfix(nr.Val.U.(*Mpint)))
if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
if Debug['B'] == 0 && !n.Bounded {
p1 := Thearch.Ginscmp(OGT, Types[Simtype[TUINT]], &nlen, Nodintconst(int64(v)), +1)
......@@ -1410,7 +1410,7 @@ func Agenr(n *Node, a *Node, res *Node) {
t = Types[TUINT64]
}
if Isconst(nl, CTSTR) {
Nodconst(&nlen, t, int64(len(nl.Val.U.Sval)))
Nodconst(&nlen, t, int64(len(nl.Val.U.(string))))
} else if Isslice(nl.Type) || nl.Type.Etype == TSTRING {
// nlen already initialized
} else {
......@@ -1425,7 +1425,7 @@ func Agenr(n *Node, a *Node, res *Node) {
if Isconst(nl, CTSTR) {
Regalloc(&n3, Types[Tptr], res)
p1 := Thearch.Gins(Thearch.Optoas(OAS, n3.Type), nil, &n3) // XXX was LEAQ!
Datastring(nl.Val.U.Sval, &p1.From)
Datastring(nl.Val.U.(string), &p1.From)
p1.From.Type = obj.TYPE_ADDR
Thearch.Gins(Thearch.Optoas(OADD, n3.Type), &n2, &n3)
goto indexdone
......@@ -1712,7 +1712,7 @@ func Igen(n *Node, a *Node, res *Node) {
// Compute &a[i] as &a + i*width.
a.Type = n.Type
a.Xoffset += Mpgetfix(n.Right.Val.U.Xval) * n.Type.Width
a.Xoffset += Mpgetfix(n.Right.Val.U.(*Mpint)) * n.Type.Width
Fixlargeoffset(a)
return
}
......@@ -1862,11 +1862,11 @@ func bgenx(n, res *Node, wantTrue bool, likely int, to *obj.Prog) {
Fatal("bgen: non-bool const %v\n", Nconv(n, obj.FmtLong))
}
if genval {
Cgen(Nodbool(wantTrue == n.Val.U.Bval), res)
Cgen(Nodbool(wantTrue == n.Val.U.(bool)), res)
return
}
// If n == wantTrue, jump; otherwise do nothing.
if wantTrue == n.Val.U.Bval {
if wantTrue == n.Val.U.(bool) {
Patch(Gbranch(obj.AJMP, nil, likely), to)
}
return
......@@ -2187,7 +2187,7 @@ func stkof(n *Node) int64 {
return off
}
if Isconst(n.Right, CTINT) {
return off + t.Type.Width*Mpgetfix(n.Right.Val.U.Xval)
return off + t.Type.Width*Mpgetfix(n.Right.Val.U.(*Mpint))
}
return 1000
......@@ -2642,7 +2642,7 @@ func cgen_div(op int, nl *Node, nr *Node, res *Node) {
case TUINT64:
var m Magic
m.W = w
m.Ud = uint64(Mpgetfix(nr.Val.U.Xval))
m.Ud = uint64(Mpgetfix(nr.Val.U.(*Mpint)))
Umagic(&m)
if m.Bad != 0 {
break
......@@ -2680,7 +2680,7 @@ func cgen_div(op int, nl *Node, nr *Node, res *Node) {
case TINT64:
var m Magic
m.W = w
m.Sd = Mpgetfix(nr.Val.U.Xval)
m.Sd = Mpgetfix(nr.Val.U.(*Mpint))
Smagic(&m)
if m.Bad != 0 {
break
......@@ -3024,7 +3024,7 @@ func cgen_slice(n, res *Node, wb bool) {
return
}
if n.Op == OSLICESTR && Isconst(n.Left, CTSTR) {
Nodconst(&xlen, indexRegType, int64(len(n.Left.Val.U.Sval)))
Nodconst(&xlen, indexRegType, int64(len(n.Left.Val.U.(string))))
return
}
regalloc(&xlen, indexRegType, nil)
......@@ -3180,20 +3180,20 @@ func cgen_slice(n, res *Node, wb bool) {
if n.Op == OSLICEARR || n.Op == OSLICE3ARR {
bound = n.Left.Type.Type.Bound
} else if n.Op == OSLICESTR && Isconst(n.Left, CTSTR) {
bound = int64(len(n.Left.Val.U.Sval))
bound = int64(len(n.Left.Val.U.(string)))
}
if Isconst(&i, CTINT) {
if mpcmpfixc(i.Val.U.Xval, 0) < 0 || bound >= 0 && mpcmpfixc(i.Val.U.Xval, bound) > 0 {
if mpcmpfixc(i.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(i.Val.U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
if Isconst(&j, CTINT) {
if mpcmpfixc(j.Val.U.Xval, 0) < 0 || bound >= 0 && mpcmpfixc(j.Val.U.Xval, bound) > 0 {
if mpcmpfixc(j.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(j.Val.U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
if Isconst(&k, CTINT) {
if mpcmpfixc(k.Val.U.Xval, 0) < 0 || bound >= 0 && mpcmpfixc(k.Val.U.Xval, bound) > 0 {
if mpcmpfixc(k.Val.U.(*Mpint), 0) < 0 || bound >= 0 && mpcmpfixc(k.Val.U.(*Mpint), bound) > 0 {
Yyerror("slice index out of bounds")
}
}
......@@ -3202,7 +3202,7 @@ func cgen_slice(n, res *Node, wb bool) {
same := func(n1, n2 *Node) bool {
return n1.Op == OREGISTER && n2.Op == OREGISTER && n1.Reg == n2.Reg ||
n1.Op == ONAME && n2.Op == ONAME && n1.Orig == n2.Orig && n1.Type == n2.Type && n1.Xoffset == n2.Xoffset ||
n1.Op == OLITERAL && n2.Op == OLITERAL && Mpcmpfixfix(n1.Val.U.Xval, n2.Val.U.Xval) == 0
n1.Op == OLITERAL && n2.Op == OLITERAL && Mpcmpfixfix(n1.Val.U.(*Mpint), n2.Val.U.(*Mpint)) == 0
}
// obvious reports whether n1 <= n2 is obviously true,
......@@ -3221,7 +3221,7 @@ func cgen_slice(n, res *Node, wb bool) {
return true // len(x) <= cap(x) always true
}
if Isconst(n1, CTINT) && Isconst(n2, CTINT) {
if Mpcmpfixfix(n1.Val.U.Xval, n2.Val.U.Xval) <= 0 {
if Mpcmpfixfix(n1.Val.U.(*Mpint), n2.Val.U.(*Mpint)) <= 0 {
return true // n1, n2 constants such that n1 <= n2
}
Yyerror("slice index out of bounds")
......@@ -3312,9 +3312,9 @@ func cgen_slice(n, res *Node, wb bool) {
switch j.Op {
case OLITERAL:
if Isconst(&i, CTINT) {
Nodconst(&j, indexRegType, Mpgetfix(j.Val.U.Xval)-Mpgetfix(i.Val.U.Xval))
Nodconst(&j, indexRegType, Mpgetfix(j.Val.U.(*Mpint))-Mpgetfix(i.Val.U.(*Mpint)))
if Debug_slice > 0 {
Warn("slice: result len == %d", Mpgetfix(j.Val.U.Xval))
Warn("slice: result len == %d", Mpgetfix(j.Val.U.(*Mpint)))
}
break
}
......@@ -3329,7 +3329,7 @@ func cgen_slice(n, res *Node, wb bool) {
fallthrough
case OREGISTER:
if i.Op == OLITERAL {
v := Mpgetfix(i.Val.U.Xval)
v := Mpgetfix(i.Val.U.(*Mpint))
if v != 0 {
ginscon(Thearch.Optoas(OSUB, indexRegType), v, &j)
}
......@@ -3372,9 +3372,9 @@ func cgen_slice(n, res *Node, wb bool) {
switch k.Op {
case OLITERAL:
if Isconst(&i, CTINT) {
Nodconst(&k, indexRegType, Mpgetfix(k.Val.U.Xval)-Mpgetfix(i.Val.U.Xval))
Nodconst(&k, indexRegType, Mpgetfix(k.Val.U.(*Mpint))-Mpgetfix(i.Val.U.(*Mpint)))
if Debug_slice > 0 {
Warn("slice: result cap == %d", Mpgetfix(k.Val.U.Xval))
Warn("slice: result cap == %d", Mpgetfix(k.Val.U.(*Mpint)))
}
break
}
......@@ -3395,7 +3395,7 @@ func cgen_slice(n, res *Node, wb bool) {
Warn("slice: result cap == 0")
}
} else if i.Op == OLITERAL {
v := Mpgetfix(i.Val.U.Xval)
v := Mpgetfix(i.Val.U.(*Mpint))
if v != 0 {
ginscon(Thearch.Optoas(OSUB, indexRegType), v, &k)
}
......@@ -3478,7 +3478,7 @@ func cgen_slice(n, res *Node, wb bool) {
w = res.Type.Type.Width // res is []T, elem size is T.width
}
if Isconst(&i, CTINT) {
ginscon(Thearch.Optoas(OADD, xbase.Type), Mpgetfix(i.Val.U.Xval)*w, &xbase)
ginscon(Thearch.Optoas(OADD, xbase.Type), Mpgetfix(i.Val.U.(*Mpint))*w, &xbase)
} else if Thearch.AddIndex != nil && Thearch.AddIndex(&i, w, &xbase) {
// done by back end
} else if w == 1 {
......
This diff is collapsed.
......@@ -89,8 +89,8 @@ func subnode(nr *Node, ni *Node, nc *Node) {
t := Types[tc]
if nc.Op == OLITERAL {
nodfconst(nr, t, &nc.Val.U.Cval.Real)
nodfconst(ni, t, &nc.Val.U.Cval.Imag)
nodfconst(nr, t, &nc.Val.U.(*Mpcplx).Real)
nodfconst(ni, t, &nc.Val.U.(*Mpcplx).Imag)
return
}
......@@ -226,7 +226,7 @@ func nodfconst(n *Node, t *Type, fval *Mpflt) {
n.Op = OLITERAL
n.Addable = true
ullmancalc(n)
n.Val.U.Fval = fval
n.Val.U = fval
n.Val.Ctype = CTFLT
n.Type = t
......
......@@ -830,7 +830,7 @@ func structfield(n *Node) *Type {
switch n.Val.Ctype {
case CTSTR:
f.Note = new(string)
*f.Note = n.Val.U.Sval
*f.Note = n.Val.U.(string)
default:
Yyerror("field annotation must be string")
......
......@@ -302,12 +302,12 @@ func Vconv(v *Val, flag int) string {
switch v.Ctype {
case CTINT:
if (flag&obj.FmtSharp != 0) || fmtmode == FExp {
return Bconv(v.U.Xval, obj.FmtSharp)
return Bconv(v.U.(*Mpint), obj.FmtSharp)
}
return Bconv(v.U.Xval, 0)
return Bconv(v.U.(*Mpint), 0)
case CTRUNE:
x := Mpgetfix(v.U.Xval)
x := Mpgetfix(v.U.(*Mpint))
if ' ' <= x && x < 0x80 && x != '\\' && x != '\'' {
return fmt.Sprintf("'%c'", int(x))
}
......@@ -317,34 +317,34 @@ func Vconv(v *Val, flag int) string {
if 0 <= x && x <= utf8.MaxRune {
return fmt.Sprintf("'\\U%08x'", uint64(x))
}
return fmt.Sprintf("('\\x00' + %v)", v.U.Xval)
return fmt.Sprintf("('\\x00' + %v)", v.U.(*Mpint))
case CTFLT:
if (flag&obj.FmtSharp != 0) || fmtmode == FExp {
return Fconv(v.U.Fval, 0)
return Fconv(v.U.(*Mpflt), 0)
}
return Fconv(v.U.Fval, obj.FmtSharp)
return Fconv(v.U.(*Mpflt), obj.FmtSharp)
case CTCPLX:
if (flag&obj.FmtSharp != 0) || fmtmode == FExp {
return fmt.Sprintf("(%v+%vi)", &v.U.Cval.Real, &v.U.Cval.Imag)
return fmt.Sprintf("(%v+%vi)", &v.U.(*Mpcplx).Real, &v.U.(*Mpcplx).Imag)
}
if mpcmpfltc(&v.U.Cval.Real, 0) == 0 {
return fmt.Sprintf("%vi", Fconv(&v.U.Cval.Imag, obj.FmtSharp))
if mpcmpfltc(&v.U.(*Mpcplx).Real, 0) == 0 {
return fmt.Sprintf("%vi", Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp))
}
if mpcmpfltc(&v.U.Cval.Imag, 0) == 0 {
return Fconv(&v.U.Cval.Real, obj.FmtSharp)
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) == 0 {
return Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp)
}
if mpcmpfltc(&v.U.Cval.Imag, 0) < 0 {
return fmt.Sprintf("(%v%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp))
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) < 0 {
return fmt.Sprintf("(%v%vi)", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp))
}
return fmt.Sprintf("(%v+%vi)", Fconv(&v.U.Cval.Real, obj.FmtSharp), Fconv(&v.U.Cval.Imag, obj.FmtSharp))
return fmt.Sprintf("(%v+%vi)", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp))
case CTSTR:
return strconv.Quote(v.U.Sval)
return strconv.Quote(v.U.(string))
case CTBOOL:
if v.U.Bval {
if v.U.(bool) {
return "true"
}
return "false"
......
......@@ -333,22 +333,22 @@ func Clearslim(n *Node) {
switch Simtype[n.Type.Etype] {
case TCOMPLEX64, TCOMPLEX128:
z.Val.U.Cval = new(Mpcplx)
Mpmovecflt(&z.Val.U.Cval.Real, 0.0)
Mpmovecflt(&z.Val.U.Cval.Imag, 0.0)
z.Val.U = new(Mpcplx)
Mpmovecflt(&z.Val.U.(*Mpcplx).Real, 0.0)
Mpmovecflt(&z.Val.U.(*Mpcplx).Imag, 0.0)
case TFLOAT32, TFLOAT64:
var zero Mpflt
Mpmovecflt(&zero, 0.0)
z.Val.Ctype = CTFLT
z.Val.U.Fval = &zero
z.Val.U = &zero
case TPTR32, TPTR64, TCHAN, TMAP:
z.Val.Ctype = CTNIL
case TBOOL:
z.Val.Ctype = CTBOOL
z.Val.U.Bval = false
z.Val.U = false
case TINT8,
TINT16,
......@@ -359,8 +359,8 @@ func Clearslim(n *Node) {
TUINT32,
TUINT64:
z.Val.Ctype = CTINT
z.Val.U.Xval = new(Mpint)
Mpmovecfix(z.Val.U.Xval, 0)
z.Val.U = new(Mpint)
Mpmovecfix(z.Val.U.(*Mpint), 0)
default:
Fatal("clearslim called on type %v", n.Type)
......@@ -1122,7 +1122,7 @@ func componentgen_wb(nr, nl *Node, wb bool) bool {
nodl.Type = Ptrto(Types[TUINT8])
Regalloc(&nodr, Types[Tptr], nil)
p := Thearch.Gins(Thearch.Optoas(OAS, Types[Tptr]), nil, &nodr)
Datastring(nr.Val.U.Sval, &p.From)
Datastring(nr.Val.U.(string), &p.From)
p.From.Type = obj.TYPE_ADDR
Thearch.Gmove(&nodr, &nodl)
Regfree(&nodr)
......@@ -1130,7 +1130,7 @@ func componentgen_wb(nr, nl *Node, wb bool) bool {
// length
nodl.Type = Types[Simtype[TUINT]]
nodl.Xoffset += int64(Array_nel) - int64(Array_array)
Nodconst(&nodr, nodl.Type, int64(len(nr.Val.U.Sval)))
Nodconst(&nodr, nodl.Type, int64(len(nr.Val.U.(string))))
Thearch.Gmove(&nodr, &nodl)
return true
}
......
......@@ -83,13 +83,13 @@ type Mpcplx struct {
type Val struct {
Ctype int16
U struct {
Bval bool // bool value CTBOOL
Xval *Mpint // int CTINT, rune CTRUNE
Fval *Mpflt // float CTFLT
Cval *Mpcplx // float CTCPLX
Sval string // string CTSTR
}
// U contains one of:
// bool bool when Ctype == CTBOOL
// *Mpint int when Ctype == CTINT, rune when Ctype == CTRUNE
// *Mpflt float when Ctype == CTFLT
// *Mpcplx pair of floats when Ctype == CTCPLX
// string string when Ctype == CTSTR
U interface{}
}
type Pkg struct {
......
......@@ -1131,13 +1131,13 @@ hidden_importsym:
{
var p *Pkg
if $2.U.Sval == "" {
if $2.U.(string) == "" {
p = importpkg;
} else {
if isbadimport($2.U.Sval) {
if isbadimport($2.U.(string)) {
errorexit();
}
p = mkpkg($2.U.Sval);
p = mkpkg($2.U.(string));
}
$$ = Pkglookup($4.Name, p);
}
......@@ -1145,13 +1145,13 @@ hidden_importsym:
{
var p *Pkg
if $2.U.Sval == "" {
if $2.U.(string) == "" {
p = importpkg;
} else {
if isbadimport($2.U.Sval) {
if isbadimport($2.U.(string)) {
errorexit();
}
p = mkpkg($2.U.Sval);
p = mkpkg($2.U.(string));
}
$$ = Pkglookup("?", p);
}
......@@ -1945,7 +1945,7 @@ oliteral:
hidden_import:
LIMPORT LNAME LLITERAL ';'
{
importimport($2, $3.U.Sval);
importimport($2, $3.U.(string));
}
| LVAR hidden_pkg_importsym hidden_type ';'
{
......@@ -2172,14 +2172,14 @@ hidden_literal:
$$ = nodlit($2);
switch($$.Val.Ctype){
case CTINT, CTRUNE:
mpnegfix($$.Val.U.Xval);
mpnegfix($$.Val.U.(*Mpint));
break;
case CTFLT:
mpnegflt($$.Val.U.Fval);
mpnegflt($$.Val.U.(*Mpflt));
break;
case CTCPLX:
mpnegflt(&$$.Val.U.Cval.Real);
mpnegflt(&$$.Val.U.Cval.Imag);
mpnegflt(&$$.Val.U.(*Mpcplx).Real);
mpnegflt(&$$.Val.U.(*Mpcplx).Imag);
break;
default:
Yyerror("bad negated constant");
......@@ -2199,11 +2199,11 @@ hidden_constant:
{
if $2.Val.Ctype == CTRUNE && $4.Val.Ctype == CTINT {
$$ = $2;
mpaddfixfix($2.Val.U.Xval, $4.Val.U.Xval, 0);
mpaddfixfix($2.Val.U.(*Mpint), $4.Val.U.(*Mpint), 0);
break;
}
$4.Val.U.Cval.Real = $4.Val.U.Cval.Imag;
Mpmovecflt(&$4.Val.U.Cval.Imag, 0.0);
$4.Val.U.(*Mpcplx).Real = $4.Val.U.(*Mpcplx).Imag;
Mpmovecflt(&$4.Val.U.(*Mpcplx).Imag, 0.0);
$$ = nodcplxlit($2.Val, $4.Val);
}
......
......@@ -412,20 +412,20 @@ func Naddr(a *obj.Addr, n *Node) {
case CTFLT:
a.Type = obj.TYPE_FCONST
a.Val = mpgetflt(n.Val.U.Fval)
a.Val = mpgetflt(n.Val.U.(*Mpflt))
case CTINT, CTRUNE:
a.Sym = nil
a.Type = obj.TYPE_CONST
a.Offset = Mpgetfix(n.Val.U.Xval)
a.Offset = Mpgetfix(n.Val.U.(*Mpint))
case CTSTR:
datagostring(n.Val.U.Sval, a)
datagostring(n.Val.U.(string), a)
case CTBOOL:
a.Sym = nil
a.Type = obj.TYPE_CONST
a.Offset = int64(obj.Bool2int(n.Val.U.Bval))
a.Offset = int64(obj.Bool2int(n.Val.U.(bool)))
case CTNIL:
a.Sym = nil
......
......@@ -647,13 +647,13 @@ func importfile(f *Val, line int) {
return
}
if len(f.U.Sval) == 0 {
if len(f.U.(string)) == 0 {
Yyerror("import path is empty")
fakeimport()
return
}
if isbadimport(f.U.Sval) {
if isbadimport(f.U.(string)) {
fakeimport()
return
}
......@@ -662,29 +662,29 @@ func importfile(f *Val, line int) {
// but we reserve the import path "main" to identify
// the main package, just as we reserve the import
// path "math" to identify the standard math package.
if f.U.Sval == "main" {
if f.U.(string) == "main" {
Yyerror("cannot import \"main\"")
errorexit()
}
if myimportpath != "" && f.U.Sval == myimportpath {
Yyerror("import %q while compiling that package (import cycle)", f.U.Sval)
if myimportpath != "" && f.U.(string) == myimportpath {
Yyerror("import %q while compiling that package (import cycle)", f.U.(string))
errorexit()
}
if f.U.Sval == "unsafe" {
if f.U.(string) == "unsafe" {
if safemode != 0 {
Yyerror("cannot import package unsafe")
errorexit()
}
importpkg = mkpkg(f.U.Sval)
importpkg = mkpkg(f.U.(string))
cannedimports("unsafe.6", unsafeimport)
imported_unsafe = 1
return
}
path_ := f.U.Sval
path_ := f.U.(string)
if islocalname(path_) {
if path_[0] == '/' {
Yyerror("import path cannot be absolute path")
......@@ -710,7 +710,7 @@ func importfile(f *Val, line int) {
file, found := findpkg(path_)
if !found {
Yyerror("can't find import: %q", f.U.Sval)
Yyerror("can't find import: %q", f.U.(string))
errorexit()
}
......@@ -735,7 +735,7 @@ func importfile(f *Val, line int) {
var imp *obj.Biobuf
imp, err = obj.Bopenr(file)
if err != nil {
Yyerror("can't open import: %q: %v", f.U.Sval, err)
Yyerror("can't open import: %q: %v", f.U.(string), err)
errorexit()
}
......@@ -798,7 +798,7 @@ func importfile(f *Val, line int) {
return
}
Yyerror("no import in %q", f.U.Sval)
Yyerror("no import in %q", f.U.(string))
unimportfile()
}
......@@ -1066,8 +1066,8 @@ l0:
ungetc(int(v))
}
yylval.val.U.Xval = new(Mpint)
Mpmovecfix(yylval.val.U.Xval, v)
yylval.val.U = new(Mpint)
Mpmovecfix(yylval.val.U.(*Mpint), v)
yylval.val.Ctype = CTRUNE
if Debug['x'] != 0 {
fmt.Printf("lex: codepoint literal\n")
......@@ -1405,11 +1405,11 @@ ncu:
ungetc(c)
str = lexbuf.String()
yylval.val.U.Xval = new(Mpint)
mpatofix(yylval.val.U.Xval, str)
if yylval.val.U.Xval.Ovf {
yylval.val.U = new(Mpint)
mpatofix(yylval.val.U.(*Mpint), str)
if yylval.val.U.(*Mpint).Ovf {
Yyerror("overflow in constant")
Mpmovecfix(yylval.val.U.Xval, 0)
Mpmovecfix(yylval.val.U.(*Mpint), 0)
}
yylval.val.Ctype = CTINT
......@@ -1461,12 +1461,12 @@ casei:
cp = nil
str = lexbuf.String()
yylval.val.U.Cval = new(Mpcplx)
Mpmovecflt(&yylval.val.U.Cval.Real, 0.0)
mpatoflt(&yylval.val.U.Cval.Imag, str)
if yylval.val.U.Cval.Imag.Val.IsInf() {
yylval.val.U = new(Mpcplx)
Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0)
mpatoflt(&yylval.val.U.(*Mpcplx).Imag, str)
if yylval.val.U.(*Mpcplx).Imag.Val.IsInf() {
Yyerror("overflow in imaginary constant")
Mpmovecflt(&yylval.val.U.Cval.Real, 0.0)
Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0)
}
yylval.val.Ctype = CTCPLX
......@@ -1481,11 +1481,11 @@ caseout:
ungetc(c)
str = lexbuf.String()
yylval.val.U.Fval = newMpflt()
mpatoflt(yylval.val.U.Fval, str)
if yylval.val.U.Fval.Val.IsInf() {
yylval.val.U = newMpflt()
mpatoflt(yylval.val.U.(*Mpflt), str)
if yylval.val.U.(*Mpflt).Val.IsInf() {
Yyerror("overflow in float constant")
Mpmovecflt(yylval.val.U.Fval, 0.0)
Mpmovecflt(yylval.val.U.(*Mpflt), 0.0)
}
yylval.val.Ctype = CTFLT
......@@ -1496,7 +1496,7 @@ caseout:
return LLITERAL
strlit:
yylval.val.U.Sval = internString(cp.Bytes())
yylval.val.U = internString(cp.Bytes())
yylval.val.Ctype = CTSTR
if Debug['x'] != 0 {
fmt.Printf("lex: string literal\n")
......
......@@ -382,11 +382,11 @@ func gdata(nam *Node, nr *Node, wid int) {
if nr.Op == OLITERAL {
switch nr.Val.Ctype {
case CTCPLX:
gdatacomplex(nam, nr.Val.U.Cval)
gdatacomplex(nam, nr.Val.U.(*Mpcplx))
return
case CTSTR:
gdatastring(nam, nr.Val.U.Sval)
gdatastring(nam, nr.Val.U.(string))
return
}
}
......
......@@ -995,7 +995,7 @@ func orderexpr(np **Node, order *Order, lhs *Node) {
haslit := false
for l := n.List; l != nil; l = l.Next {
hasbyte = hasbyte || l.N.Op == OARRAYBYTESTR
haslit = haslit || l.N.Op == OLITERAL && len(l.N.Val.U.Sval) != 0
haslit = haslit || l.N.Op == OLITERAL && len(l.N.Val.U.(string)) != 0
}
if haslit && hasbyte {
......
......@@ -437,7 +437,7 @@ func staticassign(l *Node, r *Node, out **NodeList) bool {
case OSTRARRAYBYTE:
if l.Class == PEXTERN && r.Left.Op == OLITERAL {
sval := r.Left.Val.U.Sval
sval := r.Left.Val.U.(string)
slicebytes(l, sval, len(sval))
return true
}
......@@ -449,7 +449,7 @@ func staticassign(l *Node, r *Node, out **NodeList) bool {
ta := typ(TARRAY)
ta.Type = r.Type.Type
ta.Bound = Mpgetfix(r.Right.Val.U.Xval)
ta.Bound = Mpgetfix(r.Right.Val.U.(*Mpint))
a := staticname(ta, 1)
r.Nname = a
n1 = *l
......@@ -722,7 +722,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init **NodeList) {
// make an array type
t := shallow(n.Type)
t.Bound = Mpgetfix(n.Right.Val.U.Xval)
t.Bound = Mpgetfix(n.Right.Val.U.(*Mpint))
t.Width = 0
t.Sym = nil
t.Haspointers = 0
......@@ -1226,7 +1226,7 @@ func oaslit(n *Node, init **NodeList) bool {
func getlit(lit *Node) int {
if Smallintconst(lit) {
return int(Mpgetfix(lit.Val.U.Xval))
return int(Mpgetfix(lit.Val.U.(*Mpint)))
}
return -1
}
......@@ -1290,7 +1290,7 @@ func initplan(n *Node) {
if a.Op != OKEY || !Smallintconst(a.Left) {
Fatal("initplan arraylit")
}
addvalue(p, n.Type.Type.Width*Mpgetfix(a.Left.Val.U.Xval), nil, a.Right)
addvalue(p, n.Type.Type.Width*Mpgetfix(a.Left.Val.U.(*Mpint)), nil, a.Right)
}
case OSTRUCTLIT:
......@@ -1360,19 +1360,19 @@ func iszero(n *Node) bool {
return true
case CTSTR:
return n.Val.U.Sval == ""
return n.Val.U.(string) == ""
case CTBOOL:
return !n.Val.U.Bval
return !n.Val.U.(bool)
case CTINT, CTRUNE:
return mpcmpfixc(n.Val.U.Xval, 0) == 0
return mpcmpfixc(n.Val.U.(*Mpint), 0) == 0
case CTFLT:
return mpcmpfltc(n.Val.U.Fval, 0) == 0
return mpcmpfltc(n.Val.U.(*Mpflt), 0) == 0
case CTCPLX:
return mpcmpfltc(&n.Val.U.Cval.Real, 0) == 0 && mpcmpfltc(&n.Val.U.Cval.Imag, 0) == 0
return mpcmpfltc(&n.Val.U.(*Mpcplx).Real, 0) == 0 && mpcmpfltc(&n.Val.U.(*Mpcplx).Imag, 0) == 0
}
case OARRAYLIT:
......@@ -1510,10 +1510,10 @@ func gen_as_init(n *Node) bool {
gdata(&nam, nr, int(nr.Type.Width))
case TCOMPLEX64, TCOMPLEX128:
gdatacomplex(&nam, nr.Val.U.Cval)
gdatacomplex(&nam, nr.Val.U.(*Mpcplx))
case TSTRING:
gdatastring(&nam, nr.Val.U.Sval)
gdatastring(&nam, nr.Val.U.(string))
}
return true
......
......@@ -666,8 +666,8 @@ func sortinter(t *Type) *Type {
func Nodintconst(v int64) *Node {
c := Nod(OLITERAL, nil, nil)
c.Addable = true
c.Val.U.Xval = new(Mpint)
Mpmovecfix(c.Val.U.Xval, v)
c.Val.U = new(Mpint)
Mpmovecfix(c.Val.U.(*Mpint), v)
c.Val.Ctype = CTINT
c.Type = Types[TIDEAL]
ullmancalc(c)
......@@ -677,8 +677,8 @@ func Nodintconst(v int64) *Node {
func nodfltconst(v *Mpflt) *Node {
c := Nod(OLITERAL, nil, nil)
c.Addable = true
c.Val.U.Fval = newMpflt()
mpmovefltflt(c.Val.U.Fval, v)
c.Val.U = newMpflt()
mpmovefltflt(c.Val.U.(*Mpflt), v)
c.Val.Ctype = CTFLT
c.Type = Types[TIDEAL]
ullmancalc(c)
......@@ -690,8 +690,8 @@ func Nodconst(n *Node, t *Type, v int64) {
n.Op = OLITERAL
n.Addable = true
ullmancalc(n)
n.Val.U.Xval = new(Mpint)
Mpmovecfix(n.Val.U.Xval, v)
n.Val.U = new(Mpint)
Mpmovecfix(n.Val.U.(*Mpint), v)
n.Val.Ctype = CTINT
n.Type = t
......@@ -710,7 +710,7 @@ func nodnil() *Node {
func Nodbool(b bool) *Node {
c := Nodintconst(0)
c.Val.Ctype = CTBOOL
c.Val.U.Bval = b
c.Val.U = b
c.Type = idealbool
return c
}
......@@ -724,7 +724,7 @@ func aindex(b *Node, t *Type) *Type {
Yyerror("array bound must be an integer expression")
case CTINT, CTRUNE:
bound = Mpgetfix(b.Val.U.Xval)
bound = Mpgetfix(b.Val.U.(*Mpint))
if bound < 0 {
Yyerror("array bound must be non negative")
}
......@@ -2422,11 +2422,11 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
var v Val
v.Ctype = CTSTR
v.U.Sval = rcvr.Type.Sym.Pkg.Name // package name
v.U = rcvr.Type.Sym.Pkg.Name // package name
l = list(l, nodlit(v))
v.U.Sval = rcvr.Type.Sym.Name // type name
v.U = rcvr.Type.Sym.Name // type name
l = list(l, nodlit(v))
v.U.Sval = method.Sym.Name
v.U = method.Sym.Name
l = list(l, nodlit(v)) // method name
call := Nod(OCALL, syslook("panicwrap", 0), nil)
call.List = l
......@@ -3139,7 +3139,7 @@ func powtwo(n *Node) int {
return -1
}
v := uint64(Mpgetfix(n.Val.U.Xval))
v := uint64(Mpgetfix(n.Val.U.(*Mpint)))
b := uint64(1)
for i := 0; i < 64; i++ {
if b == v {
......
......@@ -218,7 +218,7 @@ func (s *exprSwitch) walk(sw *Node) {
s.kind = switchKindExpr
if Isconst(sw.Ntest, CTBOOL) {
s.kind = switchKindTrue
if !sw.Ntest.Val.U.Bval {
if !sw.Ntest.Val.U.(bool) {
s.kind = switchKindFalse
}
}
......@@ -755,16 +755,16 @@ func exprcmp(c1, c2 *caseClause) int {
// sort by constant value to enable binary search
switch ct {
case CTFLT:
return mpcmpfltflt(n1.Val.U.Fval, n2.Val.U.Fval)
return mpcmpfltflt(n1.Val.U.(*Mpflt), n2.Val.U.(*Mpflt))
case CTINT, CTRUNE:
return Mpcmpfixfix(n1.Val.U.Xval, n2.Val.U.Xval)
return Mpcmpfixfix(n1.Val.U.(*Mpint), n2.Val.U.(*Mpint))
case CTSTR:
// Sort strings by length and then by value.
// It is much cheaper to compare lengths than values,
// and all we need here is consistency.
// We respect this sorting in exprSwitch.walkCases.
a := n1.Val.U.Sval
b := n2.Val.U.Sval
a := n1.Val.U.(string)
b := n2.Val.U.(string)
if len(a) < len(b) {
return -1
}
......
......@@ -392,7 +392,7 @@ OpSwitch:
return
}
t.Bound = Mpgetfix(v.U.Xval)
t.Bound = Mpgetfix(v.U.(*Mpint))
if doesoverflow(v, Types[TINT]) {
Yyerror("array bound is too large")
n.Type = nil
......@@ -770,7 +770,7 @@ OpSwitch:
}
if (op == ODIV || op == OMOD) && Isconst(r, CTINT) {
if mpcmpfixc(r.Val.U.Xval, 0) == 0 {
if mpcmpfixc(r.Val.U.(*Mpint), 0) == 0 {
Yyerror("division by zero")
n.Type = nil
return
......@@ -1043,14 +1043,14 @@ OpSwitch:
}
if Isconst(n.Right, CTINT) {
x := Mpgetfix(n.Right.Val.U.Xval)
x := Mpgetfix(n.Right.Val.U.(*Mpint))
if x < 0 {
Yyerror("invalid %s index %v (index must be non-negative)", why, n.Right)
} else if Isfixedarray(t) && t.Bound > 0 && x >= t.Bound {
Yyerror("invalid array index %v (out of bounds for %d-element array)", n.Right, t.Bound)
} else if Isconst(n.Left, CTSTR) && x >= int64(len(n.Left.Val.U.Sval)) {
Yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(n.Left.Val.U.Sval))
} else if Mpcmpfixfix(n.Right.Val.U.Xval, Maxintval[TINT]) > 0 {
} else if Isconst(n.Left, CTSTR) && x >= int64(len(n.Left.Val.U.(string))) {
Yyerror("invalid string index %v (out of bounds for %d-byte string)", n.Right, len(n.Left.Val.U.(string)))
} else if Mpcmpfixfix(n.Right.Val.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("invalid %s index %v (index too large)", why, n.Right)
}
}
......@@ -1435,9 +1435,9 @@ OpSwitch:
if Isconst(l, CTCPLX) {
r := n
if n.Op == OREAL {
n = nodfltconst(&l.Val.U.Cval.Real)
n = nodfltconst(&l.Val.U.(*Mpcplx).Real)
} else {
n = nodfltconst(&l.Val.U.Cval.Imag)
n = nodfltconst(&l.Val.U.(*Mpcplx).Imag)
}
n.Orig = r
}
......@@ -1451,7 +1451,7 @@ OpSwitch:
case TSTRING:
if Isconst(l, CTSTR) {
r := Nod(OXXX, nil, nil)
Nodconst(r, Types[TINT], int64(len(l.Val.U.Sval)))
Nodconst(r, Types[TINT], int64(len(l.Val.U.(string))))
r.Orig = n
n = r
}
......@@ -1859,7 +1859,7 @@ OpSwitch:
n.Type = nil
return
}
if Isconst(l, CTINT) && r != nil && Isconst(r, CTINT) && Mpcmpfixfix(l.Val.U.Xval, r.Val.U.Xval) > 0 {
if Isconst(l, CTINT) && r != nil && Isconst(r, CTINT) && Mpcmpfixfix(l.Val.U.(*Mpint), r.Val.U.(*Mpint)) > 0 {
Yyerror("len larger than cap in make(%v)", t)
n.Type = nil
return
......@@ -2255,16 +2255,16 @@ func checksliceindex(l *Node, r *Node, tp *Type) int {
}
if r.Op == OLITERAL {
if Mpgetfix(r.Val.U.Xval) < 0 {
if Mpgetfix(r.Val.U.(*Mpint)) < 0 {
Yyerror("invalid slice index %v (index must be non-negative)", r)
return -1
} else if tp != nil && tp.Bound > 0 && Mpgetfix(r.Val.U.Xval) > tp.Bound {
} else if tp != nil && tp.Bound > 0 && Mpgetfix(r.Val.U.(*Mpint)) > tp.Bound {
Yyerror("invalid slice index %v (out of bounds for %d-element array)", r, tp.Bound)
return -1
} else if Isconst(l, CTSTR) && Mpgetfix(r.Val.U.Xval) > int64(len(l.Val.U.Sval)) {
Yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val.U.Sval))
} else if Isconst(l, CTSTR) && Mpgetfix(r.Val.U.(*Mpint)) > int64(len(l.Val.U.(string))) {
Yyerror("invalid slice index %v (out of bounds for %d-byte string)", r, len(l.Val.U.(string)))
return -1
} else if Mpcmpfixfix(r.Val.U.Xval, Maxintval[TINT]) > 0 {
} else if Mpcmpfixfix(r.Val.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("invalid slice index %v (index too large)", r)
return -1
}
......@@ -2274,7 +2274,7 @@ func checksliceindex(l *Node, r *Node, tp *Type) int {
}
func checksliceconst(lo *Node, hi *Node) int {
if lo != nil && hi != nil && lo.Op == OLITERAL && hi.Op == OLITERAL && Mpcmpfixfix(lo.Val.U.Xval, hi.Val.U.Xval) > 0 {
if lo != nil && hi != nil && lo.Op == OLITERAL && hi.Op == OLITERAL && Mpcmpfixfix(lo.Val.U.(*Mpint), hi.Val.U.(*Mpint)) > 0 {
Yyerror("invalid slice index: %v > %v", lo, hi)
return -1
}
......@@ -2824,10 +2824,10 @@ func keydup(n *Node, hash []*Node) {
b = 23
case CTINT, CTRUNE:
b = uint32(Mpgetfix(n.Val.U.Xval))
b = uint32(Mpgetfix(n.Val.U.(*Mpint)))
case CTFLT:
d := mpgetflt(n.Val.U.Fval)
d := mpgetflt(n.Val.U.(*Mpflt))
x := math.Float64bits(d)
for i := 0; i < 8; i++ {
b = b*PRIME1 + uint32(x&0xFF)
......@@ -2836,8 +2836,8 @@ func keydup(n *Node, hash []*Node) {
case CTSTR:
b = 0
s := n.Val.U.Sval
for i := len(n.Val.U.Sval); i > 0; i-- {
s := n.Val.U.(string)
for i := len(n.Val.U.(string)); i > 0; i-- {
b = b*PRIME1 + uint32(s[0])
s = s[1:]
}
......@@ -2853,12 +2853,12 @@ func keydup(n *Node, hash []*Node) {
if Eqtype(a.Left.Type, n.Type) {
cmp.Right = a.Left
evconst(&cmp)
b = uint32(obj.Bool2int(cmp.Val.U.Bval))
b = uint32(obj.Bool2int(cmp.Val.U.(bool)))
}
} else if Eqtype(a.Type, n.Type) {
cmp.Right = a
evconst(&cmp)
b = uint32(obj.Bool2int(cmp.Val.U.Bval))
b = uint32(obj.Bool2int(cmp.Val.U.(bool)))
}
if b != 0 {
......@@ -2876,11 +2876,11 @@ func indexdup(n *Node, hash []*Node) {
Fatal("indexdup: not OLITERAL")
}
b := uint32(Mpgetfix(n.Val.U.Xval))
b := uint32(Mpgetfix(n.Val.U.(*Mpint)))
h := uint(b % uint32(len(hash)))
var c uint32
for a := hash[h]; a != nil; a = a.Ntest {
c = uint32(Mpgetfix(a.Val.U.Xval))
c = uint32(Mpgetfix(a.Val.U.(*Mpint)))
if b == c {
Yyerror("duplicate index in array literal: %d", b)
return
......@@ -3529,7 +3529,7 @@ func stringtoarraylit(np **Node) {
Fatal("stringtoarraylit %v", n)
}
s := n.Left.Val.U.Sval
s := n.Left.Val.U.(string)
var l *NodeList
if n.Type.Type.Etype == TUINT8 {
// []byte
......@@ -3886,12 +3886,12 @@ func checkmake(t *Type, arg string, n *Node) int {
switch n.Val.Ctype {
case CTINT, CTRUNE, CTFLT, CTCPLX:
n.Val = toint(n.Val)
if mpcmpfixc(n.Val.U.Xval, 0) < 0 {
if mpcmpfixc(n.Val.U.(*Mpint), 0) < 0 {
Yyerror("negative %s argument in make(%v)", arg, t)
return -1
}
if Mpcmpfixfix(n.Val.U.Xval, Maxintval[TINT]) > 0 {
if Mpcmpfixfix(n.Val.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("%s argument too large in make(%v)", arg, t)
return -1
}
......
......@@ -140,8 +140,8 @@ ret:
var val Val
val.Ctype = CTINT
val.U.Xval = new(Mpint)
Mpmovecfix(val.U.Xval, v)
val.U = new(Mpint)
Mpmovecfix(val.U.(*Mpint), v)
n := Nod(OLITERAL, nil, nil)
n.Orig = nn
n.Val = val
......
......@@ -1206,7 +1206,7 @@ func walkexpr(np **Node, init **NodeList) {
Yyerror("index out of bounds")
}
} else if Isconst(n.Left, CTSTR) {
n.Bounded = bounded(r, int64(len(n.Left.Val.U.Sval)))
n.Bounded = bounded(r, int64(len(n.Left.Val.U.(string))))
if Debug['m'] != 0 && n.Bounded && !Isconst(n.Right, CTINT) {
Warn("index bounds check elided")
}
......@@ -1217,16 +1217,16 @@ func walkexpr(np **Node, init **NodeList) {
// replace "abc"[1] with 'b'.
// delayed until now because "abc"[1] is not
// an ideal constant.
v := Mpgetfix(n.Right.Val.U.Xval)
v := Mpgetfix(n.Right.Val.U.(*Mpint))
Nodconst(n, n.Type, int64(n.Left.Val.U.Sval[v]))
Nodconst(n, n.Type, int64(n.Left.Val.U.(string)[v]))
n.Typecheck = 1
}
}
}
if Isconst(n.Right, CTINT) {
if Mpcmpfixfix(n.Right.Val.U.Xval, &mpzero) < 0 || Mpcmpfixfix(n.Right.Val.U.Xval, Maxintval[TINT]) > 0 {
if Mpcmpfixfix(n.Right.Val.U.(*Mpint), &mpzero) < 0 || Mpcmpfixfix(n.Right.Val.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("index out of bounds")
}
}
......@@ -1338,7 +1338,7 @@ func walkexpr(np **Node, init **NodeList) {
// comparing the lengths instead will yield the same result
// without the function call.
case OCMPSTR:
if (Isconst(n.Left, CTSTR) && len(n.Left.Val.U.Sval) == 0) || (Isconst(n.Right, CTSTR) && len(n.Right.Val.U.Sval) == 0) {
if (Isconst(n.Left, CTSTR) && len(n.Left.Val.U.(string)) == 0) || (Isconst(n.Right, CTSTR) && len(n.Right.Val.U.(string)) == 0) {
r := Nod(int(n.Etype), Nod(OLEN, n.Left, nil), Nod(OLEN, n.Right, nil))
typecheck(&r, Erv)
walkexpr(&r, init)
......@@ -1458,7 +1458,7 @@ func walkexpr(np **Node, init **NodeList) {
l = r
}
t := n.Type
if n.Esc == EscNone && Smallintconst(l) && Smallintconst(r) && (t.Type.Width == 0 || Mpgetfix(r.Val.U.Xval) < (1<<16)/t.Type.Width) {
if n.Esc == EscNone && Smallintconst(l) && Smallintconst(r) && (t.Type.Width == 0 || Mpgetfix(r.Val.U.(*Mpint)) < (1<<16)/t.Type.Width) {
// var arr [r]T
// n = arr[:l]
t = aindex(r, t.Type) // [r]T
......@@ -2862,7 +2862,7 @@ func addstr(n *Node, init **NodeList) *Node {
sz := int64(0)
for l := n.List; l != nil; l = l.Next {
if n.Op == OLITERAL {
sz += int64(len(n.Val.U.Sval))
sz += int64(len(n.Val.U.(string)))
}
}
......@@ -3415,7 +3415,7 @@ func samecheap(a *Node, b *Node) bool {
case OINDEX:
ar = a.Right
br = b.Right
if !Isconst(ar, CTINT) || !Isconst(br, CTINT) || Mpcmpfixfix(ar.Val.U.Xval, br.Val.U.Xval) != 0 {
if !Isconst(ar, CTINT) || !Isconst(br, CTINT) || Mpcmpfixfix(ar.Val.U.(*Mpint), br.Val.U.(*Mpint)) != 0 {
return false
}
}
......@@ -3451,9 +3451,9 @@ func walkrotate(np **Node) {
w := int(l.Type.Width * 8)
if Smallintconst(l.Right) && Smallintconst(r.Right) {
sl := int(Mpgetfix(l.Right.Val.U.Xval))
sl := int(Mpgetfix(l.Right.Val.U.(*Mpint)))
if sl >= 0 {
sr := int(Mpgetfix(r.Right.Val.U.Xval))
sr := int(Mpgetfix(r.Right.Val.U.(*Mpint)))
if sr >= 0 && sl+sr == w {
// Rewrite left shift half to left rotate.
if l.Op == OLSH {
......@@ -3464,7 +3464,7 @@ func walkrotate(np **Node) {
n.Op = OLROT
// Remove rotate 0 and rotate w.
s := int(Mpgetfix(n.Right.Val.U.Xval))
s := int(Mpgetfix(n.Right.Val.U.(*Mpint)))
if s == 0 || s == w {
n = n.Left
......@@ -3507,7 +3507,7 @@ func walkmul(np **Node, init **NodeList) {
// x*0 is 0 (and side effects of x).
var pow int
var w int
if Mpgetfix(nr.Val.U.Xval) == 0 {
if Mpgetfix(nr.Val.U.(*Mpint)) == 0 {
cheapexpr(nl, init)
Nodconst(n, n.Type, 0)
goto ret
......@@ -3600,10 +3600,10 @@ func walkdiv(np **Node, init **NodeList) {
m.W = w
if Issigned[nl.Type.Etype] {
m.Sd = Mpgetfix(nr.Val.U.Xval)
m.Sd = Mpgetfix(nr.Val.U.(*Mpint))
Smagic(&m)
} else {
m.Ud = uint64(Mpgetfix(nr.Val.U.Xval))
m.Ud = uint64(Mpgetfix(nr.Val.U.(*Mpint)))
Umagic(&m)
}
......@@ -3797,7 +3797,7 @@ func walkdiv(np **Node, init **NodeList) {
// n = nl & (nr-1)
n.Op = OAND
Nodconst(nc, nl.Type, Mpgetfix(nr.Val.U.Xval)-1)
Nodconst(nc, nl.Type, Mpgetfix(nr.Val.U.(*Mpint))-1)
} else {
// n = nl >> pow
n.Op = ORSH
......@@ -3827,7 +3827,7 @@ func bounded(n *Node, max int64) bool {
bits := int32(8 * n.Type.Width)
if Smallintconst(n) {
v := Mpgetfix(n.Val.U.Xval)
v := Mpgetfix(n.Val.U.(*Mpint))
return 0 <= v && v < max
}
......@@ -3835,9 +3835,9 @@ func bounded(n *Node, max int64) bool {
case OAND:
v := int64(-1)
if Smallintconst(n.Left) {
v = Mpgetfix(n.Left.Val.U.Xval)
v = Mpgetfix(n.Left.Val.U.(*Mpint))
} else if Smallintconst(n.Right) {
v = Mpgetfix(n.Right.Val.U.Xval)
v = Mpgetfix(n.Right.Val.U.(*Mpint))
}
if 0 <= v && v < max {
......@@ -3846,7 +3846,7 @@ func bounded(n *Node, max int64) bool {
case OMOD:
if !sign && Smallintconst(n.Right) {
v := Mpgetfix(n.Right.Val.U.Xval)
v := Mpgetfix(n.Right.Val.U.(*Mpint))
if 0 <= v && v <= max {
return true
}
......@@ -3854,7 +3854,7 @@ func bounded(n *Node, max int64) bool {
case ODIV:
if !sign && Smallintconst(n.Right) {
v := Mpgetfix(n.Right.Val.U.Xval)
v := Mpgetfix(n.Right.Val.U.(*Mpint))
for bits > 0 && v >= 2 {
bits--
v >>= 1
......@@ -3863,7 +3863,7 @@ func bounded(n *Node, max int64) bool {
case ORSH:
if !sign && Smallintconst(n.Right) {
v := Mpgetfix(n.Right.Val.U.Xval)
v := Mpgetfix(n.Right.Val.U.(*Mpint))
if v > int64(bits) {
return true
}
......@@ -3996,17 +3996,17 @@ func candiscard(n *Node) bool {
// Discardable as long as we know it's not division by zero.
case ODIV, OMOD:
if Isconst(n.Right, CTINT) && mpcmpfixc(n.Right.Val.U.Xval, 0) != 0 {
if Isconst(n.Right, CTINT) && mpcmpfixc(n.Right.Val.U.(*Mpint), 0) != 0 {
break
}
if Isconst(n.Right, CTFLT) && mpcmpfltc(n.Right.Val.U.Fval, 0) != 0 {
if Isconst(n.Right, CTFLT) && mpcmpfltc(n.Right.Val.U.(*Mpflt), 0) != 0 {
break
}
return false
// Discardable as long as we know it won't fail because of a bad size.
case OMAKECHAN, OMAKEMAP:
if Isconst(n.Left, CTINT) && mpcmpfixc(n.Left.Val.U.Xval, 0) == 0 {
if Isconst(n.Left, CTINT) && mpcmpfixc(n.Left.Val.U.(*Mpint), 0) == 0 {
break
}
return false
......
......@@ -2327,13 +2327,13 @@ yydefault:
{
var p *Pkg
if yyDollar[2].val.U.Sval == "" {
if yyDollar[2].val.U.(string) == "" {
p = importpkg
} else {
if isbadimport(yyDollar[2].val.U.Sval) {
if isbadimport(yyDollar[2].val.U.(string)) {
errorexit()
}
p = mkpkg(yyDollar[2].val.U.Sval)
p = mkpkg(yyDollar[2].val.U.(string))
}
yyVAL.sym = Pkglookup(yyDollar[4].sym.Name, p)
}
......@@ -2343,13 +2343,13 @@ yydefault:
{
var p *Pkg
if yyDollar[2].val.U.Sval == "" {
if yyDollar[2].val.U.(string) == "" {
p = importpkg
} else {
if isbadimport(yyDollar[2].val.U.Sval) {
if isbadimport(yyDollar[2].val.U.(string)) {
errorexit()
}
p = mkpkg(yyDollar[2].val.U.Sval)
p = mkpkg(yyDollar[2].val.U.(string))
}
yyVAL.sym = Pkglookup("?", p)
}
......@@ -3156,7 +3156,7 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1]
//line go.y:1947
{
importimport(yyDollar[2].sym, yyDollar[3].val.U.Sval)
importimport(yyDollar[2].sym, yyDollar[3].val.U.(string))
}
case 305:
yyDollar = yyS[yypt-4 : yypt+1]
......@@ -3404,14 +3404,14 @@ yydefault:
yyVAL.node = nodlit(yyDollar[2].val)
switch yyVAL.node.Val.Ctype {
case CTINT, CTRUNE:
mpnegfix(yyVAL.node.Val.U.Xval)
mpnegfix(yyVAL.node.Val.U.(*Mpint))
break
case CTFLT:
mpnegflt(yyVAL.node.Val.U.Fval)
mpnegflt(yyVAL.node.Val.U.(*Mpflt))
break
case CTCPLX:
mpnegflt(&yyVAL.node.Val.U.Cval.Real)
mpnegflt(&yyVAL.node.Val.U.Cval.Imag)
mpnegflt(&yyVAL.node.Val.U.(*Mpcplx).Real)
mpnegflt(&yyVAL.node.Val.U.(*Mpcplx).Imag)
break
default:
Yyerror("bad negated constant")
......@@ -3432,11 +3432,11 @@ yydefault:
{
if yyDollar[2].node.Val.Ctype == CTRUNE && yyDollar[4].node.Val.Ctype == CTINT {
yyVAL.node = yyDollar[2].node
mpaddfixfix(yyDollar[2].node.Val.U.Xval, yyDollar[4].node.Val.U.Xval, 0)
mpaddfixfix(yyDollar[2].node.Val.U.(*Mpint), yyDollar[4].node.Val.U.(*Mpint), 0)
break
}
yyDollar[4].node.Val.U.Cval.Real = yyDollar[4].node.Val.U.Cval.Imag
Mpmovecflt(&yyDollar[4].node.Val.U.Cval.Imag, 0.0)
yyDollar[4].node.Val.U.(*Mpcplx).Real = yyDollar[4].node.Val.U.(*Mpcplx).Imag
Mpmovecflt(&yyDollar[4].node.Val.U.(*Mpcplx).Imag, 0.0)
yyVAL.node = nodcplxlit(yyDollar[2].node.Val, yyDollar[4].node.Val)
}
case 346:
......
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