diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-12-15 15:04:58 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-12-15 15:04:58 -0500 |
commit | aa99f8f5b507468959cb1bb0942c86fc8384ba32 (patch) | |
tree | f4d1edcd1a5527360258ee0072ca5bea57a9d016 /src/texec | |
parent | 7a8a8b975bd4ca636b825a42852c5af95d9b5825 (diff) |
[EXEC] Better mapping
+ added support for mapping global arrays.
Diffstat (limited to 'src/texec')
-rw-r--r-- | src/texec/eval.go | 55 | ||||
-rw-r--r-- | src/texec/worldbuilder.go | 3 |
2 files changed, 48 insertions, 10 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index a360157..b4d04da 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -102,7 +102,7 @@ func getNames(root tparse.Node) []string { return getBlockName(root) case "define": return getDefNames(root) - case "raw", "switch", "enum": + case "raw", "struct", "enum": return getTypeName(root) } @@ -138,7 +138,14 @@ func getArtifact(a TArtifact, root *TModule) *tparse.Node { // Checking type equality // Assumes a is an unknown type and b is a known good type. func equateTypePS(a, b TType, preskip int) bool { - if len(a.T.Path) != len(b.T.Path) { + cc := 0 + for i := 0; i < len(a.Pre); i++ { + if a.Pre[i] == "const" { + cc++ + } + } + + if len(a.T.Path) != len(b.T.Path) || len(a.Pre) - preskip - cc != len(b.Pre) { fmt.Println("thing 1") return false } @@ -253,21 +260,51 @@ func getIntLiteral(v tparse.Node) int { return int(i) } -func getLiteralComposite(v tparse.Node) VarMap { - return VarMap{} +func getLiteralArray(v tparse.Node, t TType, ps int) []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)) + } + } + + return out } -func getLiteral(v tparse.Node, t TType) interface{} { +func getLiteralPS(v tparse.Node, t TType, ps int) interface{} { - if equateType(t, tInt) { + if equateTypePS(t, tInt, ps) { return getIntLiteral(v) - } else if equateType(t, tCharp) { + } else if equateTypePS(t, tCharp, ps) { return getCharLiteral(v) - } else if equateType(t, tString) { + } else if equateTypePS(t, tString, ps) { 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 getLiteralComposite(v) + return nil +} + +func getLiteral(v tparse.Node, t TType) interface{} { + return getLiteralPS(v, t, 0) } diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go index 141d1aa..9ab04a7 100644 --- a/src/texec/worldbuilder.go +++ b/src/texec/worldbuilder.go @@ -129,11 +129,12 @@ func importFile(f string, m *TModule) { modDef(froot.Sub[n], m) } else if froot.Sub[n].Data.Data == "enum"{ modDefEnum(froot.Sub[n], m) - }else if froot.Sub[n].Data.Data == "struct" || froot.Sub[n].Data.Data == "raw"{ + } else if froot.Sub[n].Data.Data == "struct" || froot.Sub[n].Data.Data == "raw"{ modDefStruct(froot.Sub[n], m) } else { m.Artifacts = append(m.Artifacts, froot.Sub[n]) } + } } |