diff options
-rw-r--r-- | src/texec/eval.go | 42 | ||||
-rw-r--r-- | src/texec/world.go | 1 | ||||
-rw-r--r-- | src/texec/worldbuilder.go | 15 |
3 files changed, 45 insertions, 13 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index 7db07b0..548a30a 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -151,7 +151,6 @@ func equateTypePS(a, b TType, preskip int) bool { } if len(a.T.Path) != len(b.T.Path) || len(a.Pre) - preskip - cc != len(b.Pre) { - fmt.Println("[EVAL] Equate type died at len check.") return false } @@ -160,25 +159,21 @@ func equateTypePS(a, b TType, preskip int) bool { preskip++ continue } else if a.Pre[i] != b.Pre[i - preskip] { - fmt.Println("[EVAL] Equate type died at pre check.") return false } } for i := 0; i < len(a.T.Path); i++ { if a.T.Path[i] != b.T.Path[i] { - fmt.Println("[EVAL] Equate type died at path check.") return false } } if a.T.Name != b.T.Name { - fmt.Println("[EVAL] Equate type died at name check.") return false } if (a.Post == "`" && b.Post != "`") || (b.Post == "`" && a.Post != "`") { - fmt.Println("[EVAL] Equate type died at rel check.") return false } @@ -265,6 +260,14 @@ func getIntLiteral(v tparse.Node) int { return int(i) } +func getLiteralComposite(v tparse.Node) []interface{} { + out := []interface{}{} + + for i := 0; i < len(v.Sub); i++ { + getLiteral(v.Sub) + } +} + func getLiteral(v tparse.Node, t TType) interface{} { if equateType(t, tInt) { @@ -275,10 +278,23 @@ func getLiteral(v tparse.Node, t TType) interface{} { return getStringLiteral(v) } - return nil + return getLiteralComposite() } +func compositeToStruct(str TVariable, cmp []interface{}) VarMap { + vars = str.Data.([]TVariable) + if len(vars) != len(cmp) { + return nil + } + + out := make(VarMap) + + for i:=0;i<len(vars);i++ { + out[vars[i].Data.string] = TVariable{vars[i].Type, cmp[i]} + } + return out +} //##################### //# Finding Artifacts # @@ -302,17 +318,25 @@ func resolveArtifact(a TArtifact, ctx *TContext, root *TModule) *TVariable { // Value statement parsing -// Get a value from nodes. Must specify type of value to generate. +// Parse a value node func evalValue(v tparse.Node, ctx *TContext) TVariable { + if v.Data.Data == "=" { + + } return TVariable{tNull, nil} } -// Get a value from nodes. Must specify type of value to generate. +// Generate a value for a definition +func evalDefVal(v tparse.Node, , ctx *TContext) { + +} + +// Eval a definition func evalDef(v tparse.Node, ctx *TContext) { } -// Get a value from nodes. Must specify type of value to generate. +// Eval a control flow func evalCF(v tparse.Node, ctx *TContext) (bool, TVariable) { //scopeVars := []string{} return false, TVariable{tNull, nil} diff --git a/src/texec/world.go b/src/texec/world.go index d88eae2..d0435a0 100644 --- a/src/texec/world.go +++ b/src/texec/world.go @@ -38,7 +38,6 @@ type TVariable struct { } type VarMap map[string]TVariable -type TypeMap map[string]TType // TContext represents a single call context. type TContext struct { diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go index 96ea292..20976ac 100644 --- a/src/texec/worldbuilder.go +++ b/src/texec/worldbuilder.go @@ -18,6 +18,7 @@ package texec import ( "tparse" + "fmt" ) /** @@ -76,7 +77,7 @@ func modDefVars(n tparse.Node, t TType) ([]string, []TVariable) { func modDefStruct(n tparse.Node, m *TModule) { var name string - tmap := make(TypeMap) + tvlist := []TVariable{} for i := 0; i < len(n.Sub); i++ { if n.Sub[i].Data.Type == tparse.DEFWORD { @@ -87,13 +88,13 @@ func modDefStruct(n tparse.Node, m *TModule) { if n.Sub[i].Sub[j].Data.Type == 10 && n.Sub[i].Sub[j].Data.Data == "type" { t = getType(n.Sub[i].Sub[j]) } else if n.Sub[i].Sub[j].Data.Type == tparse.DEFWORD { - tmap[n.Sub[i].Sub[j].Data.Data] = t + tvlist = append(tvlist, TVariable{t, n.Sub[i].Sub[j].Data.Data}) } } } } - m.Defs[name] = TVariable{tStruct, tmap} + m.Defs[name] = TVariable{tStruct, tvlist} } func modDefEnum(n tparse.Node, m *TModule) { @@ -115,6 +116,7 @@ func parseFile(p string) tparse.Node { // Import a file and auto-import sub-modules and files func importFile(f string, m *TModule) { + fmt.Printf("[INFO] Importing file %s\n", f) froot := parseFile(f) for n := 0 ; n < len(froot.Sub) ; n++ { if froot.Sub[n].Data.Data == "block" { @@ -124,6 +126,7 @@ func importFile(f string, m *TModule) { m.Artifacts = append(m.Artifacts, froot.Sub[n]) } } else if froot.Sub[n].Data.Data == "include" { + fmt.Printf("[INCLUDE] %s\n", evalPreLiteral(froot.Sub[n].Sub[0])) importFile(evalPreLiteral(froot.Sub[n].Sub[0]), m) } else if froot.Sub[n].Data.Data == "define" { modDef(froot.Sub[n], m) @@ -136,6 +139,7 @@ func importFile(f string, m *TModule) { } } + fmt.Printf("[INFO] File %s has been imported.\n", f) } // Build a module from a module block node @@ -148,12 +152,17 @@ func buildModule(module tparse.Node) TModule { out.Name = module.Sub[0].Sub[0].Sub[0].Data.Data } + fmt.Printf("[INFO] Found module %s\n", out.Name) + for n := 1 ; n < len(module.Sub) ; n++ { if module.Sub[n].Data.Data == "include" { + fmt.Printf("[INCLUDE] %s\n", evalPreLiteral(module.Sub[n].Sub[0])) importFile(evalPreLiteral(module.Sub[n].Sub[0]), &out) } } + fmt.Printf("[INFO] Finished loading module %s\n", out.Name) + return out } |