New interface and implementation to model function parameters
This commit is contained in:
+11
-9
@@ -31,18 +31,20 @@ func evalAssign(ctx ExprContext, self *term) (v any, err error) {
|
||||
|
||||
if v, err = rightChild.compute(ctx); err == nil {
|
||||
if functor, ok := v.(Functor); ok {
|
||||
var minArgs, maxArgs int = 0, -1
|
||||
|
||||
funcName := rightChild.source()
|
||||
if info, exists := ctx.GetFuncInfo(funcName); exists {
|
||||
minArgs = info.MinArgs()
|
||||
maxArgs = info.MaxArgs()
|
||||
if info, exists, _ := GetFuncInfo(ctx, funcName); exists {
|
||||
// ctx.RegisterFuncInfo(info)
|
||||
ctx.RegisterFunc2(leftTerm.source(), info.Functor(), info.ReturnType(), info.Params())
|
||||
} else if funcDef, ok := functor.(*funcDefFunctor); ok {
|
||||
l := len(funcDef.params)
|
||||
minArgs = l
|
||||
maxArgs = l
|
||||
paramCount := len(funcDef.params)
|
||||
paramSpecs := make([]ExprFuncParam, paramCount)
|
||||
for i := range paramSpecs {
|
||||
paramSpecs[i] = newFuncParam(funcDef.params[i])
|
||||
}
|
||||
ctx.RegisterFunc2(leftTerm.source(), functor, typeAny, paramSpecs)
|
||||
} else {
|
||||
err = self.Errorf("unknown function %s()", funcName)
|
||||
}
|
||||
ctx.RegisterFunc(leftTerm.source(), functor, minArgs, maxArgs)
|
||||
} else {
|
||||
ctx.UnsafeSetVar(leftTerm.source(), v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user