Commit 71080fbb authored by Russ Cox's avatar Russ Cox

cmd/compile: remove Val.Ctype

$ sizeof -p cmd/compile/internal/gc Node
Node 248
$

Change-Id: I0fbfeb0d0b36e225eb282fce9e480a96ec1d278f
Reviewed-on: https://go-review.googlesource.com/10524Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 4fdd5368
...@@ -56,7 +56,6 @@ func truncfltlit(oldv *Mpflt, t *Type) *Mpflt { ...@@ -56,7 +56,6 @@ func truncfltlit(oldv *Mpflt, t *Type) *Mpflt {
} }
var v Val var v Val
v.Ctype = CTFLT
v.U = oldv v.U = oldv
overflow(v, t) overflow(v, t)
...@@ -136,7 +135,7 @@ func convlit1(np **Node, t *Type, explicit bool) { ...@@ -136,7 +135,7 @@ func convlit1(np **Node, t *Type, explicit bool) {
case OLSH, ORSH: case OLSH, ORSH:
convlit1(&n.Left, t, explicit && isideal(n.Left.Type)) convlit1(&n.Left, t, explicit && isideal(n.Left.Type))
t = n.Left.Type t = n.Left.Type
if t != nil && t.Etype == TIDEAL && n.Val.Ctype != CTINT { if t != nil && t.Etype == TIDEAL && n.Val.Ctype() != CTINT {
n.Val = toint(n.Val) n.Val = toint(n.Val)
} }
if t != nil && !Isint[t.Etype] { if t != nil && !Isint[t.Etype] {
...@@ -229,7 +228,6 @@ func convlit1(np **Node, t *Type, explicit bool) { ...@@ -229,7 +228,6 @@ func convlit1(np **Node, t *Type, explicit bool) {
if n.Type.Etype == TUNSAFEPTR { if n.Type.Etype == TUNSAFEPTR {
n.Val.U = new(Mpint) n.Val.U = new(Mpint)
Mpmovecfix(n.Val.U.(*Mpint), 0) Mpmovecfix(n.Val.U.(*Mpint), 0)
n.Val.Ctype = CTINT
} else { } else {
goto bad goto bad
} }
...@@ -244,7 +242,7 @@ func convlit1(np **Node, t *Type, explicit bool) { ...@@ -244,7 +242,7 @@ func convlit1(np **Node, t *Type, explicit bool) {
if n.Type.Etype == TUNSAFEPTR && t.Etype != TUINTPTR { if n.Type.Etype == TUNSAFEPTR && t.Etype != TUINTPTR {
goto bad goto bad
} }
ct := int(n.Val.Ctype) ct := int(n.Val.Ctype())
if Isint[et] { if Isint[et] {
switch ct { switch ct {
default: default:
...@@ -307,10 +305,11 @@ bad: ...@@ -307,10 +305,11 @@ bad:
} }
func copyval(v Val) Val { func copyval(v Val) Val {
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
i := new(Mpint) i := new(Mpint)
mpmovefixfix(i, v.U.(*Mpint)) mpmovefixfix(i, v.U.(*Mpint))
i.Rune = v.U.(*Mpint).Rune
v.U = i v.U = i
case CTFLT: case CTFLT:
...@@ -329,19 +328,17 @@ func copyval(v Val) Val { ...@@ -329,19 +328,17 @@ func copyval(v Val) Val {
} }
func tocplx(v Val) Val { func tocplx(v Val) Val {
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
c := new(Mpcplx) c := new(Mpcplx)
Mpmovefixflt(&c.Real, v.U.(*Mpint)) Mpmovefixflt(&c.Real, v.U.(*Mpint))
Mpmovecflt(&c.Imag, 0.0) Mpmovecflt(&c.Imag, 0.0)
v.Ctype = CTCPLX
v.U = c v.U = c
case CTFLT: case CTFLT:
c := new(Mpcplx) c := new(Mpcplx)
mpmovefltflt(&c.Real, v.U.(*Mpflt)) mpmovefltflt(&c.Real, v.U.(*Mpflt))
Mpmovecflt(&c.Imag, 0.0) Mpmovecflt(&c.Imag, 0.0)
v.Ctype = CTCPLX
v.U = c v.U = c
} }
...@@ -349,11 +346,10 @@ func tocplx(v Val) Val { ...@@ -349,11 +346,10 @@ func tocplx(v Val) Val {
} }
func toflt(v Val) Val { func toflt(v Val) Val {
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
f := newMpflt() f := newMpflt()
Mpmovefixflt(f, v.U.(*Mpint)) Mpmovefixflt(f, v.U.(*Mpint))
v.Ctype = CTFLT
v.U = f v.U = f
case CTCPLX: case CTCPLX:
...@@ -362,7 +358,6 @@ func toflt(v Val) Val { ...@@ -362,7 +358,6 @@ func toflt(v Val) Val {
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 { if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 {
Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign)) Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign))
} }
v.Ctype = CTFLT
v.U = f v.U = f
} }
...@@ -370,16 +365,17 @@ func toflt(v Val) Val { ...@@ -370,16 +365,17 @@ func toflt(v Val) Val {
} }
func toint(v Val) Val { func toint(v Val) Val {
switch v.Ctype { switch v.Ctype() {
case CTRUNE: case CTRUNE:
v.Ctype = CTINT i := new(Mpint)
mpmovefixfix(i, v.U.(*Mpint))
v.U = i
case CTFLT: case CTFLT:
i := new(Mpint) i := new(Mpint)
if mpmovefltfix(i, v.U.(*Mpflt)) < 0 { if mpmovefltfix(i, v.U.(*Mpflt)) < 0 {
Yyerror("constant %v truncated to integer", Fconv(v.U.(*Mpflt), obj.FmtSharp)) Yyerror("constant %v truncated to integer", Fconv(v.U.(*Mpflt), obj.FmtSharp))
} }
v.Ctype = CTINT
v.U = i v.U = i
case CTCPLX: case CTCPLX:
...@@ -390,7 +386,6 @@ func toint(v Val) Val { ...@@ -390,7 +386,6 @@ func toint(v Val) Val {
if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 { if mpcmpfltc(&v.U.(*Mpcplx).Imag, 0) != 0 {
Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign)) Yyerror("constant %v%vi truncated to real", Fconv(&v.U.(*Mpcplx).Real, obj.FmtSharp), Fconv(&v.U.(*Mpcplx).Imag, obj.FmtSharp|obj.FmtSign))
} }
v.Ctype = CTINT
v.U = i v.U = i
} }
...@@ -398,7 +393,7 @@ func toint(v Val) Val { ...@@ -398,7 +393,7 @@ func toint(v Val) Val {
} }
func doesoverflow(v Val, t *Type) bool { func doesoverflow(v Val, t *Type) bool {
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
if !Isint[t.Etype] { if !Isint[t.Etype] {
Fatal("overflow: %v integer constant", t) Fatal("overflow: %v integer constant", t)
...@@ -443,7 +438,7 @@ func overflow(v Val, t *Type) { ...@@ -443,7 +438,7 @@ func overflow(v Val, t *Type) {
return return
} }
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
Yyerror("constant %v overflows %v", v.U.(*Mpint), t) Yyerror("constant %v overflows %v", v.U.(*Mpint), t)
...@@ -456,14 +451,13 @@ func overflow(v Val, t *Type) { ...@@ -456,14 +451,13 @@ func overflow(v Val, t *Type) {
} }
func tostr(v Val) Val { func tostr(v Val) Val {
switch v.Ctype { switch v.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
if Mpcmpfixfix(v.U.(*Mpint), Minintval[TINT]) < 0 || Mpcmpfixfix(v.U.(*Mpint), Maxintval[TINT]) > 0 { if Mpcmpfixfix(v.U.(*Mpint), Minintval[TINT]) < 0 || Mpcmpfixfix(v.U.(*Mpint), Maxintval[TINT]) > 0 {
Yyerror("overflow in int -> string") Yyerror("overflow in int -> string")
} }
r := uint(Mpgetfix(v.U.(*Mpint))) r := uint(Mpgetfix(v.U.(*Mpint)))
v = Val{} v = Val{}
v.Ctype = CTSTR
v.U = string(r) v.U = string(r)
case CTFLT: case CTFLT:
...@@ -472,7 +466,6 @@ func tostr(v Val) Val { ...@@ -472,7 +466,6 @@ func tostr(v Val) Val {
case CTNIL: case CTNIL:
v = Val{} v = Val{}
v.Ctype = CTSTR
v.U = "" v.U = ""
} }
...@@ -483,7 +476,7 @@ func consttype(n *Node) int { ...@@ -483,7 +476,7 @@ func consttype(n *Node) int {
if n == nil || n.Op != OLITERAL { if n == nil || n.Op != OLITERAL {
return -1 return -1
} }
return int(n.Val.Ctype) return int(n.Val.Ctype())
} }
func Isconst(n *Node, ct int) bool { func Isconst(n *Node, ct int) bool {
...@@ -569,7 +562,6 @@ func evconst(n *Node) { ...@@ -569,7 +562,6 @@ func evconst(n *Node) {
nl = Nod(OXXX, nil, nil) nl = Nod(OXXX, nil, nil)
*nl = *l1.N *nl = *l1.N
nl.Orig = nl nl.Orig = nl
nl.Val.Ctype = CTSTR
nl.Val.U = strings.Join(strs, "") nl.Val.U = strings.Join(strs, "")
l1.N = nl l1.N = nl
l1.Next = l2 l1.Next = l2
...@@ -617,7 +609,7 @@ func evconst(n *Node) { ...@@ -617,7 +609,7 @@ func evconst(n *Node) {
v = copyval(v) v = copyval(v)
} }
switch uint32(n.Op)<<16 | uint32(v.Ctype) { switch uint32(n.Op)<<16 | uint32(v.Ctype()) {
default: default:
if n.Diag == 0 { if n.Diag == 0 {
Yyerror("illegal constant expression %v %v", Oconv(int(n.Op), 0), nl.Type) Yyerror("illegal constant expression %v %v", Oconv(int(n.Op), 0), nl.Type)
...@@ -743,7 +735,7 @@ func evconst(n *Node) { ...@@ -743,7 +735,7 @@ func evconst(n *Node) {
if nr.Type != nil && (Issigned[nr.Type.Etype] || !Isint[nr.Type.Etype]) { if nr.Type != nil && (Issigned[nr.Type.Etype] || !Isint[nr.Type.Etype]) {
goto illegal goto illegal
} }
if nl.Val.Ctype != CTRUNE { if nl.Val.Ctype() != CTRUNE {
nl.Val = toint(nl.Val) nl.Val = toint(nl.Val)
} }
nr.Val = toint(nr.Val) nr.Val = toint(nr.Val)
...@@ -760,38 +752,46 @@ func evconst(n *Node) { ...@@ -760,38 +752,46 @@ func evconst(n *Node) {
rv = nr.Val rv = nr.Val
// convert to common ideal // convert to common ideal
if v.Ctype == CTCPLX || rv.Ctype == CTCPLX { if v.Ctype() == CTCPLX || rv.Ctype() == CTCPLX {
v = tocplx(v) v = tocplx(v)
rv = tocplx(rv) rv = tocplx(rv)
} }
if v.Ctype == CTFLT || rv.Ctype == CTFLT { if v.Ctype() == CTFLT || rv.Ctype() == CTFLT {
v = toflt(v) v = toflt(v)
rv = toflt(rv) rv = toflt(rv)
} }
// Rune and int turns into rune. // Rune and int turns into rune.
if v.Ctype == CTRUNE && rv.Ctype == CTINT { if v.Ctype() == CTRUNE && rv.Ctype() == CTINT {
rv.Ctype = CTRUNE i := new(Mpint)
mpmovefixfix(i, rv.U.(*Mpint))
i.Rune = true
rv.U = i
} }
if v.Ctype == CTINT && rv.Ctype == CTRUNE { if v.Ctype() == CTINT && rv.Ctype() == CTRUNE {
if n.Op == OLSH || n.Op == ORSH { if n.Op == OLSH || n.Op == ORSH {
rv.Ctype = CTINT i := new(Mpint)
mpmovefixfix(i, rv.U.(*Mpint))
rv.U = i
} else { } else {
v.Ctype = CTRUNE i := new(Mpint)
mpmovefixfix(i, v.U.(*Mpint))
i.Rune = true
v.U = i
} }
} }
if v.Ctype != rv.Ctype { if v.Ctype() != rv.Ctype() {
// Use of undefined name as constant? // Use of undefined name as constant?
if (v.Ctype == 0 || rv.Ctype == 0) && nerrors > 0 { if (v.Ctype() == 0 || rv.Ctype() == 0) && nerrors > 0 {
return return
} }
Fatal("constant type mismatch %v(%d) %v(%d)", nl.Type, v.Ctype, nr.Type, rv.Ctype) Fatal("constant type mismatch %v(%d) %v(%d)", nl.Type, v.Ctype(), nr.Type, rv.Ctype())
} }
// run op // run op
switch uint32(n.Op)<<16 | uint32(v.Ctype) { switch uint32(n.Op)<<16 | uint32(v.Ctype()) {
default: default:
goto illegal goto illegal
...@@ -1075,7 +1075,7 @@ ret: ...@@ -1075,7 +1075,7 @@ ret:
lineno = int32(lno) lineno = int32(lno)
// truncate precision for non-ideal float. // truncate precision for non-ideal float.
if v.Ctype == CTFLT && n.Type.Etype != TIDEAL { if v.Ctype() == CTFLT && n.Type.Etype != TIDEAL {
n.Val.U = truncfltlit(v.U.(*Mpflt), n.Type) n.Val.U = truncfltlit(v.U.(*Mpflt), n.Type)
} }
return return
...@@ -1104,9 +1104,9 @@ illegal: ...@@ -1104,9 +1104,9 @@ illegal:
func nodlit(v Val) *Node { func nodlit(v Val) *Node {
n := Nod(OLITERAL, nil, nil) n := Nod(OLITERAL, nil, nil)
n.Val = v n.Val = v
switch v.Ctype { switch v.Ctype() {
default: default:
Fatal("nodlit ctype %d", v.Ctype) Fatal("nodlit ctype %d", v.Ctype())
case CTSTR: case CTSTR:
n.Type = idealstring n.Type = idealstring
...@@ -1132,10 +1132,9 @@ func nodcplxlit(r Val, i Val) *Node { ...@@ -1132,10 +1132,9 @@ func nodcplxlit(r Val, i Val) *Node {
n := Nod(OLITERAL, nil, nil) n := Nod(OLITERAL, nil, nil)
n.Type = Types[TIDEAL] n.Type = Types[TIDEAL]
n.Val.U = c n.Val.U = c
n.Val.Ctype = CTCPLX
if r.Ctype != CTFLT || i.Ctype != CTFLT { if r.Ctype() != CTFLT || i.Ctype() != CTFLT {
Fatal("nodcplxlit ctype %d/%d", r.Ctype, i.Ctype) Fatal("nodcplxlit ctype %d/%d", r.Ctype(), i.Ctype())
} }
mpmovefltflt(&c.Real, r.U.(*Mpflt)) mpmovefltflt(&c.Real, r.U.(*Mpflt))
...@@ -1155,7 +1154,7 @@ func idealkind(n *Node) int { ...@@ -1155,7 +1154,7 @@ func idealkind(n *Node) int {
return CTxxx return CTxxx
case OLITERAL: case OLITERAL:
return int(n.Val.Ctype) return int(n.Val.Ctype())
// numeric kinds. // numeric kinds.
case OADD, case OADD,
...@@ -1230,7 +1229,7 @@ func defaultlit(np **Node, t *Type) { ...@@ -1230,7 +1229,7 @@ func defaultlit(np **Node, t *Type) {
return return
} }
if n.Val.Ctype == CTNIL { if n.Val.Ctype() == CTNIL {
lineno = int32(lno) lineno = int32(lno)
if n.Diag == 0 { if n.Diag == 0 {
Yyerror("use of untyped nil") Yyerror("use of untyped nil")
...@@ -1241,7 +1240,7 @@ func defaultlit(np **Node, t *Type) { ...@@ -1241,7 +1240,7 @@ func defaultlit(np **Node, t *Type) {
break break
} }
if n.Val.Ctype == CTSTR { if n.Val.Ctype() == CTSTR {
t1 := Types[TSTRING] t1 := Types[TSTRING]
Convlit(np, t1) Convlit(np, t1)
break break
...@@ -1447,12 +1446,11 @@ func (n *Node) Convconst(con *Node, t *Type) { ...@@ -1447,12 +1446,11 @@ func (n *Node) Convconst(con *Node, t *Type) {
con.Val = n.Val con.Val = n.Val
if Isint[tt] { if Isint[tt] {
con.Val.Ctype = CTINT
con.Val.U = new(Mpint) con.Val.U = new(Mpint)
var i int64 var i int64
switch n.Val.Ctype { switch n.Val.Ctype() {
default: default:
Fatal("convconst ctype=%d %v", n.Val.Ctype, Tconv(t, obj.FmtLong)) Fatal("convconst ctype=%d %v", n.Val.Ctype(), Tconv(t, obj.FmtLong))
case CTINT, CTRUNE: case CTINT, CTRUNE:
i = Mpgetfix(n.Val.U.(*Mpint)) i = Mpgetfix(n.Val.U.(*Mpint))
...@@ -1471,8 +1469,8 @@ func (n *Node) Convconst(con *Node, t *Type) { ...@@ -1471,8 +1469,8 @@ func (n *Node) Convconst(con *Node, t *Type) {
if Isfloat[tt] { if Isfloat[tt] {
con.Val = toflt(con.Val) con.Val = toflt(con.Val)
if con.Val.Ctype != CTFLT { if con.Val.Ctype() != CTFLT {
Fatal("convconst ctype=%d %v", con.Val.Ctype, t) Fatal("convconst ctype=%d %v", con.Val.Ctype(), t)
} }
if tt == TFLOAT32 { if tt == TFLOAT32 {
con.Val.U = truncfltlit(con.Val.U.(*Mpflt), t) con.Val.U = truncfltlit(con.Val.U.(*Mpflt), t)
...@@ -1636,13 +1634,13 @@ func isgoconst(n *Node) bool { ...@@ -1636,13 +1634,13 @@ func isgoconst(n *Node) bool {
} }
case OLITERAL: case OLITERAL:
if n.Val.Ctype != CTNIL { if n.Val.Ctype() != CTNIL {
return true return true
} }
case ONAME: case ONAME:
l := n.Sym.Def l := n.Sym.Def
if l != nil && l.Op == OLITERAL && n.Val.Ctype != CTNIL { if l != nil && l.Op == OLITERAL && n.Val.Ctype() != CTNIL {
return true return true
} }
......
...@@ -227,7 +227,6 @@ func nodfconst(n *Node, t *Type, fval *Mpflt) { ...@@ -227,7 +227,6 @@ func nodfconst(n *Node, t *Type, fval *Mpflt) {
n.Addable = true n.Addable = true
ullmancalc(n) ullmancalc(n)
n.Val.U = fval n.Val.U = fval
n.Val.Ctype = CTFLT
n.Type = t n.Type = t
if !Isfloat[t.Etype] { if !Isfloat[t.Etype] {
......
...@@ -828,7 +828,7 @@ func structfield(n *Node) *Type { ...@@ -828,7 +828,7 @@ func structfield(n *Node) *Type {
f.Broke = 1 f.Broke = 1
} }
switch n.Val.Ctype { switch n.Val.Ctype() {
case CTSTR: case CTSTR:
f.Note = new(string) f.Note = new(string)
*f.Note = n.Val.U.(string) *f.Note = n.Val.U.(string)
...@@ -937,7 +937,7 @@ func interfacefield(n *Node) *Type { ...@@ -937,7 +937,7 @@ func interfacefield(n *Node) *Type {
Fatal("interfacefield: oops %v\n", n) Fatal("interfacefield: oops %v\n", n)
} }
if n.Val.Ctype != CTxxx { if n.Val.Ctype() != CTxxx {
Yyerror("interface method cannot have annotation") Yyerror("interface method cannot have annotation")
} }
......
...@@ -299,7 +299,7 @@ func Jconv(n *Node, flag int) string { ...@@ -299,7 +299,7 @@ func Jconv(n *Node, flag int) string {
// Fmt "%V": Values // Fmt "%V": Values
func Vconv(v *Val, flag int) string { func Vconv(v *Val, flag int) string {
switch v.Ctype { switch v.Ctype() {
case CTINT: case CTINT:
if (flag&obj.FmtSharp != 0) || fmtmode == FExp { if (flag&obj.FmtSharp != 0) || fmtmode == FExp {
return Bconv(v.U.(*Mpint), obj.FmtSharp) return Bconv(v.U.(*Mpint), obj.FmtSharp)
...@@ -1109,7 +1109,7 @@ func exprfmt(n *Node, prec int) string { ...@@ -1109,7 +1109,7 @@ func exprfmt(n *Node, prec int) string {
return Sconv(n.Sym, 0) return Sconv(n.Sym, 0)
} }
} }
if n.Val.Ctype == CTNIL && n.Orig != nil && n.Orig != n { if n.Val.Ctype() == CTNIL && n.Orig != nil && n.Orig != n {
return exprfmt(n.Orig, prec) return exprfmt(n.Orig, prec)
} }
if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring { if n.Type != nil && n.Type != Types[n.Type.Etype] && n.Type != idealbool && n.Type != idealstring {
......
...@@ -340,14 +340,12 @@ func Clearslim(n *Node) { ...@@ -340,14 +340,12 @@ func Clearslim(n *Node) {
case TFLOAT32, TFLOAT64: case TFLOAT32, TFLOAT64:
var zero Mpflt var zero Mpflt
Mpmovecflt(&zero, 0.0) Mpmovecflt(&zero, 0.0)
z.Val.Ctype = CTFLT
z.Val.U = &zero z.Val.U = &zero
case TPTR32, TPTR64, TCHAN, TMAP: case TPTR32, TPTR64, TCHAN, TMAP:
z.Val.Ctype = CTNIL z.Val.U = new(NilVal)
case TBOOL: case TBOOL:
z.Val.Ctype = CTBOOL
z.Val.U = false z.Val.U = false
case TINT8, case TINT8,
...@@ -358,7 +356,6 @@ func Clearslim(n *Node) { ...@@ -358,7 +356,6 @@ func Clearslim(n *Node) {
TUINT16, TUINT16,
TUINT32, TUINT32,
TUINT64: TUINT64:
z.Val.Ctype = CTINT
z.Val.U = new(Mpint) z.Val.U = new(Mpint)
Mpmovecfix(z.Val.U.(*Mpint), 0) Mpmovecfix(z.Val.U.(*Mpint), 0)
......
...@@ -66,8 +66,9 @@ const ( ...@@ -66,8 +66,9 @@ const (
// Mpint represents an integer constant. // Mpint represents an integer constant.
type Mpint struct { type Mpint struct {
Val big.Int Val big.Int
Ovf bool // set if Val overflowed compiler limit (sticky) Ovf bool // set if Val overflowed compiler limit (sticky)
Rune bool // set if syntax indicates default type rune
} }
// Mpflt represents a floating-point constant. // Mpflt represents a floating-point constant.
...@@ -82,16 +83,40 @@ type Mpcplx struct { ...@@ -82,16 +83,40 @@ type Mpcplx struct {
} }
type Val struct { type Val struct {
Ctype int16
// U contains one of: // U contains one of:
// bool bool when Ctype == CTBOOL // bool bool when n.ValCtype() == CTBOOL
// *Mpint int when Ctype == CTINT, rune when Ctype == CTRUNE // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
// *Mpflt float when Ctype == CTFLT // *Mpflt float when n.ValCtype() == CTFLT
// *Mpcplx pair of floats when Ctype == CTCPLX // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
// string string when Ctype == CTSTR // string string when n.ValCtype() == CTSTR
// *Nilval when n.ValCtype() == CTNIL
U interface{} U interface{}
} }
type NilVal struct{}
func (v Val) Ctype() int {
switch x := v.U.(type) {
default:
return 0
case *NilVal:
return CTNIL
case bool:
return CTBOOL
case *Mpint:
if x.Rune {
return CTRUNE
}
return CTINT
case *Mpflt:
return CTFLT
case *Mpcplx:
return CTCPLX
case string:
return CTSTR
}
}
type Pkg struct { type Pkg struct {
Name string // package name Name string // package name
Path string // string literal used in import statement Path string // string literal used in import statement
......
...@@ -1996,7 +1996,7 @@ ohidden_interfacedcl_list: ...@@ -1996,7 +1996,7 @@ ohidden_interfacedcl_list:
oliteral: oliteral:
{ {
$$.Ctype = CTxxx; $$.U = nil
} }
| LLITERAL | LLITERAL
...@@ -2231,7 +2231,7 @@ hidden_literal: ...@@ -2231,7 +2231,7 @@ hidden_literal:
| '-' LLITERAL | '-' LLITERAL
{ {
$$ = nodlit($2); $$ = nodlit($2);
switch($$.Val.Ctype){ switch($$.Val.Ctype()){
case CTINT, CTRUNE: case CTINT, CTRUNE:
mpnegfix($$.Val.U.(*Mpint)); mpnegfix($$.Val.U.(*Mpint));
break; break;
...@@ -2258,7 +2258,7 @@ hidden_constant: ...@@ -2258,7 +2258,7 @@ hidden_constant:
hidden_literal hidden_literal
| '(' hidden_literal '+' hidden_literal ')' | '(' hidden_literal '+' hidden_literal ')'
{ {
if $2.Val.Ctype == CTRUNE && $4.Val.Ctype == CTINT { if $2.Val.Ctype() == CTRUNE && $4.Val.Ctype() == CTINT {
$$ = $2; $$ = $2;
mpaddfixfix($2.Val.U.(*Mpint), $4.Val.U.(*Mpint), 0); mpaddfixfix($2.Val.U.(*Mpint), $4.Val.U.(*Mpint), 0);
break; break;
......
...@@ -408,7 +408,7 @@ func Naddr(a *obj.Addr, n *Node) { ...@@ -408,7 +408,7 @@ func Naddr(a *obj.Addr, n *Node) {
if Thearch.Thechar == '8' { if Thearch.Thechar == '8' {
a.Width = 0 a.Width = 0
} }
switch n.Val.Ctype { switch n.Val.Ctype() {
default: default:
Fatal("naddr: const %v", Tconv(n.Type, obj.FmtLong)) Fatal("naddr: const %v", Tconv(n.Type, obj.FmtLong))
......
...@@ -639,7 +639,7 @@ func fakeimport() { ...@@ -639,7 +639,7 @@ func fakeimport() {
} }
func importfile(f *Val, line int) { func importfile(f *Val, line int) {
if f.Ctype != CTSTR { if _, ok := f.U.(string); !ok {
Yyerror("import statement not a string") Yyerror("import statement not a string")
fakeimport() fakeimport()
return return
...@@ -1064,9 +1064,10 @@ l0: ...@@ -1064,9 +1064,10 @@ l0:
ungetc(int(v)) ungetc(int(v))
} }
yylval.val.U = new(Mpint) x := new(Mpint)
Mpmovecfix(yylval.val.U.(*Mpint), v) yylval.val.U = x
yylval.val.Ctype = CTRUNE Mpmovecfix(x, v)
x.Rune = true
if Debug['x'] != 0 { if Debug['x'] != 0 {
fmt.Printf("lex: codepoint literal\n") fmt.Printf("lex: codepoint literal\n")
} }
...@@ -1410,7 +1411,6 @@ ncu: ...@@ -1410,7 +1411,6 @@ ncu:
Mpmovecfix(yylval.val.U.(*Mpint), 0) Mpmovecfix(yylval.val.U.(*Mpint), 0)
} }
yylval.val.Ctype = CTINT
if Debug['x'] != 0 { if Debug['x'] != 0 {
fmt.Printf("lex: integer literal\n") fmt.Printf("lex: integer literal\n")
} }
...@@ -1472,7 +1472,6 @@ casei: ...@@ -1472,7 +1472,6 @@ casei:
Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0) Mpmovecflt(&yylval.val.U.(*Mpcplx).Real, 0.0)
} }
yylval.val.Ctype = CTCPLX
if Debug['x'] != 0 { if Debug['x'] != 0 {
fmt.Printf("lex: imaginary literal\n") fmt.Printf("lex: imaginary literal\n")
} }
...@@ -1491,7 +1490,6 @@ caseout: ...@@ -1491,7 +1490,6 @@ caseout:
Mpmovecflt(yylval.val.U.(*Mpflt), 0.0) Mpmovecflt(yylval.val.U.(*Mpflt), 0.0)
} }
yylval.val.Ctype = CTFLT
if Debug['x'] != 0 { if Debug['x'] != 0 {
fmt.Printf("lex: floating literal\n") fmt.Printf("lex: floating literal\n")
} }
...@@ -1500,7 +1498,6 @@ caseout: ...@@ -1500,7 +1498,6 @@ caseout:
strlit: strlit:
yylval.val.U = internString(cp.Bytes()) yylval.val.U = internString(cp.Bytes())
yylval.val.Ctype = CTSTR
if Debug['x'] != 0 { if Debug['x'] != 0 {
fmt.Printf("lex: string literal\n") fmt.Printf("lex: string literal\n")
} }
...@@ -2235,7 +2232,7 @@ func lexinit() { ...@@ -2235,7 +2232,7 @@ func lexinit() {
Types[TNIL] = typ(TNIL) Types[TNIL] = typ(TNIL)
s = Pkglookup("nil", builtinpkg) s = Pkglookup("nil", builtinpkg)
var v Val var v Val
v.Ctype = CTNIL v.U = new(NilVal)
s.Def = nodlit(v) s.Def = nodlit(v)
s.Def.Sym = s s.Def.Sym = s
} }
...@@ -2359,7 +2356,7 @@ func lexfini() { ...@@ -2359,7 +2356,7 @@ func lexfini() {
s = Lookup("nil") s = Lookup("nil")
if s.Def == nil { if s.Def == nil {
var v Val var v Val
v.Ctype = CTNIL v.U = new(NilVal)
s.Def = nodlit(v) s.Def = nodlit(v)
s.Def.Sym = s s.Def.Sym = s
s.Origpkg = builtinpkg s.Origpkg = builtinpkg
......
...@@ -383,7 +383,7 @@ func dsymptr(s *Sym, off int, x *Sym, xoff int) int { ...@@ -383,7 +383,7 @@ func dsymptr(s *Sym, off int, x *Sym, xoff int) int {
func gdata(nam *Node, nr *Node, wid int) { func gdata(nam *Node, nr *Node, wid int) {
if nr.Op == OLITERAL { if nr.Op == OLITERAL {
switch nr.Val.Ctype { switch nr.Val.Ctype() {
case CTCPLX: case CTCPLX:
gdatacomplex(nam, nr.Val.U.(*Mpcplx)) gdatacomplex(nam, nr.Val.U.(*Mpcplx))
return return
......
...@@ -517,7 +517,7 @@ func staticname(t *Type, ctxt int) *Node { ...@@ -517,7 +517,7 @@ func staticname(t *Type, ctxt int) *Node {
func isliteral(n *Node) bool { func isliteral(n *Node) bool {
if n.Op == OLITERAL { if n.Op == OLITERAL {
if n.Val.Ctype != CTNIL { if n.Val.Ctype() != CTNIL {
return true return true
} }
} }
...@@ -1351,7 +1351,7 @@ func addvalue(p *InitPlan, xoffset int64, key *Node, n *Node) { ...@@ -1351,7 +1351,7 @@ func addvalue(p *InitPlan, xoffset int64, key *Node, n *Node) {
func iszero(n *Node) bool { func iszero(n *Node) bool {
switch n.Op { switch n.Op {
case OLITERAL: case OLITERAL:
switch n.Val.Ctype { switch n.Val.Ctype() {
default: default:
Dump("unexpected literal", n) Dump("unexpected literal", n)
Fatal("iszero") Fatal("iszero")
......
...@@ -667,7 +667,6 @@ func Nodintconst(v int64) *Node { ...@@ -667,7 +667,6 @@ func Nodintconst(v int64) *Node {
c.Addable = true c.Addable = true
c.Val.U = new(Mpint) c.Val.U = new(Mpint)
Mpmovecfix(c.Val.U.(*Mpint), v) Mpmovecfix(c.Val.U.(*Mpint), v)
c.Val.Ctype = CTINT
c.Type = Types[TIDEAL] c.Type = Types[TIDEAL]
ullmancalc(c) ullmancalc(c)
return c return c
...@@ -678,7 +677,6 @@ func nodfltconst(v *Mpflt) *Node { ...@@ -678,7 +677,6 @@ func nodfltconst(v *Mpflt) *Node {
c.Addable = true c.Addable = true
c.Val.U = newMpflt() c.Val.U = newMpflt()
mpmovefltflt(c.Val.U.(*Mpflt), v) mpmovefltflt(c.Val.U.(*Mpflt), v)
c.Val.Ctype = CTFLT
c.Type = Types[TIDEAL] c.Type = Types[TIDEAL]
ullmancalc(c) ullmancalc(c)
return c return c
...@@ -691,7 +689,6 @@ func Nodconst(n *Node, t *Type, v int64) { ...@@ -691,7 +689,6 @@ func Nodconst(n *Node, t *Type, v int64) {
ullmancalc(n) ullmancalc(n)
n.Val.U = new(Mpint) n.Val.U = new(Mpint)
Mpmovecfix(n.Val.U.(*Mpint), v) Mpmovecfix(n.Val.U.(*Mpint), v)
n.Val.Ctype = CTINT
n.Type = t n.Type = t
if Isfloat[t.Etype] { if Isfloat[t.Etype] {
...@@ -701,14 +698,13 @@ func Nodconst(n *Node, t *Type, v int64) { ...@@ -701,14 +698,13 @@ func Nodconst(n *Node, t *Type, v int64) {
func nodnil() *Node { func nodnil() *Node {
c := Nodintconst(0) c := Nodintconst(0)
c.Val.Ctype = CTNIL c.Val.U = new(NilVal)
c.Type = Types[TNIL] c.Type = Types[TNIL]
return c return c
} }
func Nodbool(b bool) *Node { func Nodbool(b bool) *Node {
c := Nodintconst(0) c := Nodintconst(0)
c.Val.Ctype = CTBOOL
c.Val.U = b c.Val.U = b
c.Type = idealbool c.Type = idealbool
return c return c
...@@ -796,7 +792,7 @@ func isnil(n *Node) bool { ...@@ -796,7 +792,7 @@ func isnil(n *Node) bool {
if n.Op != OLITERAL { if n.Op != OLITERAL {
return false return false
} }
if n.Val.Ctype != CTNIL { if n.Val.Ctype() != CTNIL {
return false return false
} }
return true return true
...@@ -2431,7 +2427,6 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) { ...@@ -2431,7 +2427,6 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
var l *NodeList var l *NodeList
var v Val var v Val
v.Ctype = CTSTR
v.U = rcvr.Type.Sym.Pkg.Name // package name v.U = rcvr.Type.Sym.Pkg.Name // package name
l = list(l, nodlit(v)) l = list(l, nodlit(v))
v.U = rcvr.Type.Sym.Name // type name v.U = rcvr.Type.Sym.Name // type name
......
...@@ -579,7 +579,7 @@ func (s *typeSwitch) walk(sw *Node) { ...@@ -579,7 +579,7 @@ func (s *typeSwitch) walk(sw *Node) {
switch c.typ { switch c.typ {
case caseKindTypeNil: case caseKindTypeNil:
var v Val var v Val
v.Ctype = CTNIL v.U = new(NilVal)
a = Nod(OIF, nil, nil) a = Nod(OIF, nil, nil)
a.Left = Nod(OEQ, s.facename, nodlit(v)) a.Left = Nod(OEQ, s.facename, nodlit(v))
typecheck(&a.Left, Erv) typecheck(&a.Left, Erv)
...@@ -742,11 +742,11 @@ func exprcmp(c1, c2 *caseClause) int { ...@@ -742,11 +742,11 @@ func exprcmp(c1, c2 *caseClause) int {
n2 := c2.node.Left n2 := c2.node.Left
// sort by type (for switches on interface) // sort by type (for switches on interface)
ct := int(n1.Val.Ctype) ct := int(n1.Val.Ctype())
if ct > int(n2.Val.Ctype) { if ct > int(n2.Val.Ctype()) {
return +1 return +1
} }
if ct < int(n2.Val.Ctype) { if ct < int(n2.Val.Ctype()) {
return -1 return -1
} }
if !Eqtype(n1.Type, n2.Type) { if !Eqtype(n1.Type, n2.Type) {
......
...@@ -301,7 +301,7 @@ OpSwitch: ...@@ -301,7 +301,7 @@ OpSwitch:
case OLITERAL: case OLITERAL:
ok |= Erv ok |= Erv
if n.Type == nil && n.Val.Ctype == CTSTR { if n.Type == nil && n.Val.Ctype() == CTSTR {
n.Type = idealstring n.Type = idealstring
} }
break OpSwitch break OpSwitch
...@@ -756,12 +756,12 @@ OpSwitch: ...@@ -756,12 +756,12 @@ OpSwitch:
} }
if et == TINTER { if et == TINTER {
if l.Op == OLITERAL && l.Val.Ctype == CTNIL { if l.Op == OLITERAL && l.Val.Ctype() == CTNIL {
// swap for back end // swap for back end
n.Left = r n.Left = r
n.Right = l n.Right = l
} else if r.Op == OLITERAL && r.Val.Ctype == CTNIL { } else if r.Op == OLITERAL && r.Val.Ctype() == CTNIL {
} else // leave alone for back end } else // leave alone for back end
if Isinter(r.Type) == Isinter(l.Type) { if Isinter(r.Type) == Isinter(l.Type) {
n.Etype = n.Op n.Etype = n.Op
...@@ -2833,7 +2833,7 @@ func keydup(n *Node, hash map[uint32][]*Node) { ...@@ -2833,7 +2833,7 @@ func keydup(n *Node, hash map[uint32][]*Node) {
} }
var b uint32 var b uint32
switch n.Val.Ctype { switch n.Val.Ctype() {
default: // unknown, bool, nil default: // unknown, bool, nil
b = 23 b = 23
...@@ -3486,7 +3486,7 @@ func typecheckfunc(n *Node) { ...@@ -3486,7 +3486,7 @@ func typecheckfunc(n *Node) {
func stringtoarraylit(np **Node) { func stringtoarraylit(np **Node) {
n := *np n := *np
if n.Left.Op != OLITERAL || n.Left.Val.Ctype != CTSTR { if n.Left.Op != OLITERAL || n.Left.Val.Ctype() != CTSTR {
Fatal("stringtoarraylit %v", n) Fatal("stringtoarraylit %v", n)
} }
...@@ -3844,7 +3844,7 @@ ret: ...@@ -3844,7 +3844,7 @@ ret:
func checkmake(t *Type, arg string, n *Node) int { func checkmake(t *Type, arg string, n *Node) int {
if n.Op == OLITERAL { if n.Op == OLITERAL {
switch n.Val.Ctype { switch n.Val.Ctype() {
case CTINT, CTRUNE, CTFLT, CTCPLX: case CTINT, CTRUNE, CTFLT, CTCPLX:
n.Val = toint(n.Val) n.Val = toint(n.Val)
if mpcmpfixc(n.Val.U.(*Mpint), 0) < 0 { if mpcmpfixc(n.Val.U.(*Mpint), 0) < 0 {
......
...@@ -138,8 +138,6 @@ yes: ...@@ -138,8 +138,6 @@ yes:
// any side effects disappear; ignore init // any side effects disappear; ignore init
ret: ret:
var val Val var val Val
val.Ctype = CTINT
val.U = new(Mpint) val.U = new(Mpint)
Mpmovecfix(val.U.(*Mpint), v) Mpmovecfix(val.U.(*Mpint), v)
n := Nod(OLITERAL, nil, nil) n := Nod(OLITERAL, nil, nil)
......
...@@ -2027,7 +2027,7 @@ func walkprint(nn *Node, init **NodeList) *Node { ...@@ -2027,7 +2027,7 @@ func walkprint(nn *Node, init **NodeList) *Node {
n = l.N n = l.N
if n.Op == OLITERAL { if n.Op == OLITERAL {
switch n.Val.Ctype { switch n.Val.Ctype() {
case CTRUNE: case CTRUNE:
defaultlit(&n, runetype) defaultlit(&n, runetype)
......
...@@ -3182,7 +3182,7 @@ yydefault: ...@@ -3182,7 +3182,7 @@ yydefault:
yyDollar = yyS[yypt-0 : yypt+1] yyDollar = yyS[yypt-0 : yypt+1]
//line go.y:1998 //line go.y:1998
{ {
yyVAL.val.Ctype = CTxxx yyVAL.val.U = nil
} }
case 304: case 304:
yyDollar = yyS[yypt-4 : yypt+1] yyDollar = yyS[yypt-4 : yypt+1]
...@@ -3434,7 +3434,7 @@ yydefault: ...@@ -3434,7 +3434,7 @@ yydefault:
//line go.y:2232 //line go.y:2232
{ {
yyVAL.node = nodlit(yyDollar[2].val) yyVAL.node = nodlit(yyDollar[2].val)
switch yyVAL.node.Val.Ctype { switch yyVAL.node.Val.Ctype() {
case CTINT, CTRUNE: case CTINT, CTRUNE:
mpnegfix(yyVAL.node.Val.U.(*Mpint)) mpnegfix(yyVAL.node.Val.U.(*Mpint))
break break
...@@ -3462,7 +3462,7 @@ yydefault: ...@@ -3462,7 +3462,7 @@ yydefault:
yyDollar = yyS[yypt-5 : yypt+1] yyDollar = yyS[yypt-5 : yypt+1]
//line go.y:2260 //line go.y:2260
{ {
if yyDollar[2].node.Val.Ctype == CTRUNE && yyDollar[4].node.Val.Ctype == CTINT { if yyDollar[2].node.Val.Ctype() == CTRUNE && yyDollar[4].node.Val.Ctype() == CTINT {
yyVAL.node = yyDollar[2].node yyVAL.node = yyDollar[2].node
mpaddfixfix(yyDollar[2].node.Val.U.(*Mpint), yyDollar[4].node.Val.U.(*Mpint), 0) mpaddfixfix(yyDollar[2].node.Val.U.(*Mpint), yyDollar[4].node.Val.U.(*Mpint), 0)
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