summaryrefslogtreecommitdiff
path: root/src/pkg/exp/eval/expr1.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/exp/eval/expr1.go')
-rwxr-xr-x[-rw-r--r--]src/pkg/exp/eval/expr1.go198
1 files changed, 99 insertions, 99 deletions
diff --git a/src/pkg/exp/eval/expr1.go b/src/pkg/exp/eval/expr1.go
index f0a78ac4d..ae0cfc723 100644..100755
--- a/src/pkg/exp/eval/expr1.go
+++ b/src/pkg/exp/eval/expr1.go
@@ -4,13 +4,13 @@
package eval
import (
- "exp/bignum"
+ "big"
"log"
)
/*
- * "As" functions. These retrieve evaluator functions from an
- * expr, panicking if the requested evaluator has the wrong type.
+* "As" functions. These retrieve evaluator functions from an
+* expr, panicking if the requested evaluator has the wrong type.
*/
func (a *expr) asBool() func(*Thread) bool {
return a.eval.(func(*Thread) bool)
@@ -21,14 +21,14 @@ func (a *expr) asUint() func(*Thread) uint64 {
func (a *expr) asInt() func(*Thread) int64 {
return a.eval.(func(*Thread) int64)
}
-func (a *expr) asIdealInt() func() *bignum.Integer {
- return a.eval.(func() *bignum.Integer)
+func (a *expr) asIdealInt() func() *big.Int {
+ return a.eval.(func() *big.Int)
}
func (a *expr) asFloat() func(*Thread) float64 {
return a.eval.(func(*Thread) float64)
}
-func (a *expr) asIdealFloat() func() *bignum.Rational {
- return a.eval.(func() *bignum.Rational)
+func (a *expr) asIdealFloat() func() *big.Rat {
+ return a.eval.(func() *big.Rat)
}
func (a *expr) asString() func(*Thread) string {
return a.eval.(func(*Thread) string)
@@ -63,11 +63,11 @@ func (a *expr) asInterface() func(*Thread) interface{} {
return func(t *Thread) interface{} { return sf(t) }
case func(t *Thread) int64:
return func(t *Thread) interface{} { return sf(t) }
- case func() *bignum.Integer:
+ case func() *big.Int:
return func(*Thread) interface{} { return sf() }
case func(t *Thread) float64:
return func(t *Thread) interface{} { return sf(t) }
- case func() *bignum.Rational:
+ case func() *big.Rat:
return func(*Thread) interface{} { return sf() }
case func(t *Thread) string:
return func(t *Thread) interface{} { return sf(t) }
@@ -84,13 +84,13 @@ func (a *expr) asInterface() func(*Thread) interface{} {
case func(t *Thread) Map:
return func(t *Thread) interface{} { return sf(t) }
default:
- log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos)
+ log.Panicf("unexpected expression node type %T at %v", a.eval, a.pos)
}
panic("fail")
}
/*
- * Operator generators.
+* Operator generators.
*/
func (a *expr) genConstant(v Value) {
@@ -103,12 +103,12 @@ func (a *expr) genConstant(v Value) {
a.eval = func(t *Thread) int64 { return v.(IntValue).Get(t) }
case *idealIntType:
val := v.(IdealIntValue).Get()
- a.eval = func() *bignum.Integer { return val }
+ a.eval = func() *big.Int { return val }
case *floatType:
a.eval = func(t *Thread) float64 { return v.(FloatValue).Get(t) }
case *idealFloatType:
val := v.(IdealFloatValue).Get()
- a.eval = func() *bignum.Rational { return val }
+ a.eval = func() *big.Rat { return val }
case *stringType:
a.eval = func(t *Thread) string { return v.(StringValue).Get(t) }
case *ArrayType:
@@ -124,7 +124,7 @@ func (a *expr) genConstant(v Value) {
case *MapType:
a.eval = func(t *Thread) Map { return v.(MapValue).Get(t) }
default:
- log.Crashf("unexpected constant type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected constant type %v at %v", a.t, a.pos)
}
}
@@ -154,7 +154,7 @@ func (a *expr) genIdentOp(level, index int) {
case *MapType:
a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get(t) }
default:
- log.Crashf("unexpected identifier type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected identifier type %v at %v", a.t, a.pos)
}
}
@@ -186,7 +186,7 @@ func (a *expr) genFuncCall(call func(t *Thread) []Value) {
case *MultiType:
a.eval = func(t *Thread) []Value { return call(t) }
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
@@ -216,7 +216,7 @@ func (a *expr) genValue(vf func(*Thread) Value) {
case *MapType:
a.eval = func(t *Thread) Map { return vf(t).(MapValue).Get(t) }
default:
- log.Crashf("unexpected result type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected result type %v at %v", a.t, a.pos)
}
}
@@ -229,18 +229,18 @@ func (a *expr) genUnaryOpNeg(v *expr) {
vf := v.asInt()
a.eval = func(t *Thread) int64 { v := vf(t); return -v }
case *idealIntType:
- v := v.asIdealInt()()
- val := v.Neg()
- a.eval = func() *bignum.Integer { return val }
+ val := v.asIdealInt()()
+ val.Neg(val)
+ a.eval = func() *big.Int { return val }
case *floatType:
vf := v.asFloat()
a.eval = func(t *Thread) float64 { v := vf(t); return -v }
case *idealFloatType:
- v := v.asIdealFloat()()
- val := v.Neg()
- a.eval = func() *bignum.Rational { return val }
+ val := v.asIdealFloat()()
+ val.Neg(val)
+ a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
@@ -250,7 +250,7 @@ func (a *expr) genUnaryOpNot(v *expr) {
vf := v.asBool()
a.eval = func(t *Thread) bool { v := vf(t); return !v }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
@@ -263,11 +263,11 @@ func (a *expr) genUnaryOpXor(v *expr) {
vf := v.asInt()
a.eval = func(t *Thread) int64 { v := vf(t); return ^v }
case *idealIntType:
- v := v.asIdealInt()()
- val := v.Neg().Sub(bignum.Int(1))
- a.eval = func() *bignum.Integer { return val }
+ val := v.asIdealInt()()
+ val.Not(val)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", a.t, a.pos)
+ log.Panicf("unexpected type %v at %v", a.t, a.pos)
}
}
@@ -325,7 +325,7 @@ func (a *expr) genBinOpAdd(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -367,13 +367,13 @@ func (a *expr) genBinOpAdd(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Add(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Add(l, r)
+ a.eval = func() *big.Int { return val }
case *floatType:
lf := l.asFloat()
rf := r.asFloat()
@@ -400,13 +400,13 @@ func (a *expr) genBinOpAdd(l, r *expr) {
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
r := r.asIdealFloat()()
- val := l.Add(r)
- a.eval = func() *bignum.Rational { return val }
+ val := l.Add(l, r)
+ a.eval = func() *big.Rat { return val }
case *stringType:
lf := l.asString()
rf := r.asString()
@@ -415,7 +415,7 @@ func (a *expr) genBinOpAdd(l, r *expr) {
return l + r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -461,7 +461,7 @@ func (a *expr) genBinOpSub(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -503,13 +503,13 @@ func (a *expr) genBinOpSub(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Sub(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Sub(l, r)
+ a.eval = func() *big.Int { return val }
case *floatType:
lf := l.asFloat()
rf := r.asFloat()
@@ -536,15 +536,15 @@ func (a *expr) genBinOpSub(l, r *expr) {
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
r := r.asIdealFloat()()
- val := l.Sub(r)
- a.eval = func() *bignum.Rational { return val }
+ val := l.Sub(l, r)
+ a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -590,7 +590,7 @@ func (a *expr) genBinOpMul(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -632,13 +632,13 @@ func (a *expr) genBinOpMul(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Mul(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Mul(l, r)
+ a.eval = func() *big.Int { return val }
case *floatType:
lf := l.asFloat()
rf := r.asFloat()
@@ -665,15 +665,15 @@ func (a *expr) genBinOpMul(l, r *expr) {
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
r := r.asIdealFloat()()
- val := l.Mul(r)
- a.eval = func() *bignum.Rational { return val }
+ val := l.Mul(l, r)
+ a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -734,7 +734,7 @@ func (a *expr) genBinOpQuo(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -791,13 +791,13 @@ func (a *expr) genBinOpQuo(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Quo(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Quo(l, r)
+ a.eval = func() *big.Int { return val }
case *floatType:
lf := l.asFloat()
rf := r.asFloat()
@@ -833,15 +833,15 @@ func (a *expr) genBinOpQuo(l, r *expr) {
return float64(float(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealFloatType:
l := l.asIdealFloat()()
r := r.asIdealFloat()()
- val := l.Quo(r)
- a.eval = func() *bignum.Rational { return val }
+ val := l.Quo(l, r)
+ a.eval = func() *big.Rat { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -902,7 +902,7 @@ func (a *expr) genBinOpRem(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -959,15 +959,15 @@ func (a *expr) genBinOpRem(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Rem(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Rem(l, r)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1013,7 +1013,7 @@ func (a *expr) genBinOpAnd(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1055,15 +1055,15 @@ func (a *expr) genBinOpAnd(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.And(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.And(l, r)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1109,7 +1109,7 @@ func (a *expr) genBinOpOr(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1151,15 +1151,15 @@ func (a *expr) genBinOpOr(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Or(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Or(l, r)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1205,7 +1205,7 @@ func (a *expr) genBinOpXor(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1247,15 +1247,15 @@ func (a *expr) genBinOpXor(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.Xor(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.Xor(l, r)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1301,7 +1301,7 @@ func (a *expr) genBinOpAndNot(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1343,15 +1343,15 @@ func (a *expr) genBinOpAndNot(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *idealIntType:
l := l.asIdealInt()()
r := r.asIdealInt()()
- val := l.AndNot(r)
- a.eval = func() *bignum.Integer { return val }
+ val := l.AndNot(l, r)
+ a.eval = func() *big.Int { return val }
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1397,7 +1397,7 @@ func (a *expr) genBinOpShl(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1439,10 +1439,10 @@ func (a *expr) genBinOpShl(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1488,7 +1488,7 @@ func (a *expr) genBinOpShr(l, r *expr) {
return uint64(uint(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
case *intType:
lf := l.asInt()
@@ -1530,10 +1530,10 @@ func (a *expr) genBinOpShr(l, r *expr) {
return int64(int(ret))
}
default:
- log.Crashf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
+ log.Panicf("unexpected size %d in type %v at %v", t.Bits, t, a.pos)
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1578,7 +1578,7 @@ func (a *expr) genBinOpLss(l, r *expr) {
return l < r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1623,7 +1623,7 @@ func (a *expr) genBinOpGtr(l, r *expr) {
return l > r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1668,7 +1668,7 @@ func (a *expr) genBinOpLeq(l, r *expr) {
return l <= r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1713,7 +1713,7 @@ func (a *expr) genBinOpGeq(l, r *expr) {
return l >= r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1786,7 +1786,7 @@ func (a *expr) genBinOpEql(l, r *expr) {
return l == r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1859,7 +1859,7 @@ func (a *expr) genBinOpNeq(l, r *expr) {
return l != r
}
default:
- log.Crashf("unexpected type %v at %v", l.t, a.pos)
+ log.Panicf("unexpected type %v at %v", l.t, a.pos)
}
}
@@ -1899,7 +1899,7 @@ func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
rf := r.asMap()
return func(lv Value, t *Thread) { lv.(MapValue).Set(t, rf(t)) }
default:
- log.Crashf("unexpected left operand type %v at %v", lt, r.pos)
+ log.Panicf("unexpected left operand type %v at %v", lt, r.pos)
}
panic("fail")
}