mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
lang/token: add IsXBinaryTildeModOp
This commit is contained in:
1 parent
a4ec3f8e92
commit
1f3df26c7f
2 files changed
+19
-16
No files matched your search
@@ -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 {
|
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error {
|
||||||
opName, lhsCast, overallCast := "", false, n.MType().IsSmallInteger()
|
|
||||||
|
|
||||||
op := n.Operator()
|
op := n.Operator()
|
||||||
|
opName := ""
|
||||||
|
lhsCast := false
|
||||||
|
overallCast := n.MType().IsSmallInteger() || op.IsXBinaryTildeModOp()
|
||||||
|
|
||||||
switch op {
|
switch op {
|
||||||
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat, t.IDXBinaryTildeModPlus:
|
case t.IDXBinaryPlus, t.IDXBinaryPipe, t.IDXBinaryHat, t.IDXBinaryTildeModPlus:
|
||||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Sign() == 0) {
|
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) {
|
} else if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||||
}
|
}
|
||||||
overallCast = overallCast || (op == t.IDXBinaryTildeModPlus)
|
|
||||||
|
|
||||||
case t.IDXBinaryMinus, t.IDXBinaryTildeModMinus:
|
case t.IDXBinaryMinus, t.IDXBinaryTildeModMinus:
|
||||||
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
if rcv := n.RHS().AsExpr().ConstValue(); (rcv != nil) && (rcv.Sign() == 0) {
|
||||||
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
return g.writeExpr(b, n.LHS().AsExpr(), false, depth)
|
||||||
}
|
}
|
||||||
overallCast = overallCast || (op == t.IDXBinaryTildeModMinus)
|
|
||||||
|
|
||||||
case t.IDXBinaryStar, t.IDXBinaryTildeModStar:
|
case t.IDXBinaryStar, t.IDXBinaryTildeModStar:
|
||||||
if lcv := n.LHS().AsExpr().ConstValue(); (lcv != nil) && (lcv.Cmp(one) == 0) {
|
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() {
|
} else if (rcv != nil) && (rcv.Sign() == 0) && n.LHS().AsExpr().Effect().Pure() {
|
||||||
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
|
return g.writeExpr(b, n.RHS().AsExpr(), false, depth)
|
||||||
}
|
}
|
||||||
overallCast = overallCast || (op == t.IDXBinaryTildeModStar)
|
|
||||||
|
|
||||||
case t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
|
case t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
|
||||||
uBits := uintBits(n.MType().QID())
|
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 {
|
} else if lhs := n.LHS().AsExpr(); lhs.ConstValue() != nil {
|
||||||
lhsCast = true
|
lhsCast = true
|
||||||
}
|
}
|
||||||
overallCast = overallCast || (op == t.IDXBinaryTildeModShiftL)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opName == "" {
|
if opName == "" {
|
||||||
|
|||||||
+15
-10
@@ -55,8 +55,11 @@ func (x ID) AssociativeForm() ID {
|
|||||||
|
|
||||||
func (x ID) IsBuiltIn() bool { return x < nBuiltInIDs }
|
func (x ID) IsBuiltIn() bool { return x < nBuiltInIDs }
|
||||||
|
|
||||||
func (x ID) IsUnaryOp() bool { return minOp <= x && x <= maxOp && unaryForms[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) 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) IsAssociativeOp() bool { return minOp <= x && x <= maxOp && associativeForms[x] != 0 }
|
||||||
|
|
||||||
func (x ID) IsLiteral(m *Map) bool {
|
func (x ID) IsLiteral(m *Map) bool {
|
||||||
@@ -279,12 +282,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
minOp = 0x40
|
minOp = 0x40
|
||||||
minAmbiguousOp = 0x40
|
minAmbiguousOp = 0x40
|
||||||
maxAmbiguousOp = 0x6F
|
maxAmbiguousOp = 0x6F
|
||||||
minXOp = 0x70
|
minXOp = 0x70
|
||||||
maxXOp = 0xAF
|
minXBinaryTildeModOp = 0x80
|
||||||
maxOp = 0xAF
|
maxXBinaryTildeModOp = 0x87
|
||||||
|
maxXOp = 0xAF
|
||||||
|
maxOp = 0xAF
|
||||||
|
|
||||||
IDPlus = ID(0x40)
|
IDPlus = ID(0x40)
|
||||||
IDMinus = ID(0x41)
|
IDMinus = ID(0x41)
|
||||||
@@ -972,8 +977,8 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDSkipU32: "skip_u32",
|
IDSkipU32: "skip_u32",
|
||||||
IDSkipU32Fast: "skip_u32_fast",
|
IDSkipU32Fast: "skip_u32_fast",
|
||||||
|
|
||||||
IDCopyFromSlice: "copy_from_slice",
|
IDCopyFromSlice: "copy_from_slice",
|
||||||
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
|
IDLimitedCopyU32FromHistory: "limited_copy_u32_from_history",
|
||||||
IDLimitedCopyU32FromHistory8ByteChunksDistance1Fast: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast",
|
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",
|
IDLimitedCopyU32FromHistory8ByteChunksDistance1FastReturnCusp: "limited_copy_u32_from_history_8_byte_chunks_distance_1_fast_return_cusp",
|
||||||
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
IDLimitedCopyU32FromHistory8ByteChunksFast: "limited_copy_u32_from_history_8_byte_chunks_fast",
|
||||||
|
|||||||
Reference in new issue
Block a user