From a0a9975815106ed8e5c9b3ddde4ce7b4cad92771 Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 1 Jun 2017 21:33:51 +1000 Subject: [PATCH] Add a built-in token.ID for the 0 literal. --- lang/check/bounds.go | 4 ++-- lang/token/list.go | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 52775e0c..faada549 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -28,7 +28,7 @@ var ( one = big.NewInt(1) ffff = big.NewInt(0xFFFF) - zeroExpr = a.NewExpr(a.FlagsTypeChecked, 0, t.IDUnderscore, nil, nil, nil, nil) + zeroExpr = a.NewExpr(a.FlagsTypeChecked, 0, t.IDZero, nil, nil, nil, nil) ) func init() { @@ -168,7 +168,7 @@ func (q *checker) bcheckStatement(n *a.Node) error { lhs.SetMType(n.XType()) rhs := n.Value() if rhs == nil { - // "var x T" has an implicit "= _". + // "var x T" has an implicit "= 0". // // TODO: check that T is an integer type. rhs = zeroExpr diff --git a/lang/token/list.go b/lang/token/list.go index cc6103a2..402b0158 100644 --- a/lang/token/list.go +++ b/lang/token/list.go @@ -203,6 +203,7 @@ const ( KeyFalse = Key(IDFalse >> KeyShift) KeyTrue = Key(IDTrue >> KeyShift) + KeyZero = Key(IDZero >> KeyShift) KeyI8 = Key(IDI8 >> KeyShift) KeyI16 = Key(IDI16 >> KeyShift) @@ -332,6 +333,7 @@ const ( IDFalse = ID(0x90<