From 9a59d9d8cbc77e14a85664e23a02b883eb52c2a1 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sun, 10 Apr 2022 03:02:25 -0400 Subject: Fixes for structs and enums --- src/texec/eval.go | 52 +++++++++++++++++++---------------------------- src/texec/worldbuilder.go | 3 ++- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/texec/eval.go b/src/texec/eval.go index 40e2523..dff3ef2 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -789,34 +789,11 @@ func evalDotChain(v tparse.Node, ctx *VarMap) *TVariable { if wnd.Data.Data != "self" { out = &TVariable{out.Type, &(out.Data)} } - - if len(v.Sub[0].Sub) > 0 { - out = evalCIN(v.Sub[0], ctx, out) - } - - v = v.Sub[1] - if v.Data.Data == "." { - wnd = &(v.Sub[0]) - } else { - wnd = &v - } } - wrk := TArtifact{[]string{}, ""} + wrk := TArtifact{[]string{}, wnd.Data.Data} for ;; { - if out == nil { - if wrk.Name != "" { - wrk.Path = append(wrk.Path, wrk.Name) - } - wrk.Name = wnd.Data.Data - - tmp := searchDef(wrk) - if tmp != nil { - out = &TVariable{tmp.Type, &(tmp.Data)} - } - } - if len(wnd.Sub) > 0 { if out == nil { out = evalCIN(*wnd, ctx, &TVariable{TType{[]string{}, wrk, ""}, nil}) @@ -827,14 +804,8 @@ func evalDotChain(v tparse.Node, ctx *VarMap) *TVariable { } out = evalCIN(*wnd, ctx, out) } - } else if out != nil { - tmp, prs := (*(out.Data.(*interface{}))).(VarMap)[wnd.Data.Data] - if !prs { - errOutNode("Unable to find struct variable (dot)", v) - } - out = &TVariable{tmp.Type, &(tmp.Data)} } - + if v.Data.Data == "." { v = v.Sub[1] if v.Data.Data == "." { @@ -842,9 +813,28 @@ func evalDotChain(v tparse.Node, ctx *VarMap) *TVariable { } else { wnd = &v } + + wrk.Path = append(wrk.Path, wrk.Name) + wrk.Name = wnd.Data.Data + } else { break } + + if out == nil { + tmp := searchDef(wrk) + if tmp != nil { + out = &TVariable{tmp.Type, &(tmp.Data)} + } + } else if len(wnd.Sub) == 0 || wnd.Sub[0].Data.Data != "call" { + tmp, prs := (*(out.Data.(*interface{}))).(VarMap)[wnd.Data.Data] + if !prs { + fmt.Println(wnd) + fmt.Println(out) + errOutNode("Unable to find struct variable (dot)", v) + } + out = &TVariable{tmp.Type, &(tmp.Data)} + } } return out diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go index 6a5fb33..69be803 100644 --- a/src/texec/worldbuilder.go +++ b/src/texec/worldbuilder.go @@ -99,7 +99,8 @@ func modDefStruct(n tparse.Node, m *TModule) { func modDefEnum(n tparse.Node, m *TModule) { name := n.Sub[0].Data.Data - t := getType(n.Sub[1].Sub[0]) + t := getType(n.Sub[1]) + fmt.Println(t) s, vs := modDefVars(n.Sub[2], t) out := TVariable{tEnum, make(VarMap)} for i := 0; i < len(s); i++ { -- cgit v1.2.3