summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger@gmail.com>2022-02-13 12:31:03 -0500
committerKyle Gunger <kgunger@gmail.com>2022-02-13 12:31:03 -0500
commit90580b76d31cb8dd9282b3f7a2488c2ebf148299 (patch)
treeb87b586269f3b6abf6dc7f195dd828b179b818cd
parent20fa93e2288a68a2f5de938ed9bd29bc9a300ced (diff)
Change how getModuleInPath works
-rw-r--r--src/texec/eval.go60
1 files changed, 29 insertions, 31 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go
index e18f56c..4cd643b 100644
--- a/src/texec/eval.go
+++ b/src/texec/eval.go
@@ -165,14 +165,11 @@ func getModuleRelative(mod *TModule, a TArtifact) *TModule {
return mod
}
-func getModuleInPath(m int) *TModule {
+func getModuleInPath(a TArtifact) *TModule {
mod := prog
-
- if m > len(cart.Path) {
- m = len(cart.Path)
- } else if m <= 0 {
- return mod
- }
+ m := len(cart.Path)
+
+ out := getModuleRelative(mod, a)
for i := 0; i < m; i++ {
for j := 0; j < len(mod.Sub); j++ {
@@ -180,13 +177,18 @@ func getModuleInPath(m int) *TModule {
mod = &(mod.Sub[j])
break
}
- if j + 1 == len(mod.Sub) {
- errOut(fmt.Sprintf("Failed to find module %d in path %v", m, cart))
- }
+ }
+ tmp := getModuleRelative(mod, a)
+ if tmp != nil {
+ out = tmp
}
}
- return mod
+ if out == nil {
+ errOut(fmt.Sprintf("Failed to find module %d in path %v", m, cart))
+ }
+
+ return out
}
// Find an artifact from a path and the root node
@@ -208,18 +210,16 @@ func getNode(a TArtifact) *tparse.Node {
func getNodeRelative(s TArtifact) *tparse.Node {
- for i := len(cart.Path); i >= 0; i-- {
- tmpmod := getModuleRelative(getModuleInPath(i), s)
- if tmpmod == nil {
- continue
- }
+ tmpmod := getModuleInPath(s)
+ if tmpmod == nil {
+ continue
+ }
- for i := 0; i < len(tmpmod.Artifacts); i++ {
- n := getNames(tmpmod.Artifacts[i])
- for j := 0; j < len(n); j++ {
- if n[j] == s.Name {
- return &(tmpmod.Artifacts[i])
- }
+ for i := 0; i < len(tmpmod.Artifacts); i++ {
+ n := getNames(tmpmod.Artifacts[i])
+ for j := 0; j < len(n); j++ {
+ if n[j] == s.Name {
+ return &(tmpmod.Artifacts[i])
}
}
}
@@ -230,17 +230,15 @@ func getNodeRelative(s TArtifact) *tparse.Node {
func getModDefRelative(s TArtifact) *TVariable {
- for i := len(cart.Path); i >= 0; i-- {
- tmpmod := getModuleRelative(getModuleInPath(i), s)
- if tmpmod == nil {
- continue
- }
+ tmpmod := getModuleInPath(s)
+ if tmpmod == nil {
+ continue
+ }
- val, prs := tmpmod.Defs[s.Name]
+ val, prs := tmpmod.Defs[s.Name]
- if prs {
- return val
- }
+ if prs {
+ return val
}
errOut(fmt.Sprintf("Failed to resolve mod def artifact (relative) %v", s))