summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-12-15 16:07:39 -0500
committerKyle Gunger <kgunger12@gmail.com>2021-12-15 16:07:39 -0500
commit233ea2d71548525f074ee5aa13119b32434a1ec2 (patch)
treedec16e238978d8a7e2fbf18ce6a5671202a33a0d /src
parentcd1571adfd8a734f352501d18a3731db920578cb (diff)
[EXEC] fix multi-level array and struct globals
Diffstat (limited to 'src')
-rw-r--r--src/texec/eval.go47
1 files changed, 20 insertions, 27 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go
index b4d04da..fce8f5e 100644
--- a/src/texec/eval.go
+++ b/src/texec/eval.go
@@ -260,51 +260,44 @@ func getIntLiteral(v tparse.Node) int {
return int(i)
}
-func getLiteralArray(v tparse.Node, t TType, ps int) []interface{} {
+func getCompositeLiteral(v tparse.Node) []interface{} {
out := []interface{}{}
if v.Data.Data != "comp" || v.Data.Type != 10 {
return out
}
- if equateTypePS(t, tInt, ps) {
- for i := 0; i < len(v.Sub); i++ {
- out = append(out, getIntLiteral(v.Sub[i]))
- }
- } else if equateTypePS(t, tCharp, ps) {
- for i := 0; i < len(v.Sub); i++ {
- out = append(out, getCharLiteral(v.Sub[i]))
- }
- } else if equateTypePS(t, tString, ps) {
- for i := 0; i < len(v.Sub); i++ {
- out = append(out, getStringLiteral(v.Sub[i]))
- }
- } else if len(t.Pre) > ps && t.Pre[ps] == "{}" {
- for i := 0; i < len(v.Sub); i++ {
- out = append(out, getLiteralArray(v.Sub[i], t, ps + 1))
+ var add interface{}
+ for i := 0; i < len(v.Sub); i++ {
+ if v.Sub[i].Data.Type == tparse.LITERAL {
+ dat := []rune(v.Sub[i].Data.Data)
+ if dat[0] == '"' {
+ add = getStringLiteral(v.Sub[i])
+ } else if dat[0] == '\'' {
+ add = getCharLiteral(v.Sub[i])
+ } else {
+ add = getIntLiteral(v.Sub[i])
+ }
+ } else if v.Sub[i].Data.Data == "comp" && v.Sub[i].Data.Type == 10 {
+ add = getCompositeLiteral(v.Sub[i])
}
+ out = append(out, add)
}
return out
}
-func getLiteralPS(v tparse.Node, t TType, ps int) interface{} {
+func getLiteral(v tparse.Node, t TType) interface{} {
- if equateTypePS(t, tInt, ps) {
+ if equateType(t, tInt) {
return getIntLiteral(v)
- } else if equateTypePS(t, tCharp, ps) {
+ } else if equateType(t, tCharp) {
return getCharLiteral(v)
- } else if equateTypePS(t, tString, ps) {
+ } else if equateType(t, tString) {
return getStringLiteral(v)
- } else if len(t.Pre) > ps && t.Pre[ps] == "{}" && v.Data.Data == "comp" && v.Data.Type == 10 {
- return getLiteralArray(v, t, 1)
}
- return nil
-}
-
-func getLiteral(v tparse.Node, t TType) interface{} {
- return getLiteralPS(v, t, 0)
+ return getCompositeLiteral(v)
}