make sure mathgen outputs code which passes go fmt
This commit is contained in:
parent
f8c841fa99
commit
583e381ecb
3
Makefile
3
Makefile
@ -3,5 +3,8 @@ all: gen
|
|||||||
test: gen
|
test: gen
|
||||||
go test ./...
|
go test ./...
|
||||||
|
|
||||||
|
fmt: gen
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
gen:
|
gen:
|
||||||
(cd core && make gen)
|
(cd core && make gen)
|
||||||
|
319
core/math.go
319
core/math.go
@ -16,166 +16,132 @@ func mathReduce(fn mathReduceFn, zero types.Elem, s seq.Seq) types.Elem {
|
|||||||
return seq.Reduce(reduceFn, zero, s)
|
return seq.Reduce(reduceFn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func plusInt(a, b types.Elem) types.Elem {
|
func plusInt(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int(a) + Int(b) }
|
return types.GoType{Int(a) + Int(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusInt8(a, b types.Elem) types.Elem {
|
func plusInt8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int8(a) + Int8(b) }
|
return types.GoType{Int8(a) + Int8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusInt16(a, b types.Elem) types.Elem {
|
func plusInt16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int16(a) + Int16(b) }
|
return types.GoType{Int16(a) + Int16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusInt32(a, b types.Elem) types.Elem {
|
func plusInt32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int32(a) + Int32(b) }
|
return types.GoType{Int32(a) + Int32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusInt64(a, b types.Elem) types.Elem {
|
func plusInt64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int64(a) + Int64(b) }
|
return types.GoType{Int64(a) + Int64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusUint(a, b types.Elem) types.Elem {
|
func plusUint(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint(a) + Uint(b) }
|
return types.GoType{Uint(a) + Uint(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusUint8(a, b types.Elem) types.Elem {
|
func plusUint8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint8(a) + Uint8(b) }
|
return types.GoType{Uint8(a) + Uint8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusUint16(a, b types.Elem) types.Elem {
|
func plusUint16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint16(a) + Uint16(b) }
|
return types.GoType{Uint16(a) + Uint16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusUint32(a, b types.Elem) types.Elem {
|
func plusUint32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint32(a) + Uint32(b) }
|
return types.GoType{Uint32(a) + Uint32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusUint64(a, b types.Elem) types.Elem {
|
func plusUint64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint64(a) + Uint64(b) }
|
return types.GoType{Uint64(a) + Uint64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusFloat32(a, b types.Elem) types.Elem {
|
func plusFloat32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float32(a) + Float32(b) }
|
return types.GoType{Float32(a) + Float32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusFloat64(a, b types.Elem) types.Elem {
|
func plusFloat64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float64(a) + Float64(b) }
|
return types.GoType{Float64(a) + Float64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusComplex64(a, b types.Elem) types.Elem {
|
func plusComplex64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex64(a) + Complex64(b) }
|
return types.GoType{Complex64(a) + Complex64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func plusComplex128(a, b types.Elem) types.Elem {
|
func plusComplex128(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex128(a) + Complex128(b) }
|
return types.GoType{Complex128(a) + Complex128(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func plusString(a, b types.Elem) types.Elem {
|
func plusString(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ String(a) + String(b) }
|
return types.GoType{String(a) + String(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Plus(s seq.Seq) types.Elem {
|
func Plus(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
|
|
||||||
if seq.Empty(s) {
|
if seq.Empty(s) {
|
||||||
return types.GoType{ 0 }
|
return types.GoType{0}
|
||||||
}
|
}
|
||||||
first, _, _ = s.FirstRest()
|
first, _, _ = s.FirstRest()
|
||||||
|
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fn = plusInt
|
fn = plusInt
|
||||||
|
zero = types.GoType{int(0)}
|
||||||
zero = types.GoType{ int(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case int8:
|
case int8:
|
||||||
fn = plusInt8
|
fn = plusInt8
|
||||||
|
zero = types.GoType{int8(0)}
|
||||||
zero = types.GoType{ int8(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case int16:
|
case int16:
|
||||||
fn = plusInt16
|
fn = plusInt16
|
||||||
|
zero = types.GoType{int16(0)}
|
||||||
zero = types.GoType{ int16(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case int32:
|
case int32:
|
||||||
fn = plusInt32
|
fn = plusInt32
|
||||||
|
zero = types.GoType{int32(0)}
|
||||||
zero = types.GoType{ int32(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
fn = plusInt64
|
fn = plusInt64
|
||||||
|
zero = types.GoType{int64(0)}
|
||||||
zero = types.GoType{ int64(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint:
|
case uint:
|
||||||
fn = plusUint
|
fn = plusUint
|
||||||
|
zero = types.GoType{uint(0)}
|
||||||
zero = types.GoType{ uint(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint8:
|
case uint8:
|
||||||
fn = plusUint8
|
fn = plusUint8
|
||||||
|
zero = types.GoType{uint8(0)}
|
||||||
zero = types.GoType{ uint8(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint16:
|
case uint16:
|
||||||
fn = plusUint16
|
fn = plusUint16
|
||||||
|
zero = types.GoType{uint16(0)}
|
||||||
zero = types.GoType{ uint16(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint32:
|
case uint32:
|
||||||
fn = plusUint32
|
fn = plusUint32
|
||||||
|
zero = types.GoType{uint32(0)}
|
||||||
zero = types.GoType{ uint32(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint64:
|
case uint64:
|
||||||
fn = plusUint64
|
fn = plusUint64
|
||||||
|
zero = types.GoType{uint64(0)}
|
||||||
zero = types.GoType{ uint64(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case float32:
|
case float32:
|
||||||
fn = plusFloat32
|
fn = plusFloat32
|
||||||
|
zero = types.GoType{float32(0)}
|
||||||
zero = types.GoType{ float32(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
fn = plusFloat64
|
fn = plusFloat64
|
||||||
|
zero = types.GoType{float64(0)}
|
||||||
zero = types.GoType{ float64(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case complex64:
|
case complex64:
|
||||||
fn = plusComplex64
|
fn = plusComplex64
|
||||||
|
zero = types.GoType{complex64(0)}
|
||||||
zero = types.GoType{ complex64(0) }
|
|
||||||
|
|
||||||
|
|
||||||
case complex128:
|
case complex128:
|
||||||
fn = plusComplex128
|
fn = plusComplex128
|
||||||
|
zero = types.GoType{complex128(0)}
|
||||||
zero = types.GoType{ complex128(0) }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
fn = plusString
|
fn = plusString
|
||||||
@ -187,66 +153,62 @@ func Plus(s seq.Seq) types.Elem {
|
|||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func minusInt(a, b types.Elem) types.Elem {
|
func minusInt(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int(a) - Int(b) }
|
return types.GoType{Int(a) - Int(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusInt8(a, b types.Elem) types.Elem {
|
func minusInt8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int8(a) - Int8(b) }
|
return types.GoType{Int8(a) - Int8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusInt16(a, b types.Elem) types.Elem {
|
func minusInt16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int16(a) - Int16(b) }
|
return types.GoType{Int16(a) - Int16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusInt32(a, b types.Elem) types.Elem {
|
func minusInt32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int32(a) - Int32(b) }
|
return types.GoType{Int32(a) - Int32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusInt64(a, b types.Elem) types.Elem {
|
func minusInt64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int64(a) - Int64(b) }
|
return types.GoType{Int64(a) - Int64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusUint(a, b types.Elem) types.Elem {
|
func minusUint(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint(a) - Uint(b) }
|
return types.GoType{Uint(a) - Uint(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusUint8(a, b types.Elem) types.Elem {
|
func minusUint8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint8(a) - Uint8(b) }
|
return types.GoType{Uint8(a) - Uint8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusUint16(a, b types.Elem) types.Elem {
|
func minusUint16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint16(a) - Uint16(b) }
|
return types.GoType{Uint16(a) - Uint16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusUint32(a, b types.Elem) types.Elem {
|
func minusUint32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint32(a) - Uint32(b) }
|
return types.GoType{Uint32(a) - Uint32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusUint64(a, b types.Elem) types.Elem {
|
func minusUint64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint64(a) - Uint64(b) }
|
return types.GoType{Uint64(a) - Uint64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusFloat32(a, b types.Elem) types.Elem {
|
func minusFloat32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float32(a) - Float32(b) }
|
return types.GoType{Float32(a) - Float32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusFloat64(a, b types.Elem) types.Elem {
|
func minusFloat64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float64(a) - Float64(b) }
|
return types.GoType{Float64(a) - Float64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusComplex64(a, b types.Elem) types.Elem {
|
func minusComplex64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex64(a) - Complex64(b) }
|
return types.GoType{Complex64(a) - Complex64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func minusComplex128(a, b types.Elem) types.Elem {
|
func minusComplex128(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex128(a) - Complex128(b) }
|
return types.GoType{Complex128(a) - Complex128(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Minus(s seq.Seq) types.Elem {
|
func Minus(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
|
|
||||||
@ -256,229 +218,179 @@ func Minus(s seq.Seq) types.Elem {
|
|||||||
zero, s, _ = s.FirstRest()
|
zero, s, _ = s.FirstRest()
|
||||||
first = zero
|
first = zero
|
||||||
|
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fn = minusInt
|
fn = minusInt
|
||||||
|
|
||||||
|
|
||||||
case int8:
|
case int8:
|
||||||
fn = minusInt8
|
fn = minusInt8
|
||||||
|
|
||||||
|
|
||||||
case int16:
|
case int16:
|
||||||
fn = minusInt16
|
fn = minusInt16
|
||||||
|
|
||||||
|
|
||||||
case int32:
|
case int32:
|
||||||
fn = minusInt32
|
fn = minusInt32
|
||||||
|
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
fn = minusInt64
|
fn = minusInt64
|
||||||
|
|
||||||
|
|
||||||
case uint:
|
case uint:
|
||||||
fn = minusUint
|
fn = minusUint
|
||||||
|
|
||||||
|
|
||||||
case uint8:
|
case uint8:
|
||||||
fn = minusUint8
|
fn = minusUint8
|
||||||
|
|
||||||
|
|
||||||
case uint16:
|
case uint16:
|
||||||
fn = minusUint16
|
fn = minusUint16
|
||||||
|
|
||||||
|
|
||||||
case uint32:
|
case uint32:
|
||||||
fn = minusUint32
|
fn = minusUint32
|
||||||
|
|
||||||
|
|
||||||
case uint64:
|
case uint64:
|
||||||
fn = minusUint64
|
fn = minusUint64
|
||||||
|
|
||||||
|
|
||||||
case float32:
|
case float32:
|
||||||
fn = minusFloat32
|
fn = minusFloat32
|
||||||
|
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
fn = minusFloat64
|
fn = minusFloat64
|
||||||
|
|
||||||
|
|
||||||
case complex64:
|
case complex64:
|
||||||
fn = minusComplex64
|
fn = minusComplex64
|
||||||
|
|
||||||
|
|
||||||
case complex128:
|
case complex128:
|
||||||
fn = minusComplex128
|
fn = minusComplex128
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("$#v cannot have Minus called on it", first))
|
panic(fmt.Sprintf("$#v cannot have Minus called on it", first))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func multInt(a, b types.Elem) types.Elem {
|
func multInt(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int(a) * Int(b) }
|
return types.GoType{Int(a) * Int(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multInt8(a, b types.Elem) types.Elem {
|
func multInt8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int8(a) * Int8(b) }
|
return types.GoType{Int8(a) * Int8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multInt16(a, b types.Elem) types.Elem {
|
func multInt16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int16(a) * Int16(b) }
|
return types.GoType{Int16(a) * Int16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multInt32(a, b types.Elem) types.Elem {
|
func multInt32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int32(a) * Int32(b) }
|
return types.GoType{Int32(a) * Int32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multInt64(a, b types.Elem) types.Elem {
|
func multInt64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int64(a) * Int64(b) }
|
return types.GoType{Int64(a) * Int64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multUint(a, b types.Elem) types.Elem {
|
func multUint(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint(a) * Uint(b) }
|
return types.GoType{Uint(a) * Uint(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multUint8(a, b types.Elem) types.Elem {
|
func multUint8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint8(a) * Uint8(b) }
|
return types.GoType{Uint8(a) * Uint8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multUint16(a, b types.Elem) types.Elem {
|
func multUint16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint16(a) * Uint16(b) }
|
return types.GoType{Uint16(a) * Uint16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multUint32(a, b types.Elem) types.Elem {
|
func multUint32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint32(a) * Uint32(b) }
|
return types.GoType{Uint32(a) * Uint32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multUint64(a, b types.Elem) types.Elem {
|
func multUint64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint64(a) * Uint64(b) }
|
return types.GoType{Uint64(a) * Uint64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multFloat32(a, b types.Elem) types.Elem {
|
func multFloat32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float32(a) * Float32(b) }
|
return types.GoType{Float32(a) * Float32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multFloat64(a, b types.Elem) types.Elem {
|
func multFloat64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float64(a) * Float64(b) }
|
return types.GoType{Float64(a) * Float64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multComplex64(a, b types.Elem) types.Elem {
|
func multComplex64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex64(a) * Complex64(b) }
|
return types.GoType{Complex64(a) * Complex64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func multComplex128(a, b types.Elem) types.Elem {
|
func multComplex128(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex128(a) * Complex128(b) }
|
return types.GoType{Complex128(a) * Complex128(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Mult(s seq.Seq) types.Elem {
|
func Mult(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
|
|
||||||
if seq.Empty(s) {
|
if seq.Empty(s) {
|
||||||
return types.GoType{ 1 }
|
return types.GoType{1}
|
||||||
}
|
}
|
||||||
first, _, _ = s.FirstRest()
|
first, _, _ = s.FirstRest()
|
||||||
|
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fn = multInt
|
fn = multInt
|
||||||
|
zero = types.GoType{int(1)}
|
||||||
zero = types.GoType{ int(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case int8:
|
case int8:
|
||||||
fn = multInt8
|
fn = multInt8
|
||||||
|
zero = types.GoType{int8(1)}
|
||||||
zero = types.GoType{ int8(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case int16:
|
case int16:
|
||||||
fn = multInt16
|
fn = multInt16
|
||||||
|
zero = types.GoType{int16(1)}
|
||||||
zero = types.GoType{ int16(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case int32:
|
case int32:
|
||||||
fn = multInt32
|
fn = multInt32
|
||||||
|
zero = types.GoType{int32(1)}
|
||||||
zero = types.GoType{ int32(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
fn = multInt64
|
fn = multInt64
|
||||||
|
zero = types.GoType{int64(1)}
|
||||||
zero = types.GoType{ int64(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint:
|
case uint:
|
||||||
fn = multUint
|
fn = multUint
|
||||||
|
zero = types.GoType{uint(1)}
|
||||||
zero = types.GoType{ uint(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint8:
|
case uint8:
|
||||||
fn = multUint8
|
fn = multUint8
|
||||||
|
zero = types.GoType{uint8(1)}
|
||||||
zero = types.GoType{ uint8(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint16:
|
case uint16:
|
||||||
fn = multUint16
|
fn = multUint16
|
||||||
|
zero = types.GoType{uint16(1)}
|
||||||
zero = types.GoType{ uint16(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint32:
|
case uint32:
|
||||||
fn = multUint32
|
fn = multUint32
|
||||||
|
zero = types.GoType{uint32(1)}
|
||||||
zero = types.GoType{ uint32(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case uint64:
|
case uint64:
|
||||||
fn = multUint64
|
fn = multUint64
|
||||||
|
zero = types.GoType{uint64(1)}
|
||||||
zero = types.GoType{ uint64(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case float32:
|
case float32:
|
||||||
fn = multFloat32
|
fn = multFloat32
|
||||||
|
zero = types.GoType{float32(1)}
|
||||||
zero = types.GoType{ float32(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
fn = multFloat64
|
fn = multFloat64
|
||||||
|
zero = types.GoType{float64(1)}
|
||||||
zero = types.GoType{ float64(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case complex64:
|
case complex64:
|
||||||
fn = multComplex64
|
fn = multComplex64
|
||||||
|
zero = types.GoType{complex64(1)}
|
||||||
zero = types.GoType{ complex64(1) }
|
|
||||||
|
|
||||||
|
|
||||||
case complex128:
|
case complex128:
|
||||||
fn = multComplex128
|
fn = multComplex128
|
||||||
|
zero = types.GoType{complex128(1)}
|
||||||
zero = types.GoType{ complex128(1) }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("$#v cannot have Mult called on it", first))
|
panic(fmt.Sprintf("$#v cannot have Mult called on it", first))
|
||||||
@ -486,66 +398,62 @@ func Mult(s seq.Seq) types.Elem {
|
|||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func divInt(a, b types.Elem) types.Elem {
|
func divInt(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int(a) / Int(b) }
|
return types.GoType{Int(a) / Int(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divInt8(a, b types.Elem) types.Elem {
|
func divInt8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int8(a) / Int8(b) }
|
return types.GoType{Int8(a) / Int8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divInt16(a, b types.Elem) types.Elem {
|
func divInt16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int16(a) / Int16(b) }
|
return types.GoType{Int16(a) / Int16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divInt32(a, b types.Elem) types.Elem {
|
func divInt32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int32(a) / Int32(b) }
|
return types.GoType{Int32(a) / Int32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divInt64(a, b types.Elem) types.Elem {
|
func divInt64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int64(a) / Int64(b) }
|
return types.GoType{Int64(a) / Int64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divUint(a, b types.Elem) types.Elem {
|
func divUint(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint(a) / Uint(b) }
|
return types.GoType{Uint(a) / Uint(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divUint8(a, b types.Elem) types.Elem {
|
func divUint8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint8(a) / Uint8(b) }
|
return types.GoType{Uint8(a) / Uint8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divUint16(a, b types.Elem) types.Elem {
|
func divUint16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint16(a) / Uint16(b) }
|
return types.GoType{Uint16(a) / Uint16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divUint32(a, b types.Elem) types.Elem {
|
func divUint32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint32(a) / Uint32(b) }
|
return types.GoType{Uint32(a) / Uint32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divUint64(a, b types.Elem) types.Elem {
|
func divUint64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint64(a) / Uint64(b) }
|
return types.GoType{Uint64(a) / Uint64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divFloat32(a, b types.Elem) types.Elem {
|
func divFloat32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float32(a) / Float32(b) }
|
return types.GoType{Float32(a) / Float32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divFloat64(a, b types.Elem) types.Elem {
|
func divFloat64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Float64(a) / Float64(b) }
|
return types.GoType{Float64(a) / Float64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divComplex64(a, b types.Elem) types.Elem {
|
func divComplex64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex64(a) / Complex64(b) }
|
return types.GoType{Complex64(a) / Complex64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func divComplex128(a, b types.Elem) types.Elem {
|
func divComplex128(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Complex128(a) / Complex128(b) }
|
return types.GoType{Complex128(a) / Complex128(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Div(s seq.Seq) types.Elem {
|
func Div(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
|
|
||||||
@ -555,117 +463,97 @@ func Div(s seq.Seq) types.Elem {
|
|||||||
zero, s, _ = s.FirstRest()
|
zero, s, _ = s.FirstRest()
|
||||||
first = zero
|
first = zero
|
||||||
|
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fn = divInt
|
fn = divInt
|
||||||
|
|
||||||
|
|
||||||
case int8:
|
case int8:
|
||||||
fn = divInt8
|
fn = divInt8
|
||||||
|
|
||||||
|
|
||||||
case int16:
|
case int16:
|
||||||
fn = divInt16
|
fn = divInt16
|
||||||
|
|
||||||
|
|
||||||
case int32:
|
case int32:
|
||||||
fn = divInt32
|
fn = divInt32
|
||||||
|
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
fn = divInt64
|
fn = divInt64
|
||||||
|
|
||||||
|
|
||||||
case uint:
|
case uint:
|
||||||
fn = divUint
|
fn = divUint
|
||||||
|
|
||||||
|
|
||||||
case uint8:
|
case uint8:
|
||||||
fn = divUint8
|
fn = divUint8
|
||||||
|
|
||||||
|
|
||||||
case uint16:
|
case uint16:
|
||||||
fn = divUint16
|
fn = divUint16
|
||||||
|
|
||||||
|
|
||||||
case uint32:
|
case uint32:
|
||||||
fn = divUint32
|
fn = divUint32
|
||||||
|
|
||||||
|
|
||||||
case uint64:
|
case uint64:
|
||||||
fn = divUint64
|
fn = divUint64
|
||||||
|
|
||||||
|
|
||||||
case float32:
|
case float32:
|
||||||
fn = divFloat32
|
fn = divFloat32
|
||||||
|
|
||||||
|
|
||||||
case float64:
|
case float64:
|
||||||
fn = divFloat64
|
fn = divFloat64
|
||||||
|
|
||||||
|
|
||||||
case complex64:
|
case complex64:
|
||||||
fn = divComplex64
|
fn = divComplex64
|
||||||
|
|
||||||
|
|
||||||
case complex128:
|
case complex128:
|
||||||
fn = divComplex128
|
fn = divComplex128
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("$#v cannot have Div called on it", first))
|
panic(fmt.Sprintf("$#v cannot have Div called on it", first))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func modInt(a, b types.Elem) types.Elem {
|
func modInt(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int(a) % Int(b) }
|
return types.GoType{Int(a) % Int(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modInt8(a, b types.Elem) types.Elem {
|
func modInt8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int8(a) % Int8(b) }
|
return types.GoType{Int8(a) % Int8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modInt16(a, b types.Elem) types.Elem {
|
func modInt16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int16(a) % Int16(b) }
|
return types.GoType{Int16(a) % Int16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modInt32(a, b types.Elem) types.Elem {
|
func modInt32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int32(a) % Int32(b) }
|
return types.GoType{Int32(a) % Int32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modInt64(a, b types.Elem) types.Elem {
|
func modInt64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Int64(a) % Int64(b) }
|
return types.GoType{Int64(a) % Int64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modUint(a, b types.Elem) types.Elem {
|
func modUint(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint(a) % Uint(b) }
|
return types.GoType{Uint(a) % Uint(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modUint8(a, b types.Elem) types.Elem {
|
func modUint8(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint8(a) % Uint8(b) }
|
return types.GoType{Uint8(a) % Uint8(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modUint16(a, b types.Elem) types.Elem {
|
func modUint16(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint16(a) % Uint16(b) }
|
return types.GoType{Uint16(a) % Uint16(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modUint32(a, b types.Elem) types.Elem {
|
func modUint32(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint32(a) % Uint32(b) }
|
return types.GoType{Uint32(a) % Uint32(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func modUint64(a, b types.Elem) types.Elem {
|
func modUint64(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ Uint64(a) % Uint64(b) }
|
return types.GoType{Uint64(a) % Uint64(b)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func Mod(s seq.Seq) types.Elem {
|
func Mod(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
|
|
||||||
@ -675,55 +563,42 @@ func Mod(s seq.Seq) types.Elem {
|
|||||||
zero, s, _ = s.FirstRest()
|
zero, s, _ = s.FirstRest()
|
||||||
first = zero
|
first = zero
|
||||||
|
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
|
|
||||||
case int:
|
case int:
|
||||||
fn = modInt
|
fn = modInt
|
||||||
|
|
||||||
|
|
||||||
case int8:
|
case int8:
|
||||||
fn = modInt8
|
fn = modInt8
|
||||||
|
|
||||||
|
|
||||||
case int16:
|
case int16:
|
||||||
fn = modInt16
|
fn = modInt16
|
||||||
|
|
||||||
|
|
||||||
case int32:
|
case int32:
|
||||||
fn = modInt32
|
fn = modInt32
|
||||||
|
|
||||||
|
|
||||||
case int64:
|
case int64:
|
||||||
fn = modInt64
|
fn = modInt64
|
||||||
|
|
||||||
|
|
||||||
case uint:
|
case uint:
|
||||||
fn = modUint
|
fn = modUint
|
||||||
|
|
||||||
|
|
||||||
case uint8:
|
case uint8:
|
||||||
fn = modUint8
|
fn = modUint8
|
||||||
|
|
||||||
|
|
||||||
case uint16:
|
case uint16:
|
||||||
fn = modUint16
|
fn = modUint16
|
||||||
|
|
||||||
|
|
||||||
case uint32:
|
case uint32:
|
||||||
fn = modUint32
|
fn = modUint32
|
||||||
|
|
||||||
|
|
||||||
case uint64:
|
case uint64:
|
||||||
fn = modUint64
|
fn = modUint64
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("$#v cannot have Mod called on it", first))
|
panic(fmt.Sprintf("$#v cannot have Mod called on it", first))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,30 +15,30 @@ type MathOpType struct {
|
|||||||
// The standard types for which math operations work upon. These don't include
|
// The standard types for which math operations work upon. These don't include
|
||||||
// byte and rune because those are aliases of int8 and int32, respectively
|
// byte and rune because those are aliases of int8 and int32, respectively
|
||||||
var MathOpTypes = []MathOpType{
|
var MathOpTypes = []MathOpType{
|
||||||
{"Int", "int"},
|
{"Int", "int"},
|
||||||
{"Int8", "int8"},
|
{"Int8", "int8"},
|
||||||
{"Int16", "int16"},
|
{"Int16", "int16"},
|
||||||
{"Int32", "int32"},
|
{"Int32", "int32"},
|
||||||
{"Int64", "int64"},
|
{"Int64", "int64"},
|
||||||
{"Uint", "uint"},
|
{"Uint", "uint"},
|
||||||
{"Uint8", "uint8"},
|
{"Uint8", "uint8"},
|
||||||
{"Uint16", "uint16"},
|
{"Uint16", "uint16"},
|
||||||
{"Uint32", "uint32"},
|
{"Uint32", "uint32"},
|
||||||
{"Uint64", "uint64"},
|
{"Uint64", "uint64"},
|
||||||
{"Float32", "float32"},
|
{"Float32", "float32"},
|
||||||
{"Float64", "float64"},
|
{"Float64", "float64"},
|
||||||
{"Complex64", "complex64"},
|
{"Complex64", "complex64"},
|
||||||
{"Complex128", "complex128"},
|
{"Complex128", "complex128"},
|
||||||
}
|
}
|
||||||
|
|
||||||
var MathOpsIntOnly = []MathOpType{
|
var MathOpsIntOnly = []MathOpType{
|
||||||
{"Int", "int"},
|
{"Int", "int"},
|
||||||
{"Int8", "int8"},
|
{"Int8", "int8"},
|
||||||
{"Int16", "int16"},
|
{"Int16", "int16"},
|
||||||
{"Int32", "int32"},
|
{"Int32", "int32"},
|
||||||
{"Int64", "int64"},
|
{"Int64", "int64"},
|
||||||
{"Uint", "uint"},
|
{"Uint", "uint"},
|
||||||
{"Uint8", "uint8"},
|
{"Uint8", "uint8"},
|
||||||
{"Uint16", "uint16"},
|
{"Uint16", "uint16"},
|
||||||
{"Uint32", "uint32"},
|
{"Uint32", "uint32"},
|
||||||
{"Uint64", "uint64"},
|
{"Uint64", "uint64"},
|
||||||
@ -53,7 +53,7 @@ type MathOp struct {
|
|||||||
// Will be the first item in the reduce, and allows for the function being
|
// Will be the first item in the reduce, and allows for the function being
|
||||||
// called with an empty seq. If empty string than the first item in the
|
// called with an empty seq. If empty string than the first item in the
|
||||||
// given sequence is used and an empty sequence is not allowed
|
// given sequence is used and an empty sequence is not allowed
|
||||||
Unit string
|
Unit string
|
||||||
|
|
||||||
// This is going to be the same for all ops, it's just convenient to have
|
// This is going to be the same for all ops, it's just convenient to have
|
||||||
// here
|
// here
|
||||||
|
@ -15,52 +15,43 @@ func mathReduce(fn mathReduceFn, zero types.Elem, s seq.Seq) types.Elem {
|
|||||||
}
|
}
|
||||||
return seq.Reduce(reduceFn, zero, s)
|
return seq.Reduce(reduceFn, zero, s)
|
||||||
}
|
}
|
||||||
|
{{range .}}{{$mathOp := .}}{{range .OpTypes}}
|
||||||
{{range .}}
|
|
||||||
{{$mathOp := .}}
|
|
||||||
{{range .OpTypes}}
|
|
||||||
func {{$mathOp.Private}}{{.CastFn}}(a, b types.Elem) types.Elem {
|
func {{$mathOp.Private}}{{.CastFn}}(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ {{.CastFn}}(a) {{$mathOp.Op}} {{.CastFn}}(b) }
|
return types.GoType{{`{`}}{{.CastFn}}(a) {{$mathOp.Op}} {{.CastFn}}(b)}
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}{{if $mathOp.IncludeString}}
|
||||||
{{if $mathOp.IncludeString}}
|
|
||||||
func {{$mathOp.Private}}String(a, b types.Elem) types.Elem {
|
func {{$mathOp.Private}}String(a, b types.Elem) types.Elem {
|
||||||
return types.GoType{ String(a) {{$mathOp.Op}} String(b) }
|
return types.GoType{String(a) {{$mathOp.Op}} String(b)}
|
||||||
}
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
func {{$mathOp.Public}}(s seq.Seq) types.Elem {
|
func {{$mathOp.Public}}(s seq.Seq) types.Elem {
|
||||||
var first, zero types.Elem
|
var first, zero types.Elem
|
||||||
{{if (eq $mathOp.Unit "")}}
|
{{if (eq $mathOp.Unit "")}}
|
||||||
if seq.Empty(s) {
|
if seq.Empty(s) {
|
||||||
panic("{{$mathOp.Public}} cannot be called with no arguments")
|
panic("{{$mathOp.Public}} cannot be called with no arguments")
|
||||||
}
|
}
|
||||||
zero, s, _ = s.FirstRest()
|
zero, s, _ = s.FirstRest()
|
||||||
first = zero
|
first = zero
|
||||||
{{else}}
|
{{else}}
|
||||||
if seq.Empty(s) {
|
if seq.Empty(s) {
|
||||||
return types.GoType{ {{$mathOp.Unit}} }
|
return types.GoType{{`{`}}{{$mathOp.Unit}}}
|
||||||
}
|
}
|
||||||
first, _, _ = s.FirstRest()
|
first, _, _ = s.FirstRest()
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
var fn mathReduceFn
|
var fn mathReduceFn
|
||||||
switch first.(types.GoType).V.(type) {
|
switch first.(types.GoType).V.(type) {
|
||||||
{{range .OpTypes}}
|
{{range .OpTypes}}
|
||||||
case {{.Type}}:
|
case {{.Type}}:
|
||||||
fn = {{$mathOp.Private}}{{.CastFn}}
|
fn = {{$mathOp.Private}}{{.CastFn}}{{if (ne $mathOp.Unit "")}}
|
||||||
{{if (ne $mathOp.Unit "")}}
|
zero = types.GoType{{`{`}}{{.Type}}({{$mathOp.Unit}})}{{end}}
|
||||||
zero = types.GoType{ {{.Type}}({{$mathOp.Unit}}) }
|
{{end}}{{if $mathOp.IncludeString}}
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
{{if $mathOp.IncludeString}}
|
|
||||||
case string:
|
case string:
|
||||||
fn = {{$mathOp.Private}}String
|
fn = {{$mathOp.Private}}String
|
||||||
zero = types.GoType{string("")}
|
zero = types.GoType{string("")}
|
||||||
{{end}}
|
{{end}}
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("$#v cannot have {{$mathOp.Public}} called on it", first))
|
panic(fmt.Sprintf("$#v cannot have {{$mathOp.Public}} called on it", first))
|
||||||
}
|
}
|
||||||
|
|
||||||
return mathReduce(fn, zero, s)
|
return mathReduce(fn, zero, s)
|
||||||
}
|
}{{end}}
|
||||||
{{end}}
|
|
||||||
|
@ -51,7 +51,6 @@ func Eval(p *pkgctx.PkgCtx, el types.Elem) types.Elem {
|
|||||||
Bail(el, "Empty list after colon, no function given")
|
Bail(el, "Empty list after colon, no function given")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var fnName string
|
var fnName string
|
||||||
if gt, ok := fnEl.(types.GoType); ok {
|
if gt, ok := fnEl.(types.GoType); ok {
|
||||||
fnName, _ = gt.V.(string)
|
fnName, _ = gt.V.(string)
|
||||||
|
Loading…
Reference in New Issue
Block a user