diff --git a/lang/check/bounds.go b/lang/check/bounds.go index 0bd09243..033dd60d 100644 --- a/lang/check/bounds.go +++ b/lang/check/bounds.go @@ -36,7 +36,7 @@ var ( func init() { zeroExpr.SetConstValue(zero) - zeroExpr.SetMType(TypeExprIdealNumber) + zeroExpr.SetMType(TypeExprIdeal) } func btoi(b bool) *big.Int { diff --git a/lang/check/check.go b/lang/check/check.go index 315bdca8..2ebff691 100644 --- a/lang/check/check.go +++ b/lang/check/check.go @@ -50,12 +50,12 @@ func (e *Error) Error() string { // TypeExprFoo is an *ast.Node MType (implicit type). var ( - TypeExprBoolean = a.NewTypeExpr(0, t.IDBool, nil, nil, nil) - TypeExprIdealNumber = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil) - TypeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) + TypeExprBool = a.NewTypeExpr(0, t.IDBool, nil, nil, nil) + TypeExprIdeal = a.NewTypeExpr(0, t.IDIdeal, nil, nil, nil) + TypeExprU8 = a.NewTypeExpr(0, t.IDU8, nil, nil, nil) ) -func numeric(n *a.TypeExpr) bool { return n == TypeExprIdealNumber || n.IsNumType() } +func numeric(n *a.TypeExpr) bool { return n == TypeExprIdeal || n.IsNumType() } // TypeMap maps from variable names (as token IDs) to types. type TypeMap map[t.ID]*a.TypeExpr @@ -364,7 +364,7 @@ func (c *Checker) checkFuncBody(node *a.Node) error { if typ := o.MType(); typ == nil { return fmt.Errorf("check: internal error: expression %q has no (implicit) type", o.String(q.idMap)) - } else if typ == TypeExprIdealNumber && o.ConstValue() == nil { + } else if typ == TypeExprIdeal && o.ConstValue() == nil { return fmt.Errorf("check: internal error: expression %q has ideal number type "+ "but no const value", o.String(q.idMap)) } diff --git a/lang/check/type.go b/lang/check/type.go index b0914c4e..6538f0b4 100644 --- a/lang/check/type.go +++ b/lang/check/type.go @@ -56,7 +56,7 @@ func (q *checker) tcheckStatement(n *a.Node) error { if err := q.tcheckExpr(cond, 0); err != nil { return err } - if !cond.MType().Eq(TypeExprBoolean) { + if !cond.MType().Eq(TypeExprBool) { return fmt.Errorf("check: if condition %q, of type %q, does not have a boolean type", cond.String(q.idMap), cond.MType().String(q.idMap)) } @@ -128,7 +128,7 @@ func (q *checker) tcheckStatement(n *a.Node) error { if err := q.tcheckExpr(cond, 0); err != nil { return err } - if !cond.MType().Eq(TypeExprBoolean) { + if !cond.MType().Eq(TypeExprBool) { return fmt.Errorf("check: for-loop condition %q, of type %q, does not have a boolean type", cond.String(q.idMap), cond.MType().String(q.idMap)) } @@ -161,7 +161,7 @@ func (q *checker) tcheckAssert(n *a.Assert) error { if err := q.tcheckExpr(cond, 0); err != nil { return err } - if !cond.MType().Eq(TypeExprBoolean) { + if !cond.MType().Eq(TypeExprBool) { return fmt.Errorf("check: assert condition %q, of type %q, does not have a boolean type", cond.String(q.idMap), cond.MType().String(q.idMap)) } @@ -188,7 +188,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error { rTyp := rhs.MType() if n.Operator().Key() == t.KeyEq { - if (rTyp == TypeExprIdealNumber && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) { + if (rTyp == TypeExprIdeal && lTyp.IsNumType()) || lTyp.EqIgnoringRefinements(rTyp) { return nil } return fmt.Errorf("check: cannot assign %q of type %q to %q of type %q", @@ -209,7 +209,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error { n.Operator().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) } - if rTyp == TypeExprIdealNumber || lTyp.EqIgnoringRefinements(rTyp) { + if rTyp == TypeExprIdeal || lTyp.EqIgnoringRefinements(rTyp) { return nil } return fmt.Errorf("check: assignment %q: %q and %q, of types %q and %q, do not have compatible types", @@ -260,7 +260,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { return fmt.Errorf("check: invalid numeric literal %q", s) } n.SetConstValue(z) - n.SetMType(TypeExprIdealNumber) + n.SetMType(TypeExprIdeal) return nil } else if id1.IsIdent() { @@ -276,12 +276,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error { switch id1.Key() { case t.KeyFalse: n.SetConstValue(zero) - n.SetMType(TypeExprBoolean) + n.SetMType(TypeExprBool) return nil case t.KeyTrue: n.SetConstValue(one) - n.SetMType(TypeExprBoolean) + n.SetMType(TypeExprBool) return nil case t.KeyUnderscore: @@ -400,14 +400,14 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error { return nil case t.KeyXUnaryNot: - if !rTyp.Eq(TypeExprBoolean) { + if !rTyp.Eq(TypeExprBool) { return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type", n.ID0().AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) } if cv := rhs.ConstValue(); cv != nil { n.SetConstValue(btoi(cv.Cmp(zero) == 0)) } - n.SetMType(TypeExprBoolean) + n.SetMType(TypeExprBool) return nil } return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprUnaryOp", n.ID0().Key()) @@ -451,11 +451,11 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { case t.KeyXBinaryNotEq, t.KeyXBinaryEqEq: // No-op. case t.KeyXBinaryAnd, t.KeyXBinaryOr: - if lTyp != TypeExprBoolean { + if lTyp != TypeExprBool { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", op.AmbiguousForm().String(q.idMap), lhs.String(q.idMap), lTyp.String(q.idMap)) } - if rTyp != TypeExprBoolean { + if rTyp != TypeExprBool { return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type", op.AmbiguousForm().String(q.idMap), rhs.String(q.idMap), rTyp.String(q.idMap)) } @@ -463,7 +463,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { switch op.Key() { default: - if !lTyp.EqIgnoringRefinements(rTyp) && lTyp != TypeExprIdealNumber && rTyp != TypeExprIdealNumber { + if !lTyp.EqIgnoringRefinements(rTyp) && lTyp != TypeExprIdeal && rTyp != TypeExprIdeal { return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q, do not have compatible types", op.AmbiguousForm().String(q.idMap), lhs.String(q.idMap), rhs.String(q.idMap), @@ -471,7 +471,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { ) } case t.KeyXBinaryShiftL, t.KeyXBinaryShiftR: - if (lTyp == TypeExprIdealNumber) && (rTyp != TypeExprIdealNumber) { + if (lTyp == TypeExprIdeal) && (rTyp != TypeExprIdeal) { return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+ "cannot shift an ideal number by a non-ideal number", op.AmbiguousForm().String(q.idMap), @@ -488,8 +488,8 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error { } if comparisonOps[0xFF&op.Key()] { - n.SetMType(TypeExprBoolean) - } else if lTyp != TypeExprIdealNumber { + n.SetMType(TypeExprBool) + } else if lTyp != TypeExprIdeal { n.SetMType(lTyp) } else { n.SetMType(rTyp)