2009-09-01 12:51:33 -06:00
|
|
|
|
2009-09-01 23:57:53 -06:00
|
|
|
// This file is machine generated by gen.go.
|
2009-09-02 13:03:20 -06:00
|
|
|
// 6g gen.go && 6l gen.6 && ./6.out >expr1.go
|
2009-09-01 23:57:53 -06:00
|
|
|
|
|
|
|
package eval
|
2009-09-01 12:51:33 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bignum";
|
|
|
|
"log";
|
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
2009-09-01 23:57:53 -06:00
|
|
|
* "As" functions. These retrieve evaluator functions from an
|
|
|
|
* expr, panicking if the requested evaluator has the wrong type.
|
|
|
|
*/
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asBool() (func(*Thread) bool) {
|
|
|
|
return a.eval.(func(*Thread)(bool))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asUint() (func(*Thread) uint64) {
|
|
|
|
return a.eval.(func(*Thread)(uint64))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asInt() (func(*Thread) int64) {
|
|
|
|
return a.eval.(func(*Thread)(int64))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
|
|
|
func (a *expr) asIdealInt() (func() *bignum.Integer) {
|
|
|
|
return a.eval.(func()(*bignum.Integer))
|
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asFloat() (func(*Thread) float64) {
|
|
|
|
return a.eval.(func(*Thread)(float64))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
|
|
|
func (a *expr) asIdealFloat() (func() *bignum.Rational) {
|
|
|
|
return a.eval.(func()(*bignum.Rational))
|
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asString() (func(*Thread) string) {
|
|
|
|
return a.eval.(func(*Thread)(string))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asArray() (func(*Thread) ArrayValue) {
|
|
|
|
return a.eval.(func(*Thread)(ArrayValue))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asStruct() (func(*Thread) StructValue) {
|
|
|
|
return a.eval.(func(*Thread)(StructValue))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asPtr() (func(*Thread) Value) {
|
|
|
|
return a.eval.(func(*Thread)(Value))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asFunc() (func(*Thread) Func) {
|
|
|
|
return a.eval.(func(*Thread)(Func))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asSlice() (func(*Thread) Slice) {
|
|
|
|
return a.eval.(func(*Thread)(Slice))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asMap() (func(*Thread) Map) {
|
|
|
|
return a.eval.(func(*Thread)(Map))
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asMulti() (func(*Thread) []Value) {
|
|
|
|
return a.eval.(func(*Thread)[]Value)
|
2009-09-01 23:57:53 -06:00
|
|
|
}
|
|
|
|
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) asInterface() (func(*Thread) interface{}) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch sf := a.eval.(type) {
|
2009-09-02 13:03:20 -06:00
|
|
|
case func(*Thread)bool:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)uint64:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)int64:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)*bignum.Integer:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)float64:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)*bignum.Rational:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)string:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)ArrayValue:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)StructValue:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)Value:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)Func:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)Slice:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
|
|
|
case func(*Thread)Map:
|
|
|
|
return func(t *Thread) interface{} { return sf(t) }
|
2009-09-01 23:57:53 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected expression node type %T at %v", a.eval, a.pos);
|
|
|
|
}
|
|
|
|
panic();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Operator generators.
|
2009-09-01 12:51:33 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
func (a *expr) genConstant(v Value) {
|
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *boolType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) bool { return v.(BoolValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { return v.(UintValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) int64 { return v.(IntValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
|
|
|
val := v.(IdealIntValue).Get();
|
2009-09-01 23:57:53 -06:00
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) float64 { return v.(FloatValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
|
|
|
val := v.(IdealFloatValue).Get();
|
2009-09-01 23:57:53 -06:00
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) string { return v.(StringValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *ArrayType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) ArrayValue { return v.(ArrayValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *StructType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) StructValue { return v.(StructValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Value { return v.(PtrValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Func { return v.(FuncValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *SliceType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Slice { return v.(SliceValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Map { return v.(MapValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected constant type %v at %v", a.t, a.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-01 23:57:53 -06:00
|
|
|
func (a *expr) genIdentOp(level, index int) {
|
2009-09-02 13:03:20 -06:00
|
|
|
a.evalAddr = func(t *Thread) Value { return t.f.Get(level, index) };
|
2009-09-01 12:51:33 -06:00
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *boolType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) bool { return t.f.Get(level, index).(BoolValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { return t.f.Get(level, index).(UintValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) int64 { return t.f.Get(level, index).(IntValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) float64 { return t.f.Get(level, index).(FloatValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) string { return t.f.Get(level, index).(StringValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *ArrayType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) ArrayValue { return t.f.Get(level, index).(ArrayValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *StructType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) StructValue { return t.f.Get(level, index).(StructValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Value { return t.f.Get(level, index).(PtrValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Func { return t.f.Get(level, index).(FuncValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *SliceType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Slice { return t.f.Get(level, index).(SliceValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Map { return t.f.Get(level, index).(MapValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected identifier type %v at %v", a.t, a.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) genFuncCall(call func(t *Thread) []Value) {
|
|
|
|
a.exec = func(t *Thread) { call(t)};
|
2009-09-01 12:51:33 -06:00
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *boolType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) bool { return call(t)[0].(BoolValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { return call(t)[0].(UintValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) int64 { return call(t)[0].(IntValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) float64 { return call(t)[0].(FloatValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) string { return call(t)[0].(StringValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *ArrayType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) ArrayValue { return call(t)[0].(ArrayValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *StructType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) StructValue { return call(t)[0].(StructValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Value { return call(t)[0].(PtrValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Func { return call(t)[0].(FuncValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *SliceType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Slice { return call(t)[0].(SliceValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Map { return call(t)[0].(MapValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MultiType:
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) []Value { return call(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected result type %v at %v", a.t, a.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:03:20 -06:00
|
|
|
func (a *expr) genValue(vf func(*Thread) Value) {
|
2009-09-01 12:51:33 -06:00
|
|
|
a.evalAddr = vf;
|
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *boolType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) bool { return vf(t).(BoolValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { return vf(t).(UintValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) int64 { return vf(t).(IntValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) float64 { return vf(t).(FloatValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) string { return vf(t).(StringValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *ArrayType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) ArrayValue { return vf(t).(ArrayValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *StructType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) StructValue { return vf(t).(StructValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Value { return vf(t).(PtrValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Func { return vf(t).(FuncValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *SliceType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Slice { return vf(t).(SliceValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
2009-09-03 18:14:49 -06:00
|
|
|
a.eval = func(t *Thread) Map { return vf(t).(MapValue).Get(t) }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected result type %v at %v", a.t, a.pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genUnaryOpNeg(v *expr) {
|
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
vf := v.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { v := vf(t); return -v }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
vf := v.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { v := vf(t); return -v }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
v := v.asIdealInt()();
|
|
|
|
val := v.Neg();
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
vf := v.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) float64 { v := vf(t); return -v }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
v := v.asIdealFloat()();
|
|
|
|
val := v.Neg();
|
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", a.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genUnaryOpNot(v *expr) {
|
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *boolType:
|
|
|
|
vf := v.asBool();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { v := vf(t); return !v }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", a.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genUnaryOpXor(v *expr) {
|
|
|
|
switch _ := a.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
vf := v.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { v := vf(t); return ^v }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
vf := v.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { v := vf(t); return ^v }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
v := v.asIdealInt()();
|
|
|
|
val := v.Neg().Sub(bignum.Int(1));
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", a.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpAdd(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l + r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l + r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Add(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) float64 { l, r := lf(t), rf(t); return l + r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Add(r);
|
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) string { l, r := lf(t), rf(t); return l + r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpSub(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l - r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l - r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Sub(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) float64 { l, r := lf(t), rf(t); return l - r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Sub(r);
|
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpMul(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l * r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l * r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Mul(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) float64 { l, r := lf(t), rf(t); return l * r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Mul(r);
|
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpQuo(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 15:11:40 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); if r == 0 { t.Abort(DivByZeroError{}) } return l / r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 15:11:40 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); if r == 0 { t.Abort(DivByZeroError{}) } return l / r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Quo(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 15:11:40 -06:00
|
|
|
a.eval = func(t *Thread) float64 { l, r := lf(t), rf(t); if r == 0 { t.Abort(DivByZeroError{}) } return l / r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Quo(r);
|
|
|
|
a.eval = func() *bignum.Rational { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpRem(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 15:11:40 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); if r == 0 { t.Abort(DivByZeroError{}) } return l % r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 15:11:40 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); if r == 0 { t.Abort(DivByZeroError{}) } return l % r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Rem(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpAnd(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l & r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l & r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.And(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpOr(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l | r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l | r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Or(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpXor(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l ^ r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l ^ r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Xor(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpAndNot(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l &^ r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l &^ r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.AndNot(r);
|
|
|
|
a.eval = func() *bignum.Integer { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpShl(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l << r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l << r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpShr(l, r *expr) {
|
2009-09-01 23:57:53 -06:00
|
|
|
switch _ := l.t.lit().(type) {
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) uint64 { l, r := lf(t), rf(t); return l >> r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) int64 { l, r := lf(t), rf(t); return l >> r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpLss(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l < r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l < r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) < 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l < r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) < 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l < r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpGtr(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l > r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l > r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) > 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l > r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) > 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l > r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpLeq(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l <= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l <= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) <= 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l <= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) <= 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l <= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpGeq(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l >= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l >= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) >= 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l >= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) >= 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l >= r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpEql(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *boolType:
|
|
|
|
lf := l.asBool();
|
|
|
|
rf := r.asBool();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) == 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) == 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
|
|
|
lf := l.asPtr();
|
|
|
|
rf := r.asPtr();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
|
|
|
lf := l.asFunc();
|
|
|
|
rf := r.asFunc();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
|
|
|
lf := l.asMap();
|
|
|
|
rf := r.asMap();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l == r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *expr) genBinOpNeq(l, r *expr) {
|
|
|
|
switch _ := l.t.lit().(type) {
|
|
|
|
case *boolType:
|
|
|
|
lf := l.asBool();
|
|
|
|
rf := r.asBool();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
lf := l.asUint();
|
|
|
|
rf := r.asUint();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
lf := l.asInt();
|
|
|
|
rf := r.asInt();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealIntType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealInt()();
|
|
|
|
r := r.asIdealInt()();
|
|
|
|
val := l.Cmp(r) != 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
lf := l.asFloat();
|
|
|
|
rf := r.asFloat();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *idealFloatType:
|
2009-09-01 23:57:53 -06:00
|
|
|
l := l.asIdealFloat()();
|
|
|
|
r := r.asIdealFloat()();
|
|
|
|
val := l.Cmp(r) != 0;
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { return val }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
lf := l.asString();
|
|
|
|
rf := r.asString();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
|
|
|
lf := l.asPtr();
|
|
|
|
rf := r.asPtr();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
|
|
|
lf := l.asFunc();
|
|
|
|
rf := r.asFunc();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
|
|
|
lf := l.asMap();
|
|
|
|
rf := r.asMap();
|
2009-09-02 13:03:20 -06:00
|
|
|
a.eval = func(t *Thread) bool { l, r := lf(t), rf(t); return l != r }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
2009-09-01 23:57:53 -06:00
|
|
|
log.Crashf("unexpected type %v at %v", l.t, a.pos);
|
2009-09-01 12:51:33 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 13:03:20 -06:00
|
|
|
func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
|
2009-09-01 12:51:33 -06:00
|
|
|
switch _ := lt.lit().(type) {
|
|
|
|
case *boolType:
|
|
|
|
rf := r.asBool();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(BoolValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *uintType:
|
|
|
|
rf := r.asUint();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(UintValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *intType:
|
|
|
|
rf := r.asInt();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(IntValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *floatType:
|
|
|
|
rf := r.asFloat();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(FloatValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *stringType:
|
|
|
|
rf := r.asString();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(StringValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *ArrayType:
|
|
|
|
rf := r.asArray();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.Assign(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *StructType:
|
|
|
|
rf := r.asStruct();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.Assign(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *PtrType:
|
|
|
|
rf := r.asPtr();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(PtrValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *FuncType:
|
|
|
|
rf := r.asFunc();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(FuncValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *SliceType:
|
|
|
|
rf := r.asSlice();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(SliceValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
case *MapType:
|
|
|
|
rf := r.asMap();
|
2009-09-03 18:14:49 -06:00
|
|
|
return func(lv Value, t *Thread) { lv.(MapValue).Set(t, rf(t)) }
|
2009-09-01 12:51:33 -06:00
|
|
|
default:
|
|
|
|
log.Crashf("unexpected left operand type %v at %v", lt, r.pos);
|
|
|
|
}
|
|
|
|
panic();
|
|
|
|
}
|