lang: core, funcs: Rename things for consistency

Seems we had different patterns going on. This makes those all
consistent now.
This commit is contained in:
James Shubin
2025-03-26 19:06:20 -04:00
parent 30aca74089
commit 8ff187b4e9
8 changed files with 41 additions and 42 deletions

View File

@@ -164,7 +164,7 @@ func (obj *ListConcatFunc) Build(typ *types.Type) (*types.Type, error) {
obj.Type = tList // list type obj.Type = tList // list type
fn := &types.FuncValue{ fn := &types.FuncValue{
T: typ, T: typ,
V: obj.Function, // implementation V: obj.Call, // implementation
} }
obj.Fn = fn // inside wrapper.Func obj.Fn = fn // inside wrapper.Func
//return obj.Fn.T, nil //return obj.Fn.T, nil
@@ -183,12 +183,12 @@ func (obj *ListConcatFunc) Copy() interfaces.Func {
} }
} }
// Function is the actual implementation here. This is used in lieu of the // Call this function with the input args and return the value if it is possible
// Stream function which we'd have these contents within. // to do so at this time.
func (obj *ListConcatFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *ListConcatFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
values := []types.Value{} values := []types.Value{}
for _, x := range input { for _, x := range args {
values = append(values, x.List()...) values = append(values, x.List()...)
} }

View File

@@ -208,7 +208,7 @@ func (obj *ListLookupFunc) Build(typ *types.Type) (*types.Type, error) {
obj.Type = tList // list type obj.Type = tList // list type
fn := &types.FuncValue{ fn := &types.FuncValue{
T: typ, T: typ,
V: obj.Function, // implementation V: obj.Call, // implementation
} }
obj.Fn = fn // inside wrapper.Func obj.Fn = fn // inside wrapper.Func
//return obj.Fn.T, nil //return obj.Fn.T, nil
@@ -227,11 +227,11 @@ func (obj *ListLookupFunc) Copy() interfaces.Func {
} }
} }
// Function is the actual implementation here. This is used in lieu of the // Call is the actual implementation here. This is used in lieu of the Stream
// Stream function which we'd have these contents within. // function which we'd have these contents within.
func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *ListLookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
l := (input[0]).(*types.ListValue) l := (args[0]).(*types.ListValue)
index := input[1].Int() index := args[1].Int()
//zero := l.Type().Val.New() // the zero value //zero := l.Type().Val.New() // the zero value
// TODO: should we handle overflow by returning zero? // TODO: should we handle overflow by returning zero?
@@ -247,8 +247,8 @@ func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (t
if exists { if exists {
return val, nil return val, nil
} }
if len(input) == 3 { // default value since lookup is missing if len(args) == 3 { // default value since lookup is missing
return input[2], nil return args[2], nil
} }
return nil, fmt.Errorf("list index not present, got: %d, len is: %d", index, len(l.List())) return nil, fmt.Errorf("list index not present, got: %d, len is: %d", index, len(l.List()))

View File

@@ -155,12 +155,12 @@ func (obj *PoolFunc) Stream(ctx context.Context) error {
// Call this function with the input args and return the value if it is possible // Call this function with the input args and return the value if it is possible
// to do so at this time. // to do so at this time.
func (obj *PoolFunc) Call(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *PoolFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
// Validation of these inputs happens in the Local API which does it. // Validation of these inputs happens in the Local API which does it.
namespace := input[0].Str() namespace := args[0].Str()
uid := input[1].Str() uid := args[1].Str()
// TODO: pass in config // TODO: pass in config
//config := input[2].???() //config := args[2].???()
result, err := obj.init.Local.Pool(ctx, namespace, uid, nil) result, err := obj.init.Local.Pool(ctx, namespace, uid, nil)
if err != nil { if err != nil {

View File

@@ -162,8 +162,8 @@ func (obj *VarDirFunc) Stream(ctx context.Context) error {
// Call this function with the input args and return the value if it is possible // Call this function with the input args and return the value if it is possible
// to do so at this time. // to do so at this time.
func (obj *VarDirFunc) Call(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *VarDirFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
reldir := input[0].Str() reldir := args[0].Str()
if strings.HasPrefix(reldir, "/") { if strings.HasPrefix(reldir, "/") {
return nil, fmt.Errorf("path must be relative") return nil, fmt.Errorf("path must be relative")
} }

View File

@@ -210,7 +210,7 @@ func (obj *MapLookupFunc) Build(typ *types.Type) (*types.Type, error) {
obj.Type = tMap // map type obj.Type = tMap // map type
fn := &types.FuncValue{ fn := &types.FuncValue{
T: typ, T: typ,
V: obj.Function, // implementation V: obj.Call, // implementation
} }
obj.Fn = fn // inside wrapper.Func obj.Fn = fn // inside wrapper.Func
//return obj.Fn.T, nil //return obj.Fn.T, nil
@@ -229,19 +229,19 @@ func (obj *MapLookupFunc) Copy() interfaces.Func {
} }
} }
// Function is the actual implementation here. This is used in lieu of the // Call is the actual implementation here. This is used in lieu of the Stream
// Stream function which we'd have these contents within. // function which we'd have these contents within.
func (obj *MapLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { func (obj *MapLookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {
m := (input[0]).(*types.MapValue) m := (args[0]).(*types.MapValue)
key := input[1] key := args[1]
//zero := m.Type().Val.New() // the zero value //zero := m.Type().Val.New() // the zero value
val, exists := m.Lookup(key) val, exists := m.Lookup(key)
if exists { if exists {
return val, nil return val, nil
} }
if len(input) == 3 { // default value since lookup is missing if len(args) == 3 { // default value since lookup is missing
return input[2], nil return args[2], nil
} }
return nil, fmt.Errorf("map key not present, got: %v", key) return nil, fmt.Errorf("map key not present, got: %v", key)

View File

@@ -66,26 +66,26 @@ func init() {
} }
func TestpkgAllKind(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgAllKind(ctx context.Context, args []types.Value) (types.Value, error) {
return &types.FloatValue{ return &types.FloatValue{
V: testpkg.AllKind(input[0].Int(), input[1].Str()), V: testpkg.AllKind(args[0].Int(), args[1].Str()),
}, nil }, nil
} }
func TestpkgToUpper(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgToUpper(ctx context.Context, args []types.Value) (types.Value, error) {
return &types.StrValue{ return &types.StrValue{
V: testpkg.ToUpper(input[0].Str()), V: testpkg.ToUpper(args[0].Str()),
}, nil }, nil
} }
func TestpkgMax(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgMax(ctx context.Context, args []types.Value) (types.Value, error) {
return &types.FloatValue{ return &types.FloatValue{
V: testpkg.Max(input[0].Float(), input[1].Float()), V: testpkg.Max(args[0].Float(), args[1].Float()),
}, nil }, nil
} }
func TestpkgWithError(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgWithError(ctx context.Context, args []types.Value) (types.Value, error) {
v, err := testpkg.WithError(input[0].Str()) v, err := testpkg.WithError(args[0].Str())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -94,14 +94,14 @@ func TestpkgWithError(ctx context.Context, input []types.Value) (types.Value, er
}, nil }, nil
} }
func TestpkgWithInt(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgWithInt(ctx context.Context, args []types.Value) (types.Value, error) {
return &types.StrValue{ return &types.StrValue{
V: testpkg.WithInt(input[0].Float(), int(input[1].Int()), input[2].Int(), int(input[3].Int()), int(input[4].Int()), input[5].Bool(), input[6].Str()), V: testpkg.WithInt(args[0].Float(), int(args[1].Int()), args[2].Int(), int(args[3].Int()), int(args[4].Int()), args[5].Bool(), args[6].Str()),
}, nil }, nil
} }
func TestpkgSuperByte(ctx context.Context, input []types.Value) (types.Value, error) { func TestpkgSuperByte(ctx context.Context, args []types.Value) (types.Value, error) {
return &types.StrValue{ return &types.StrValue{
V: string(testpkg.SuperByte([]byte(input[0].Str()), input[1].Str())), V: string(testpkg.SuperByte([]byte(args[0].Str()), args[1].Str())),
}, nil }, nil
} }

View File

@@ -112,8 +112,7 @@ func generateTemplate(c config, f functions, path, templateFile, finalName strin
func (obj *function) MakeGolangArgs() (string, error) { func (obj *function) MakeGolangArgs() (string, error) {
var args []string var args []string
for i, a := range obj.Args { for i, a := range obj.Args {
input := fmt.Sprintf("input[%d]", i) gol, err := a.ToGolang(fmt.Sprintf("args[%d]", i))
gol, err := a.ToGolang(input)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@@ -46,7 +46,7 @@ func init() {
{{ end }} {{ end }}
} }
{{ range $i, $func := .Functions }} {{ range $i, $func := .Functions }}
{{$func.Help}}func {{$func.InternalName}}(ctx context.Context, input []types.Value) (types.Value, error) { {{$func.Help}}func {{$func.InternalName}}(ctx context.Context, args []types.Value) (types.Value, error) {
{{- if $func.Errorful }} {{- if $func.Errorful }}
v, err := {{ if not (eq $func.GolangPackage.Alias "") }}{{$func.GolangPackage.Alias}}{{else}}{{$func.GolangPackage.Name}}{{end}}.{{$func.GolangFunc}}({{$func.MakeGolangArgs}}) v, err := {{ if not (eq $func.GolangPackage.Alias "") }}{{$func.GolangPackage.Alias}}{{else}}{{$func.GolangPackage.Name}}{{end}}.{{$func.GolangFunc}}({{$func.MakeGolangArgs}})
if err != nil { if err != nil {