lang: ast: Refactor to unindent slightly

This commit is contained in:
James Shubin
2025-04-27 22:19:14 -04:00
parent 16d3e3063c
commit fb6eae184a

View File

@@ -9857,8 +9857,7 @@ func (obj *ExprFunc) Graph(env *interfaces.Env) (*pgraph.Graph, interfaces.Func,
//return nil, funcs.ErrCantSpeculate
return nil, fmt.Errorf("not implemented")
}
funcValueFunc = structs.FuncValueToConstFunc(&full.FuncValue{
V: func(innerTxn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
v := func(innerTxn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
// Extend the environment with the arguments.
extendedEnv := env.Copy() // TODO: Should we copy?
for i := range obj.Args {
@@ -9893,7 +9892,9 @@ func (obj *ExprFunc) Graph(env *interfaces.Env) (*pgraph.Graph, interfaces.Func,
innerTxn.AddGraph(subgraph)
return bodyFunc, nil
},
}
funcValueFunc = structs.FuncValueToConstFunc(&full.FuncValue{
V: v,
F: f,
T: obj.typ,
})
@@ -9902,21 +9903,16 @@ func (obj *ExprFunc) Graph(env *interfaces.Env) (*pgraph.Graph, interfaces.Func,
// can use that directly. We don't need to copy it because we
// expect anything that is Callable to be stateless, and so it
// can use the same function call for every instantiation of it.
var fn interfaces.FuncSig
var f interfaces.FuncSig
callableFunc, ok := obj.function.(interfaces.CallableFunc)
if ok {
// XXX: this might be dead code, how do we exercise it?
// If the function is callable then the surrounding
// ExprCall will produce a graph containing this func
// instead of calling ExprFunc.Graph().
fn = callableFunc.Call
f = callableFunc.Call
}
// obj.function is a node which transforms input values into
// an output value, but we need to construct a node which takes no
// inputs and produces a FuncValue, so we need to wrap it.
funcValueFunc = structs.FuncValueToConstFunc(&full.FuncValue{
V: func(txn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
v := func(txn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
// Copy obj.function so that the underlying ExprFunc.function gets
// refreshed with a new ExprFunc.Function() call. Otherwise, multiple
// calls to this function will share the same Func.
@@ -9938,8 +9934,14 @@ func (obj *ExprFunc) Graph(env *interfaces.Env) (*pgraph.Graph, interfaces.Func,
})
}
return valueTransformingFunc, nil
},
F: fn,
}
// obj.function is a node which transforms input values into
// an output value, but we need to construct a node which takes no
// inputs and produces a FuncValue, so we need to wrap it.
funcValueFunc = structs.FuncValueToConstFunc(&full.FuncValue{
V: v,
F: f,
T: obj.typ,
})
} else /* len(obj.Values) > 0 */ {
@@ -10012,9 +10014,7 @@ func (obj *ExprFunc) Value() (types.Value, error) {
//return nil, fmt.Errorf("not implemented")
return nil, funcs.ErrCantSpeculate
}
return &full.FuncValue{
V: func(innerTxn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
v := func(innerTxn interfaces.Txn, args []interfaces.Func) (interfaces.Func, error) {
// There are no ExprParams, so we start with the empty environment.
// Extend that environment with the arguments.
extendedEnv := interfaces.EmptyEnv()
@@ -10058,7 +10058,10 @@ func (obj *ExprFunc) Value() (types.Value, error) {
innerTxn.AddGraph(subgraph)
return bodyFunc, nil
},
}
return &full.FuncValue{
V: v,
F: f,
T: obj.typ,
}, nil