From 8ff187b4e9e49764c6e2427ac3bc5490740ac41e Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 26 Mar 2025 19:06:20 -0400 Subject: [PATCH] lang: core, funcs: Rename things for consistency Seems we had different patterns going on. This makes those all consistent now. --- lang/core/list/list_concat.go | 10 ++++---- lang/core/list/list_lookup.go | 16 ++++++------- lang/core/local/pool.go | 8 +++---- lang/core/local/vardir.go | 4 ++-- lang/core/map/map_lookup.go | 16 ++++++------- lang/funcs/funcgen/fixtures/func_base.tpl | 24 +++++++++---------- lang/funcs/funcgen/func.go | 3 +-- .../funcgen/templates/generated_funcs.go.tpl | 2 +- 8 files changed, 41 insertions(+), 42 deletions(-) diff --git a/lang/core/list/list_concat.go b/lang/core/list/list_concat.go index 84c2e011..3dc20256 100644 --- a/lang/core/list/list_concat.go +++ b/lang/core/list/list_concat.go @@ -164,7 +164,7 @@ func (obj *ListConcatFunc) Build(typ *types.Type) (*types.Type, error) { obj.Type = tList // list type fn := &types.FuncValue{ T: typ, - V: obj.Function, // implementation + V: obj.Call, // implementation } obj.Fn = fn // inside wrapper.Func //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 -// Stream function which we'd have these contents within. -func (obj *ListConcatFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { +// Call this function with the input args and return the value if it is possible +// to do so at this time. +func (obj *ListConcatFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { values := []types.Value{} - for _, x := range input { + for _, x := range args { values = append(values, x.List()...) } diff --git a/lang/core/list/list_lookup.go b/lang/core/list/list_lookup.go index fdcff68b..bfef16d2 100644 --- a/lang/core/list/list_lookup.go +++ b/lang/core/list/list_lookup.go @@ -208,7 +208,7 @@ func (obj *ListLookupFunc) Build(typ *types.Type) (*types.Type, error) { obj.Type = tList // list type fn := &types.FuncValue{ T: typ, - V: obj.Function, // implementation + V: obj.Call, // implementation } obj.Fn = fn // inside wrapper.Func //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 -// Stream function which we'd have these contents within. -func (obj *ListLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { - l := (input[0]).(*types.ListValue) - index := input[1].Int() +// Call is the actual implementation here. This is used in lieu of the Stream +// function which we'd have these contents within. +func (obj *ListLookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { + l := (args[0]).(*types.ListValue) + index := args[1].Int() //zero := l.Type().Val.New() // the zero value // 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 { return val, nil } - if len(input) == 3 { // default value since lookup is missing - return input[2], nil + if len(args) == 3 { // default value since lookup is missing + return args[2], nil } return nil, fmt.Errorf("list index not present, got: %d, len is: %d", index, len(l.List())) diff --git a/lang/core/local/pool.go b/lang/core/local/pool.go index 4faaec25..21e4d17c 100644 --- a/lang/core/local/pool.go +++ b/lang/core/local/pool.go @@ -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 // 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. - namespace := input[0].Str() - uid := input[1].Str() + namespace := args[0].Str() + uid := args[1].Str() // TODO: pass in config - //config := input[2].???() + //config := args[2].???() result, err := obj.init.Local.Pool(ctx, namespace, uid, nil) if err != nil { diff --git a/lang/core/local/vardir.go b/lang/core/local/vardir.go index 7352ff57..07c02da8 100644 --- a/lang/core/local/vardir.go +++ b/lang/core/local/vardir.go @@ -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 // to do so at this time. -func (obj *VarDirFunc) Call(ctx context.Context, input []types.Value) (types.Value, error) { - reldir := input[0].Str() +func (obj *VarDirFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { + reldir := args[0].Str() if strings.HasPrefix(reldir, "/") { return nil, fmt.Errorf("path must be relative") } diff --git a/lang/core/map/map_lookup.go b/lang/core/map/map_lookup.go index b5cef9da..fea955e6 100644 --- a/lang/core/map/map_lookup.go +++ b/lang/core/map/map_lookup.go @@ -210,7 +210,7 @@ func (obj *MapLookupFunc) Build(typ *types.Type) (*types.Type, error) { obj.Type = tMap // map type fn := &types.FuncValue{ T: typ, - V: obj.Function, // implementation + V: obj.Call, // implementation } obj.Fn = fn // inside wrapper.Func //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 -// Stream function which we'd have these contents within. -func (obj *MapLookupFunc) Function(ctx context.Context, input []types.Value) (types.Value, error) { - m := (input[0]).(*types.MapValue) - key := input[1] +// Call is the actual implementation here. This is used in lieu of the Stream +// function which we'd have these contents within. +func (obj *MapLookupFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) { + m := (args[0]).(*types.MapValue) + key := args[1] //zero := m.Type().Val.New() // the zero value val, exists := m.Lookup(key) if exists { return val, nil } - if len(input) == 3 { // default value since lookup is missing - return input[2], nil + if len(args) == 3 { // default value since lookup is missing + return args[2], nil } return nil, fmt.Errorf("map key not present, got: %v", key) diff --git a/lang/funcs/funcgen/fixtures/func_base.tpl b/lang/funcs/funcgen/fixtures/func_base.tpl index 19867878..db992dd3 100644 --- a/lang/funcs/funcgen/fixtures/func_base.tpl +++ b/lang/funcs/funcgen/fixtures/func_base.tpl @@ -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{ - V: testpkg.AllKind(input[0].Int(), input[1].Str()), + V: testpkg.AllKind(args[0].Int(), args[1].Str()), }, 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{ - V: testpkg.ToUpper(input[0].Str()), + V: testpkg.ToUpper(args[0].Str()), }, 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{ - V: testpkg.Max(input[0].Float(), input[1].Float()), + V: testpkg.Max(args[0].Float(), args[1].Float()), }, nil } -func TestpkgWithError(ctx context.Context, input []types.Value) (types.Value, error) { - v, err := testpkg.WithError(input[0].Str()) +func TestpkgWithError(ctx context.Context, args []types.Value) (types.Value, error) { + v, err := testpkg.WithError(args[0].Str()) if err != nil { return nil, err } @@ -94,14 +94,14 @@ func TestpkgWithError(ctx context.Context, input []types.Value) (types.Value, er }, 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{ - 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 } -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{ - V: string(testpkg.SuperByte([]byte(input[0].Str()), input[1].Str())), + V: string(testpkg.SuperByte([]byte(args[0].Str()), args[1].Str())), }, nil } diff --git a/lang/funcs/funcgen/func.go b/lang/funcs/funcgen/func.go index 8ab3bad9..e6e6e03d 100644 --- a/lang/funcs/funcgen/func.go +++ b/lang/funcs/funcgen/func.go @@ -112,8 +112,7 @@ func generateTemplate(c config, f functions, path, templateFile, finalName strin func (obj *function) MakeGolangArgs() (string, error) { var args []string for i, a := range obj.Args { - input := fmt.Sprintf("input[%d]", i) - gol, err := a.ToGolang(input) + gol, err := a.ToGolang(fmt.Sprintf("args[%d]", i)) if err != nil { return "", err } diff --git a/lang/funcs/funcgen/templates/generated_funcs.go.tpl b/lang/funcs/funcgen/templates/generated_funcs.go.tpl index 4a4fde00..4cca6bf8 100644 --- a/lang/funcs/funcgen/templates/generated_funcs.go.tpl +++ b/lang/funcs/funcgen/templates/generated_funcs.go.tpl @@ -46,7 +46,7 @@ func init() { {{ end }} } {{ 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 }} v, err := {{ if not (eq $func.GolangPackage.Alias "") }}{{$func.GolangPackage.Alias}}{{else}}{{$func.GolangPackage.Name}}{{end}}.{{$func.GolangFunc}}({{$func.MakeGolangArgs}}) if err != nil {