mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 00:55:11 +01:00
Add a ~mod<< operator
This commit is contained in:
1 parent
9260f66dd3
commit
bc702b4c2b
4 files changed
+28
-7
No files matched your search
@@ -466,6 +466,7 @@ var cOpNames = [...]string{
|
|||||||
t.IDPipeEq: " |= ",
|
t.IDPipeEq: " |= ",
|
||||||
t.IDHatEq: " ^= ",
|
t.IDHatEq: " ^= ",
|
||||||
t.IDPercentEq: " %= ",
|
t.IDPercentEq: " %= ",
|
||||||
|
t.IDTildeModShiftLEq: " <<= ",
|
||||||
t.IDTildeModPlusEq: " += ",
|
t.IDTildeModPlusEq: " += ",
|
||||||
t.IDTildeModMinusEq: " -= ",
|
t.IDTildeModMinusEq: " -= ",
|
||||||
t.IDTildeSatPlusEq: noSuchCOperator,
|
t.IDTildeSatPlusEq: noSuchCOperator,
|
||||||
@@ -487,6 +488,7 @@ var cOpNames = [...]string{
|
|||||||
t.IDXBinaryPipe: " | ",
|
t.IDXBinaryPipe: " | ",
|
||||||
t.IDXBinaryHat: " ^ ",
|
t.IDXBinaryHat: " ^ ",
|
||||||
t.IDXBinaryPercent: " % ",
|
t.IDXBinaryPercent: " % ",
|
||||||
|
t.IDXBinaryTildeModShiftL: " << ",
|
||||||
t.IDXBinaryTildeModPlus: " + ",
|
t.IDXBinaryTildeModPlus: " + ",
|
||||||
t.IDXBinaryTildeModMinus: " - ",
|
t.IDXBinaryTildeModMinus: " - ",
|
||||||
t.IDXBinaryTildeSatPlus: noSuchCOperator,
|
t.IDXBinaryTildeSatPlus: noSuchCOperator,
|
||||||
|
|||||||
+10
-2
@@ -1078,7 +1078,7 @@ func (q *checker) bcheckExprBinaryOp1(op t.ID, lhs *a.Expr, lMin *big.Int, lMax
|
|||||||
}
|
}
|
||||||
return zero, big.NewInt(0).Sub(rMax, one), nil
|
return zero, big.NewInt(0).Sub(rMax, one), nil
|
||||||
|
|
||||||
case t.IDXBinaryShiftL:
|
case t.IDXBinaryShiftL, t.IDXBinaryTildeModShiftL:
|
||||||
if lMin.Sign() < 0 {
|
if lMin.Sign() < 0 {
|
||||||
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.Str(q.tm))
|
return nil, nil, fmt.Errorf("check: shift op argument %q is possibly negative", lhs.Str(q.tm))
|
||||||
}
|
}
|
||||||
@@ -1088,7 +1088,15 @@ func (q *checker) bcheckExprBinaryOp1(op t.ID, lhs *a.Expr, lMin *big.Int, lMax
|
|||||||
if rMax.Cmp(ffff) > 0 {
|
if rMax.Cmp(ffff) > 0 {
|
||||||
return nil, nil, fmt.Errorf("check: shift %q out of range", rhs.Str(q.tm))
|
return nil, nil, fmt.Errorf("check: shift %q out of range", rhs.Str(q.tm))
|
||||||
}
|
}
|
||||||
return big.NewInt(0).Lsh(lMin, uint(rMin.Uint64())), big.NewInt(0).Lsh(lMax, uint(rMax.Uint64())), nil
|
nMin := big.NewInt(0).Lsh(lMin, uint(rMin.Uint64()))
|
||||||
|
nMax := big.NewInt(0).Lsh(lMax, uint(rMax.Uint64()))
|
||||||
|
if op == t.IDXBinaryTildeModShiftL {
|
||||||
|
if qid := lhs.MType().QID(); qid[0] == t.IDBase {
|
||||||
|
b := numTypeBounds[qid[1]]
|
||||||
|
nMax = min(nMax, b[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nMin, nMax, nil
|
||||||
|
|
||||||
case t.IDXBinaryShiftR:
|
case t.IDXBinaryShiftR:
|
||||||
if lMin.Sign() < 0 {
|
if lMin.Sign() < 0 {
|
||||||
|
|||||||
+6
-5
@@ -298,7 +298,7 @@ func (q *checker) tcheckAssign(n *a.Assign) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch n.Operator() {
|
switch n.Operator() {
|
||||||
case t.IDShiftLEq, t.IDShiftREq:
|
case t.IDShiftLEq, t.IDShiftREq, t.IDTildeModShiftLEq:
|
||||||
if !rTyp.IsNumTypeOrIdeal() {
|
if !rTyp.IsNumTypeOrIdeal() {
|
||||||
return fmt.Errorf("check: assignment %q: shift %q, of type %q, does not have numeric type",
|
return fmt.Errorf("check: assignment %q: shift %q, of type %q, does not have numeric type",
|
||||||
n.Operator().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
n.Operator().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
||||||
@@ -768,7 +768,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
|
|||||||
lTyp.Str(q.tm), rTyp.Str(q.tm),
|
lTyp.Str(q.tm), rTyp.Str(q.tm),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
case t.IDXBinaryShiftL, t.IDXBinaryShiftR:
|
case t.IDXBinaryShiftL, t.IDXBinaryShiftR, t.IDXBinaryTildeModShiftL:
|
||||||
if lTyp.IsIdeal() && !rTyp.IsIdeal() {
|
if lTyp.IsIdeal() && !rTyp.IsIdeal() {
|
||||||
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+
|
return fmt.Errorf("check: binary %q: %q and %q, of types %q and %q; "+
|
||||||
"cannot shift an ideal number by a non-ideal number",
|
"cannot shift an ideal number by a non-ideal number",
|
||||||
@@ -859,9 +859,6 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
|
|||||||
return nil, fmt.Errorf("check: division by zero in const expression %q", n.Str(tm))
|
return nil, fmt.Errorf("check: division by zero in const expression %q", n.Str(tm))
|
||||||
}
|
}
|
||||||
return big.NewInt(0).Mod(l, r), nil
|
return big.NewInt(0).Mod(l, r), nil
|
||||||
case t.IDXBinaryTildeModPlus, t.IDXBinaryTildeModMinus,
|
|
||||||
t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
|
|
||||||
return nil, fmt.Errorf("check: cannot apply tilde-operators to ideal numbers")
|
|
||||||
case t.IDXBinaryNotEq:
|
case t.IDXBinaryNotEq:
|
||||||
return btoi(l.Cmp(r) != 0), nil
|
return btoi(l.Cmp(r) != 0), nil
|
||||||
case t.IDXBinaryLessThan:
|
case t.IDXBinaryLessThan:
|
||||||
@@ -878,6 +875,10 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
|
|||||||
return btoi((l.Sign() != 0) && (r.Sign() != 0)), nil
|
return btoi((l.Sign() != 0) && (r.Sign() != 0)), nil
|
||||||
case t.IDXBinaryOr:
|
case t.IDXBinaryOr:
|
||||||
return btoi((l.Sign() != 0) || (r.Sign() != 0)), nil
|
return btoi((l.Sign() != 0) || (r.Sign() != 0)), nil
|
||||||
|
case t.IDXBinaryTildeModShiftL,
|
||||||
|
t.IDXBinaryTildeModPlus, t.IDXBinaryTildeModMinus,
|
||||||
|
t.IDXBinaryTildeSatPlus, t.IDXBinaryTildeSatMinus:
|
||||||
|
return nil, fmt.Errorf("check: cannot apply tilde-operators to ideal numbers")
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("check: unrecognized token (0x%02X) for evalConstValueBinaryOp", n.Operator())
|
return nil, fmt.Errorf("check: unrecognized token (0x%02X) for evalConstValueBinaryOp", n.Operator())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ const (
|
|||||||
IDPipeEq = ID(0x17)
|
IDPipeEq = ID(0x17)
|
||||||
IDHatEq = ID(0x18)
|
IDHatEq = ID(0x18)
|
||||||
IDPercentEq = ID(0x19)
|
IDPercentEq = ID(0x19)
|
||||||
|
IDTildeModShiftLEq = ID(0x1A)
|
||||||
IDTildeModPlusEq = ID(0x1B)
|
IDTildeModPlusEq = ID(0x1B)
|
||||||
IDTildeModMinusEq = ID(0x1C)
|
IDTildeModMinusEq = ID(0x1C)
|
||||||
IDTildeSatPlusEq = ID(0x1D)
|
IDTildeSatPlusEq = ID(0x1D)
|
||||||
@@ -260,6 +261,7 @@ const (
|
|||||||
IDPipe = ID(0x37)
|
IDPipe = ID(0x37)
|
||||||
IDHat = ID(0x38)
|
IDHat = ID(0x38)
|
||||||
IDPercent = ID(0x39)
|
IDPercent = ID(0x39)
|
||||||
|
IDTildeModShiftL = ID(0x3A)
|
||||||
IDTildeModPlus = ID(0x3B)
|
IDTildeModPlus = ID(0x3B)
|
||||||
IDTildeModMinus = ID(0x3C)
|
IDTildeModMinus = ID(0x3C)
|
||||||
IDTildeSatPlus = ID(0x3D)
|
IDTildeSatPlus = ID(0x3D)
|
||||||
@@ -300,6 +302,7 @@ const (
|
|||||||
IDXBinaryPipe = ID(0x5F)
|
IDXBinaryPipe = ID(0x5F)
|
||||||
IDXBinaryHat = ID(0x60)
|
IDXBinaryHat = ID(0x60)
|
||||||
IDXBinaryPercent = ID(0x61)
|
IDXBinaryPercent = ID(0x61)
|
||||||
|
IDXBinaryTildeModShiftL = ID(0x62)
|
||||||
IDXBinaryTildeModPlus = ID(0x63)
|
IDXBinaryTildeModPlus = ID(0x63)
|
||||||
IDXBinaryTildeModMinus = ID(0x64)
|
IDXBinaryTildeModMinus = ID(0x64)
|
||||||
IDXBinaryTildeSatPlus = ID(0x65)
|
IDXBinaryTildeSatPlus = ID(0x65)
|
||||||
@@ -540,6 +543,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDPipeEq: "|=",
|
IDPipeEq: "|=",
|
||||||
IDHatEq: "^=",
|
IDHatEq: "^=",
|
||||||
IDPercentEq: "%=",
|
IDPercentEq: "%=",
|
||||||
|
IDTildeModShiftLEq: "~mod<<=",
|
||||||
IDTildeModPlusEq: "~mod+=",
|
IDTildeModPlusEq: "~mod+=",
|
||||||
IDTildeModMinusEq: "~mod-=",
|
IDTildeModMinusEq: "~mod-=",
|
||||||
IDTildeSatPlusEq: "~sat+=",
|
IDTildeSatPlusEq: "~sat+=",
|
||||||
@@ -558,6 +562,7 @@ var builtInsByID = [nBuiltInIDs]string{
|
|||||||
IDPipe: "|",
|
IDPipe: "|",
|
||||||
IDHat: "^",
|
IDHat: "^",
|
||||||
IDPercent: "%",
|
IDPercent: "%",
|
||||||
|
IDTildeModShiftL: "~mod<<",
|
||||||
IDTildeModPlus: "~mod+",
|
IDTildeModPlus: "~mod+",
|
||||||
IDTildeModMinus: "~mod-",
|
IDTildeModMinus: "~mod-",
|
||||||
IDTildeSatPlus: "~sat+",
|
IDTildeSatPlus: "~sat+",
|
||||||
@@ -845,6 +850,8 @@ var lexers = [256][]suffixLexer{
|
|||||||
{"", IDGreaterThan},
|
{"", IDGreaterThan},
|
||||||
},
|
},
|
||||||
'~': {
|
'~': {
|
||||||
|
{"mod<<=", IDTildeModShiftLEq},
|
||||||
|
{"mod<<", IDTildeModShiftL},
|
||||||
{"mod+=", IDTildeModPlusEq},
|
{"mod+=", IDTildeModPlusEq},
|
||||||
{"mod+", IDTildeModPlus},
|
{"mod+", IDTildeModPlus},
|
||||||
{"mod-=", IDTildeModMinusEq},
|
{"mod-=", IDTildeModMinusEq},
|
||||||
@@ -873,6 +880,7 @@ var ambiguousForms = [nBuiltInSymbolicIDs]ID{
|
|||||||
IDXBinaryPipe: IDPipe,
|
IDXBinaryPipe: IDPipe,
|
||||||
IDXBinaryHat: IDHat,
|
IDXBinaryHat: IDHat,
|
||||||
IDXBinaryPercent: IDPercent,
|
IDXBinaryPercent: IDPercent,
|
||||||
|
IDXBinaryTildeModShiftL: IDTildeModShiftL,
|
||||||
IDXBinaryTildeModPlus: IDTildeModPlus,
|
IDXBinaryTildeModPlus: IDTildeModPlus,
|
||||||
IDXBinaryTildeModMinus: IDTildeModMinus,
|
IDXBinaryTildeModMinus: IDTildeModMinus,
|
||||||
IDXBinaryTildeSatPlus: IDTildeSatPlus,
|
IDXBinaryTildeSatPlus: IDTildeSatPlus,
|
||||||
@@ -941,6 +949,7 @@ var binaryForms = [nBuiltInSymbolicIDs]ID{
|
|||||||
IDPipeEq: IDXBinaryPipe,
|
IDPipeEq: IDXBinaryPipe,
|
||||||
IDHatEq: IDXBinaryHat,
|
IDHatEq: IDXBinaryHat,
|
||||||
IDPercentEq: IDXBinaryPercent,
|
IDPercentEq: IDXBinaryPercent,
|
||||||
|
IDTildeModShiftLEq: IDXBinaryTildeModShiftL,
|
||||||
IDTildeModPlusEq: IDXBinaryTildeModPlus,
|
IDTildeModPlusEq: IDXBinaryTildeModPlus,
|
||||||
IDTildeModMinusEq: IDXBinaryTildeModMinus,
|
IDTildeModMinusEq: IDXBinaryTildeModMinus,
|
||||||
IDTildeSatPlusEq: IDXBinaryTildeSatPlus,
|
IDTildeSatPlusEq: IDXBinaryTildeSatPlus,
|
||||||
@@ -956,6 +965,7 @@ var binaryForms = [nBuiltInSymbolicIDs]ID{
|
|||||||
IDPipe: IDXBinaryPipe,
|
IDPipe: IDXBinaryPipe,
|
||||||
IDHat: IDXBinaryHat,
|
IDHat: IDXBinaryHat,
|
||||||
IDPercent: IDXBinaryPercent,
|
IDPercent: IDXBinaryPercent,
|
||||||
|
IDTildeModShiftL: IDXBinaryTildeModShiftL,
|
||||||
IDTildeModPlus: IDXBinaryTildeModPlus,
|
IDTildeModPlus: IDXBinaryTildeModPlus,
|
||||||
IDTildeModMinus: IDXBinaryTildeModMinus,
|
IDTildeModMinus: IDXBinaryTildeModMinus,
|
||||||
IDTildeSatPlus: IDXBinaryTildeSatPlus,
|
IDTildeSatPlus: IDXBinaryTildeSatPlus,
|
||||||
|
|||||||
Reference in new issue
Block a user