lang: ast, funcs: Start plumbing through the textarea
We need to get these everywhere and this is a start.
This commit is contained in:
@@ -3960,6 +3960,8 @@ func (obj *StmtFor) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
|
||||
extendedEnv.Variables[obj.indexParam.envKey] = &interfaces.FuncSingleton{
|
||||
MakeFunc: func() (*pgraph.Graph, interfaces.Func, error) {
|
||||
f := &structs.ConstFunc{
|
||||
Textarea: obj.Textarea, // XXX: advance by `for ` chars?
|
||||
|
||||
Value: &types.IntValue{
|
||||
V: int64(index),
|
||||
},
|
||||
@@ -4022,6 +4024,8 @@ func (obj *StmtFor) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
|
||||
// Add a vertex for the list passing itself.
|
||||
edgeName := structs.ForFuncArgNameList
|
||||
forFunc := &structs.ForFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
IndexType: obj.indexParam.typ,
|
||||
ValueType: obj.valueParam.typ,
|
||||
|
||||
@@ -4522,6 +4526,8 @@ func (obj *StmtForKV) Graph(env *interfaces.Env) (*pgraph.Graph, error) {
|
||||
// Add a vertex for the map passing itself.
|
||||
edgeName := structs.ForKVFuncArgNameMap
|
||||
forKVFunc := &structs.ForKVFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
KeyType: obj.keyParam.typ,
|
||||
ValType: obj.valParam.typ,
|
||||
|
||||
@@ -7415,6 +7421,8 @@ func (obj *ExprBool) Check(typ *types.Type) ([]*interfaces.UnificationInvariant,
|
||||
// Func returns the reactive stream of values that this expression produces.
|
||||
func (obj *ExprBool) Func() (interfaces.Func, error) {
|
||||
return &structs.ConstFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Value: &types.BoolValue{V: obj.V},
|
||||
}, nil
|
||||
}
|
||||
@@ -7612,6 +7620,8 @@ func (obj *ExprStr) Check(typ *types.Type) ([]*interfaces.UnificationInvariant,
|
||||
// Func returns the reactive stream of values that this expression produces.
|
||||
func (obj *ExprStr) Func() (interfaces.Func, error) {
|
||||
return &structs.ConstFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Value: &types.StrValue{V: obj.V},
|
||||
}, nil
|
||||
}
|
||||
@@ -7765,6 +7775,8 @@ func (obj *ExprInt) Check(typ *types.Type) ([]*interfaces.UnificationInvariant,
|
||||
// Func returns the reactive stream of values that this expression produces.
|
||||
func (obj *ExprInt) Func() (interfaces.Func, error) {
|
||||
return &structs.ConstFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Value: &types.IntValue{V: obj.V},
|
||||
}, nil
|
||||
}
|
||||
@@ -7920,6 +7932,8 @@ func (obj *ExprFloat) Check(typ *types.Type) ([]*interfaces.UnificationInvariant
|
||||
// Func returns the reactive stream of values that this expression produces.
|
||||
func (obj *ExprFloat) Func() (interfaces.Func, error) {
|
||||
return &structs.ConstFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Value: &types.FloatValue{V: obj.V},
|
||||
}, nil
|
||||
}
|
||||
@@ -8231,6 +8245,8 @@ func (obj *ExprList) Func() (interfaces.Func, error) {
|
||||
|
||||
// composite func (list, map, struct)
|
||||
return &structs.CompositeFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Type: typ,
|
||||
Len: len(obj.Elements),
|
||||
}, nil
|
||||
@@ -8683,6 +8699,8 @@ func (obj *ExprMap) Func() (interfaces.Func, error) {
|
||||
|
||||
// composite func (list, map, struct)
|
||||
return &structs.CompositeFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Type: typ, // the key/val types are known via this type
|
||||
Len: len(obj.KVs),
|
||||
}, nil
|
||||
@@ -9120,6 +9138,8 @@ func (obj *ExprStruct) Func() (interfaces.Func, error) {
|
||||
|
||||
// composite func (list, map, struct)
|
||||
return &structs.CompositeFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Type: typ,
|
||||
}, nil
|
||||
}
|
||||
@@ -10980,6 +11000,8 @@ func (obj *ExprCall) Graph(env *interfaces.Env) (*pgraph.Graph, interfaces.Func,
|
||||
// Add a vertex for the call itself.
|
||||
edgeName := structs.CallFuncArgNameFunction
|
||||
callFunc := &structs.CallFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Type: obj.typ,
|
||||
FuncType: ftyp,
|
||||
EdgeName: edgeName,
|
||||
@@ -12686,6 +12708,8 @@ func (obj *ExprIf) Func() (interfaces.Func, error) {
|
||||
}
|
||||
|
||||
return &structs.IfFunc{
|
||||
Textarea: obj.Textarea,
|
||||
|
||||
Type: typ, // this is the output type of the expression
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ const (
|
||||
// The arguments are connected to the received FuncValues in such a way that
|
||||
// CallFunc emits the result of applying the function to the arguments.
|
||||
type CallFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
Type *types.Type // the type of the result of applying the function
|
||||
FuncType *types.Type // the type of the function
|
||||
EdgeName string // name of the edge used
|
||||
|
||||
@@ -48,6 +48,8 @@ const (
|
||||
// value as a stream that depends on those inputs. It helps the list, map, and
|
||||
// struct's that fulfill the Expr interface but expressing a Func method.
|
||||
type CompositeFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
Type *types.Type // this is the type of the composite value we hold
|
||||
Len int // length of list or map (if used)
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ const (
|
||||
|
||||
// ConstFunc is a function that returns the constant value passed to Value.
|
||||
type ConstFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
Value types.Value
|
||||
NameHint string
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ const (
|
||||
// build a subgraph that processes each element, and in doing so we get a larger
|
||||
// function graph. This is rebuilt as necessary if the input list changes.
|
||||
type ForFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
IndexType *types.Type
|
||||
ValueType *types.Type
|
||||
|
||||
|
||||
@@ -51,6 +51,8 @@ const (
|
||||
// build a subgraph that processes each key and val, and in doing so we get a
|
||||
// larger function graph. This is rebuilt as necessary if the input map changes.
|
||||
type ForKVFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
KeyType *types.Type
|
||||
ValType *types.Type
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ const (
|
||||
// IfFunc is a function that passes through the value of the correct branch
|
||||
// based on the conditional value it gets.
|
||||
type IfFunc struct {
|
||||
interfaces.Textarea
|
||||
|
||||
Type *types.Type // this is the type of the if expression output we hold
|
||||
|
||||
init *interfaces.Init
|
||||
|
||||
@@ -45,6 +45,8 @@ import (
|
||||
// which is implemented by &ConstFunc{}.
|
||||
func FuncValueToConstFunc(fv *full.FuncValue) interfaces.Func {
|
||||
return &ConstFunc{
|
||||
//Textarea: ???, // XXX: add me!
|
||||
|
||||
Value: fv,
|
||||
NameHint: "FuncValue",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user