lang/token: add IsXBinaryTildeModOp

This commit is contained in:
Nigel Tao committed 2026-06-19 19:09:26 +10:00
1 parent a4ec3f8e92
commit 1f3df26c7f
2 files changed
+19 -16

No files matched your search

+4 -6
View File
@@ -286,9 +286,11 @@ func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, depth uint32) error {
}
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
opName, lhsCast, overallCast := "", false, n.MType().IsSmallInteger()
op := n.Operator()
opName := ""
lhsCast := false
overallCast := n.MType().IsSmallInteger() || op.IsXBinaryTildeModOp()
switch op {
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat, t.IDXBinaryTildeModPlus:
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Sign() == 0) {
@@ -296,13 +298,11 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
} else if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
}
overallCast = overallCast || (op == t.IDXBinaryTildeModPlus)
case t.IDXBinaryMinus, t.IDXBinaryTildeModMinus:
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
}
overallCast = overallCast || (op == t.IDXBinaryTildeModMinus)
case t.IDXBinaryStar, t.IDXBinaryTildeModStar:
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Cmp(one) == 0) {
@@ -314,7 +314,6 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
} else if (rcv != nil) && (rcv.Sign() == 0) && n.LHS().AsExpr().Effect().Pure() {
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
}
overallCast = overallCast || (op == t.IDXBinaryTildeModStar)
case t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
uBits := uintBits(n.MType().QID())
@@ -337,7 +336,6 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
} else if lhs := n.LHS().AsExpr(); lhs.ConstValue() != nil {
lhsCast = true
}
overallCast = overallCast || (op == t.IDXBinaryTildeModShiftL)
}
if opName == "" {
+15 -10
View File
@@ -55,8 +55,11 @@ func (x ID) AssociativeForm() ID {
func (x ID) IsBuiltIn() bool { return x < nBuiltInIDs }
func (x ID) IsUnaryOp() bool { return minOp <= x && x <= maxOp && unaryForms[x] != 0 }
func (x ID) IsBinaryOp() bool { return minOp <= x && x <= maxOp && binaryForms[x] != 0 }
func (x ID) IsUnaryOp() bool { return minOp <= x && x <= maxOp && unaryForms[x] != 0 }
func (x ID) IsBinaryOp() bool { return minOp <= x && x <= maxOp && binaryForms[x] != 0 }
func (x ID) IsXBinaryTildeModOp() bool {
return minXBinaryTildeModOp <= x && x <= maxXBinaryTildeModOp && binaryForms[x] != 0
}
func (x ID) IsAssociativeOp() bool { return minOp <= x && x <= maxOp && associativeForms[x] != 0 }
func (x ID) IsLiteral(m *Map) bool {
@@ -279,12 +282,14 @@ const (
)
const (
minOp = 0x40
minAmbiguousOp = 0x40
maxAmbiguousOp = 0x6F
minXOp = 0x70
maxXOp = 0xAF
maxOp = 0xAF
minOp = 0x40
minAmbiguousOp = 0x40
maxAmbiguousOp = 0x6F
minXOp = 0x70
minXBinaryTildeModOp = 0x80
maxXBinaryTildeModOp = 0x87
maxXOp = 0xAF
maxOp = 0xAF
IDPlus = ID(0x40)
IDMinus = ID(0x41)
@@ -972,8 +977,8 @@ var builtInsByID = [nBuiltInIDs]string{
IDSkipU32: "skip_u32",
IDSkipU32Fast: "skip_u32_fast",
IDCopyFromSlice: "copy_from_slice",
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
IDCopyFromSlice: "copy_from_slice",
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp",
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",