diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-11-03 18:22:19 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-11-03 18:22:19 -0400 |
commit | b988a5838635e365d9a165df0db7263cbb34d4a0 (patch) | |
tree | 858ac03a79616bd9c4cbe26c06a7db7df74b2f5e | |
parent | b7fc265fc44ce8b7dcb0565311610181bd3ba1e2 (diff) |
[EXEC] Fix some errors, leave others
-rw-r--r-- | src/texec/eval.go | 21 | ||||
-rw-r--r-- | src/texec/libtnsl.go | 2 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index a8bd50f..ba936a6 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -18,13 +18,14 @@ package texec import "strings" import "tparse" +import "fmt" // Check if a block is the main function func isMain(n tparse.Node) bool { if n.Data.Data == "block" { if n.Sub[0].Data.Data == "bdef" { - for i := 0; i < len(n.Sub.Sub); i++ { - if n.Sub.Sub[i].Data.Type == tparse.DEFWORD && n.Sub.Sub[i].Data.Data == "main" { + for i := 0; i < len(n.Sub[0].Sub); i++ { + if n.Sub[0].Sub[i].Data.Type == tparse.DEFWORD && n.Sub[0].Sub[i].Data.Data == "main" { return true } } @@ -37,9 +38,9 @@ func isMain(n tparse.Node) bool { func isCF(n tparse.Node) bool { if n.Data.Data == "block" { if n.Sub[0].Data.Data == "bdef" { - for i := 0; i < len(n.Sub.Sub); i++ { - if n.Sub.Sub[i].Data.Type == tparse.KEYWORD { - if n.Sub.Sub[i].Data.Data == "if" || n.Sub.Sub[i].Data.Data == "elif" || n.Sub.Sub[i].Data.Data == "else" || n.Sub.Sub[i].Data.Data == "match" || n.Sub.Sub[i].Data.Data == "case" || n.Sub.Sub[i].Data.Data == "loop" { + for i := 0; i < len(n.Sub[0].Sub); i++ { + if n.Sub[0].Sub[i].Data.Type == tparse.KEYWORD { + if n.Sub[0].Sub[i].Data.Data == "if" || n.Sub[0].Sub[i].Data.Data == "elif" || n.Sub[0].Sub[i].Data.Data == "else" || n.Sub[0].Sub[i].Data.Data == "match" || n.Sub[0].Sub[i].Data.Data == "case" || n.Sub[0].Sub[i].Data.Data == "loop" { return true } } @@ -60,7 +61,7 @@ func defaultVaule(t string) interface{} { } // Match specific type (t) with general type (g) -func typeMatches(t, g string) { +func typeMatches(t, g string) bool { switch t { case "int", "uint", "int8", "uint8", "char", "charp": return g == "number" @@ -93,18 +94,18 @@ func evalDef(n tparse.Node, ctx *TContext) { for i := 0; i < len(n.Sub[1].Sub); i++ { name := n.Sub[1].Sub[i].Data.Data - _, prs := ctx.VarMap[name] + _, prs := ctx.VarMap[vars][name] if prs { panic(fmt.Sprintf("Attempted re-definition of a variable %v", name)) } val := defaultVaule(t) if n.Sub[1].Sub[i].Data.Data == "=" { - name = n.Sub[1].Sub[i].Sub[0] + name = n.Sub[1].Sub[i].Sub[0].Data.Data val = evalValue(n.Sub[1].Sub[i].Sub[1], ctx) } - - ctx.VarMap[name] = TVariable{t, val} + + ctx.VarMap[vars][name] = TVariable{t, val} } } diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index c881cea..1d36892 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -128,7 +128,7 @@ func tfile_write(file, in *TVariable) { b[0] = (in.Data).(byte) } else { (file.Data).(*os.File).Close() - panic(fmt.Sprintf("Failed to write to file, attempted to use unsupported type (%v)\n", out.Type)) + panic(fmt.Sprintf("Failed to write to file, attempted to use unsupported type (%v)\n", in.Type)) } (file.Data).(*os.File).Write(b) } |