eval: getCaller -> mustCaller

This commit is contained in:
Qi Xiao 2016-02-15 14:54:41 +01:00
parent 5219fbcbdf
commit a2635d78b7
2 changed files with 13 additions and 6 deletions

View File

@ -26,15 +26,22 @@ type Caller interface {
Call(ec *EvalCtx, args []Value)
}
func getCaller(v Value) Caller {
func mustCaller(v Value) Caller {
caller, ok := getCaller(v)
if !ok {
throw(fmt.Errorf("a %s is not callable", v.Kind()))
}
return caller
}
func getCaller(v Value) (Caller, bool) {
if caller, ok := v.(Caller); ok {
return caller
return caller, true
}
if indexer, ok := getIndexer(v); ok {
return IndexerCaller{indexer}
return IndexerCaller{indexer}, true
}
throw(fmt.Errorf("a %s is not callable", v.Kind()))
panic("unreachable")
return nil, false
}
func (ec *EvalCtx) PCall(f Caller, args []Value) (ex error) {

View File

@ -237,7 +237,7 @@ func (cp *compiler) form(n *parse.Form) Op {
headValues := headOp(ec)
headMust := ec.must(headValues, "the head of command", p)
headMust.mustLen(1)
headCaller := getCaller(headValues[0])
headCaller := mustCaller(headValues[0])
// args
var args []Value