From 1df28c1d001a834b12986a5c865be19d9cef5b5f Mon Sep 17 00:00:00 2001 From: James Shubin Date: Fri, 6 Jun 2025 02:54:00 -0400 Subject: [PATCH] lang: ast, funcs: Start plumbing through the textarea We need to get these everywhere and this is a start. --- lang/ast/structs.go | 24 ++++++++++++++++++++++++ lang/funcs/structs/call.go | 2 ++ lang/funcs/structs/composite.go | 2 ++ lang/funcs/structs/const.go | 2 ++ lang/funcs/structs/for.go | 2 ++ lang/funcs/structs/forkv.go | 2 ++ lang/funcs/structs/if.go | 2 ++ lang/funcs/structs/util.go | 2 ++ 8 files changed, 38 insertions(+) diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 624dd56b..8662cd5c 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -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 } diff --git a/lang/funcs/structs/call.go b/lang/funcs/structs/call.go index d0a1eb62..e841f171 100644 --- a/lang/funcs/structs/call.go +++ b/lang/funcs/structs/call.go @@ -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 diff --git a/lang/funcs/structs/composite.go b/lang/funcs/structs/composite.go index eba396c0..cde6d2ce 100644 --- a/lang/funcs/structs/composite.go +++ b/lang/funcs/structs/composite.go @@ -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) diff --git a/lang/funcs/structs/const.go b/lang/funcs/structs/const.go index c9696a3b..358dfd8f 100644 --- a/lang/funcs/structs/const.go +++ b/lang/funcs/structs/const.go @@ -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 diff --git a/lang/funcs/structs/for.go b/lang/funcs/structs/for.go index c3d973a7..6956505f 100644 --- a/lang/funcs/structs/for.go +++ b/lang/funcs/structs/for.go @@ -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 diff --git a/lang/funcs/structs/forkv.go b/lang/funcs/structs/forkv.go index 6380bcf7..88dfc698 100644 --- a/lang/funcs/structs/forkv.go +++ b/lang/funcs/structs/forkv.go @@ -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 diff --git a/lang/funcs/structs/if.go b/lang/funcs/structs/if.go index a242ea67..ebee1931 100644 --- a/lang/funcs/structs/if.go +++ b/lang/funcs/structs/if.go @@ -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 diff --git a/lang/funcs/structs/util.go b/lang/funcs/structs/util.go index 819b9376..91b4f170 100644 --- a/lang/funcs/structs/util.go +++ b/lang/funcs/structs/util.go @@ -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", }