diff options
-rw-r--r-- | src/texec/eval.go | 59 | ||||
-rw-r--r-- | src/texec/libtnsl.go | 4 | ||||
-rw-r--r-- | src/texec/world.go | 2 | ||||
-rw-r--r-- | src/texec/worldbuilder.go | 8 |
4 files changed, 51 insertions, 22 deletions
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<len(vars);i++ { - out[vars[i].Data.(string)] = TVariable{vars[i].Type, cmp[i]} + if equateType(vars[i].Type, tInt) || equateType(t, tCharp) || equateType(t, tString) { + out[vars[i].Data.(string)] = &(TVariable{vars[i].Type, cmp[i]}) + } + } return out @@ -449,6 +456,16 @@ func resolveArtifactCall(a TArtifact, params []TVariable) TVariable { } func resolveArtifact(a TArtifact, ctx *VarMap) *TVariable { + if len(a.Path) == 0 { + val, prs := (*ctx)[a.Name] + if !prs { + errOutCTX(fmt.Sprintf("Could not resolve %s in the current context.", a.Name), *ctx) + } + return val + } else { + + } + return nil } @@ -460,8 +477,16 @@ func resolveArtifact(a TArtifact, ctx *VarMap) *TVariable { // Parse a value node func evalValue(v tparse.Node, ctx *VarMap) TVariable { - if v.Data.Data == "=" { - + switch v.Data.Data { + case "=": + case "+": + case "-": + case "*": + case "/": + case "&&": + case "||": + case "==": + case ".": } return null } diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index b810e5f..2a2a9d5 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -114,6 +114,8 @@ func tnslFileEval(file, in TVariable, function string) TVariable { func tprint(in TVariable) { if equateType(in.Type, tString) { fmt.Print(in.Data.(string)) + } else if equateType(in.Type, tCharp) { + fmt.Print(in.Data.(rune)) } else { fmt.Print(in.Data) } @@ -122,6 +124,8 @@ func tprint(in TVariable) { func tprintln(in TVariable) { if equateType(in.Type, tString) { fmt.Println(in.Data.(string)) + } else if equateType(in.Type, tCharp) { + fmt.Println(in.Data.(rune)) } else { fmt.Println(in.Data) } diff --git a/src/texec/world.go b/src/texec/world.go index 7921a13..306517f 100644 --- a/src/texec/world.go +++ b/src/texec/world.go @@ -37,7 +37,7 @@ type TVariable struct { Data interface{} } -type VarMap map[string]TVariable +type VarMap map[string]*TVariable // TModule represents a collection of files and sub-modules in a program type TModule struct { diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go index 2f71e79..6a5fb33 100644 --- a/src/texec/worldbuilder.go +++ b/src/texec/worldbuilder.go @@ -51,7 +51,7 @@ func modDef(n tparse.Node, m *TModule) { t := getType(n.Sub[0]) s, vs := modDefVars(n.Sub[1], t) for i := 0; i < len(s); i++ { - m.Defs[s[i]] = vs[i] + m.Defs[s[i]] = &(vs[i]) } } @@ -94,7 +94,7 @@ func modDefStruct(n tparse.Node, m *TModule) { } } - m.Defs[name] = TVariable{tStruct, tvlist} + m.Defs[name] = &(TVariable{tStruct, tvlist}) } func modDefEnum(n tparse.Node, m *TModule) { @@ -103,9 +103,9 @@ func modDefEnum(n tparse.Node, m *TModule) { s, vs := modDefVars(n.Sub[2], t) out := TVariable{tEnum, make(VarMap)} for i := 0; i < len(s); i++ { - out.Data.(VarMap)[s[i]] = vs[i] + out.Data.(VarMap)[s[i]] = &(vs[i]) } - m.Defs[name] = out + m.Defs[name] = &(out) } // Parse a file and make an AST from it. |