// a function that expects an l-value and the frame in which to
// evaluate the RHS expressions. The l-value must have exactly the
// type given by lt. Returns nil if type checking fails.
-func (a *assignCompiler) compile(b *block, lt Type) (func(Value, *Thread)) {
+func (a *assignCompiler) compile(b *block, lt Type) func(Value, *Thread) {
lmt, isMT := lt.(*MultiType)
rmt, isUnpack := a.rmt, a.isUnpack
// compileAssign compiles an assignment operation without the full
// generality of an assignCompiler. See assignCompiler for a
// description of the arguments.
-func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) (func(Value, *Thread)) {
+func (a *compiler) compileAssign(pos token.Position, b *block, lt Type, rs []*expr, errOp, errPosName string) func(Value, *Thread) {
ac, ok := a.checkAssign(pos, rs, errOp, errPosName)
if !ok {
return nil
// TODO(austin) Now that the expression compiler works on
// semantic values instead of AST's, there should be a much
// better way of doing this.
- var find func(Type, int, string) (func(*expr) *expr)
- find = func(t Type, depth int, pathName string) (func(*expr) *expr) {
+ var find func(Type, int, string) func(*expr) *expr
+ find = func(t Type, depth int, pathName string) func(*expr) *expr {
// Don't bother looking if we've found something shallower
if bestDepth != -1 && bestDepth < depth {
return nil
* "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) }
-func (a *expr) asUint() (func(*Thread) uint64) {
- return a.eval.(func(*Thread) uint64)
-}
-func (a *expr) asInt() (func(*Thread) int64) { return a.eval.(func(*Thread) int64) }
-func (a *expr) asIdealInt() (func() *bignum.Integer) {
+func (a *expr) asBool() func(*Thread) bool { return a.eval.(func(*Thread) bool) }
+func (a *expr) asUint() func(*Thread) uint64 { return a.eval.(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) asFloat() (func(*Thread) float64) {
+func (a *expr) asFloat() func(*Thread) float64 {
return a.eval.(func(*Thread) float64)
}
-func (a *expr) asIdealFloat() (func() *bignum.Rational) {
+func (a *expr) asIdealFloat() func() *bignum.Rational {
return a.eval.(func() *bignum.Rational)
}
-func (a *expr) asString() (func(*Thread) string) {
+func (a *expr) asString() func(*Thread) string {
return a.eval.(func(*Thread) string)
}
-func (a *expr) asArray() (func(*Thread) ArrayValue) {
+func (a *expr) asArray() func(*Thread) ArrayValue {
return a.eval.(func(*Thread) ArrayValue)
}
-func (a *expr) asStruct() (func(*Thread) StructValue) {
+func (a *expr) asStruct() func(*Thread) StructValue {
return a.eval.(func(*Thread) StructValue)
}
-func (a *expr) asPtr() (func(*Thread) Value) { return a.eval.(func(*Thread) Value) }
-func (a *expr) asFunc() (func(*Thread) Func) { return a.eval.(func(*Thread) Func) }
-func (a *expr) asSlice() (func(*Thread) Slice) {
- return a.eval.(func(*Thread) Slice)
-}
-func (a *expr) asMap() (func(*Thread) Map) { return a.eval.(func(*Thread) Map) }
-func (a *expr) asMulti() (func(*Thread) []Value) {
+func (a *expr) asPtr() func(*Thread) Value { return a.eval.(func(*Thread) Value) }
+func (a *expr) asFunc() func(*Thread) Func { return a.eval.(func(*Thread) Func) }
+func (a *expr) asSlice() func(*Thread) Slice { return a.eval.(func(*Thread) Slice) }
+func (a *expr) asMap() func(*Thread) Map { return a.eval.(func(*Thread) Map) }
+func (a *expr) asMulti() func(*Thread) []Value {
return a.eval.(func(*Thread) []Value)
}
-func (a *expr) asInterface() (func(*Thread) interface{}) {
+func (a *expr) asInterface() func(*Thread) interface{} {
switch sf := a.eval.(type) {
case func(t *Thread) bool:
return func(t *Thread) interface{} { return sf(t) }
}
}
-func genAssign(lt Type, r *expr) (func(lv Value, t *Thread)) {
+func genAssign(lt Type, r *expr) func(lv Value, t *Thread) {
switch lt.lit().(type) {
case *boolType:
rf := r.asBool()
* Function compiler
*/
-func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) (func(*Thread) Func) {
+func (a *compiler) compileFunc(b *block, decl *FuncDecl, body *ast.BlockStmt) func(*Thread) Func {
// Create body scope
//
// The scope of a parameter or result is the body of the
Iter() <-chan interface{}
}
-func not(f func(interface{}) bool) (func(interface{}) bool) {
+func not(f func(interface{}) bool) func(interface{}) bool {
return func(e interface{}) bool { return !f(e) }
}
p.parameters(params, multiLine)
if result != nil {
p.print(blank)
-
if len(result) == 1 && result[0].Names == nil {
- // single anonymous result; no ()'s unless it's a function type
- f := result[0]
- if _, isFtyp := f.Type.(*ast.FuncType); !isFtyp {
- p.expr(f.Type, multiLine)
- return
- }
+ // single anonymous result; no ()'s
+ p.expr(result[0].Type, multiLine)
+ return
}
-
p.parameters(result, multiLine)
}
- return
}
}
+// formatting of function results
+func _() func() {}
+func _() func(int) { return nil }
+func _() func(int) int { return nil }
+func _() func(int) func(int) func() { return nil }
+
+
// formatting of consecutive single-line functions
func _() {}
func _() {}
}
+// formatting of function results
+func _() func() {}
+func _() func(int) { return nil }
+func _() func(int) int { return nil }
+func _() func(int) func(int) func() { return nil }
+
+
// formatting of consecutive single-line functions
func _() {}
func _() {}
},
pair{struct {
x (interface {
- a(func(func(int) int) (func(func(int)) int))
+ a(func(func(int) int) func(func(int)) int)
b()
})
}{},
return fmt.Sprint(i + 1)
}
-func writer(f func(interface{}) string) (func(io.Writer, interface{}, string)) {
+func writer(f func(interface{}) string) func(io.Writer, interface{}, string) {
return func(w io.Writer, v interface{}, format string) {
io.WriteString(w, f(v))
}