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