From b74f28bf1e54dfcd7e679cbd688091d4b5f2642a Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sun, 13 Feb 2022 00:08:59 -0500 Subject: [EXEC] Pointers. --- src/texec/eval.go | 59 +++++++++++++++++++++++++++++++++-------------- src/texec/libtnsl.go | 4 ++++ src/texec/world.go | 2 +- src/texec/worldbuilder.go | 8 +++---- 4 files changed, 51 insertions(+), 22 deletions(-) (limited to 'src/texec') diff --git a/src/texec/eval.go b/src/texec/eval.go index 7f18f49..cacaa66 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -53,18 +53,20 @@ var ( // Error helper func errOut(msg string) { - fmt.Println("Error in eval:") + fmt.Println("==== BEGIN ERROR ====") fmt.Println(msg) fmt.Println(cart) - panic("EVAL ERROR") + fmt.Println("==== END ERROR ====") + panic(">>> PANIC FROM EVAL <<<") } func errOutCTX(msg string, ctx VarMap) { - fmt.Println("Error in eval:") + fmt.Println("==== BEGIN ERROR ====") fmt.Println(msg) fmt.Println(cart) fmt.Println(ctx) - panic("EVAL ERROR") + fmt.Println("==== END ERROR ====") + panic(">>> PANIC FROM EVAL <<<") } // Names of artifacts, finding artifacts @@ -226,7 +228,7 @@ func getNodeRelative(s TArtifact) *tparse.Node { return nil } -func getModDefRelative(s TArtifact) TVariable { +func getModDefRelative(s TArtifact) *TVariable { for i := len(cart.Path); i >= 0; i-- { tmpmod := getModuleRelative(getModuleInPath(i), s) @@ -234,19 +236,19 @@ func getModDefRelative(s TArtifact) TVariable { continue } - def, prs := tmpmod.Defs[s.Name] + _, prs := tmpmod.Defs[s.Name] if prs { - return def + return &(mod.Defs[a.Name]) } } errOut(fmt.Sprintf("Failed to resolve mod def artifact %v", s)) - return null + return nil } // Returns a mod definition, requires a resolved artifact -func getModDef(a TArtifact) TVariable { +func getModDef(a TArtifact) *TVariable { mod := prog for i := 0; i < len(a.Path); i++ { @@ -258,14 +260,14 @@ func getModDef(a TArtifact) TVariable { } } - def, prs := mod.Defs[a.Name] + v, prs := mod.Defs[a.Name] if prs { - return def + return v } errOut(fmt.Sprintf("Failed to resolve mod def artifact %v", a)) - return null + return nil } // Type related stuff @@ -421,8 +423,10 @@ func getLiteral(v tparse.Node, t TType) interface{} { return getLiteralComposite(v) } -func compositeToStruct(str TVariable, cmp []interface{}) VarMap { - vars := str.Data.([]TVariable) +func compositeToStruct(str TArtifact, cmp []interface{}) VarMap { + sv := getModDefRelative(str) + + vars := sv.Data.([]TVariable) if len(vars) != len(cmp) { return nil } @@ -430,7 +434,10 @@ func compositeToStruct(str TVariable, cmp []interface{}) VarMap { out := make(VarMap) for i:=0;i