From 96cf52263053db6bc3069c9fbc664ed0725ac41e Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Fri, 19 Nov 2021 01:39:05 -0500 Subject: Some refactoring, clearing out eval + Fixed BuildRoot + Refactored world.go - Deleted most of eval, I'm going to re-do it. --- src/texec/eval.go | 176 ++++++++++++------------------------------------------ 1 file changed, 38 insertions(+), 138 deletions(-) (limited to 'src/texec/eval.go') diff --git a/src/texec/eval.go b/src/texec/eval.go index 9900194..4aefd5a 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -16,158 +16,58 @@ package texec -import "strings" -import "strconv" -import "unicode" -import "tparse" -import "fmt" - -// Check if a block is the main function -func funcName(n tparse.Node) string { - if n.Data.Data == "block" { - if n.Sub[0].Data.Data == "bdef" { - for i := 0; i < len(n.Sub[0].Sub); i++ { - if n.Sub[0].Sub[i].Data.Type == tparse.DEFWORD { - return n.Sub[0].Sub[i].Data.Data - } - } - } - } - return "" -} - -// Default values for variables -func defaultVaule(t string) interface{} { - switch t { - case "int", "uint", "int8", "uint8", "char", "charp": - return 0 - case "string": - return "" - } - return nil -} - -// Match specific type (t) with general type (g) -func typeMatches(t, g string) bool { - switch t { - case "int", "uint", "int8", "uint8": - return g == "integer" - case "float": - return g == "float" - case "char", "charp": - return g == "char" - case "string": - return g == "string" - } - return false -} +// Don't want to deal with this rn -// Get the control flow's name -func cfType(n tparse.Node) string { - if n.Data.Data == "block" { - if n.Sub[0].Data.Data == "bdef" { - 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 n.Sub[0].Sub[i].Data.Data - } - } - } - } - } +/* + So here's what I care to support at present: + Type checking, basic types, writing to stdout or a file + Variable and state contexts + Reading from files + Raw structs + Appending to arrays + Calling functions and methods + libtnsl stub + + This subset should theoretically be enough to write a compiler. +*/ - return "" -} +//################ +//# Helper Funcs # +//################ -// Get type as string from nodes -func evalType(n tparse.Node) string { - return "" -} - -// Returns generated value and general "type" of value (string, number) -func evalPreLiteral(n tparse.Node) string { - r := tparse.StringAsRunes(n.Data.Data) - l := len(r) - if r[0] == '"' || r[0] == '\'' { - return tparse.RunesAsString(r[1:l - 1]) +func equateType(a, b TType) bool { + if len(a.Pre) != len(b.Pre) || len(a.Post) != len(b.Post) { + return false + } else if len(a.T.Path) != len(b.T.Path) { + return false } - return "" -} -// Returns generated value and general "type" of value (string, number) -func evalLiteral(n tparse.Node) (interface{}, string) { - r := tparse.StringAsRunes(n.Data.Data) - l := len(r) - - if r[0] == '"' { - return tparse.RunesAsString(r[1:l - 1]), "string" - } else if r[0] == '\'' { - return tparse.RunesAsString(r[1:l - 1]), "char" - } else if unicode.IsNumber(r[0]) { - if strings.Contains(n.Data.Data, ".") { - f, _ := strconv.ParseFloat(n.Data.Data, 64) - return f, "float" - } else { - i, _ := strconv.Atoi(n.Data.Data) - return i, "integer" + for i := 0; i < len(a.Pre); i++ { + if a.Pre[i] != b.Pre[i] { + return false } } - return nil, "" -} - -// Evaluates a definition and sets up a TVariable in the context's var map -func evalDef(n tparse.Node, ctx *TContext) { - vars := len(ctx.VarMap) - 1 - - t := evalType(n.Sub[0]) - - for i := 0; i < len(n.Sub[1].Sub); i++ { - name := n.Sub[1].Sub[i].Data.Data - - _, 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].Data.Data - val = evalValue(n.Sub[1].Sub[i].Sub[1], ctx) + for i := 0; i < len(a.T.Path); i++ { + if a.T.Path[i] != b.T.Path[i] { + return false } - - ctx.VarMap[vars][name] = TVariable{t, val} } -} -func delScopeVars(sV []string, ctx *TContext) { - m := len(ctx.VarMap) - 1 - for i := 0; i < len(sV); i++ { - delete(ctx.VarMap[m], sV[i]) + if a.T.Name != b.T.Name { + return false } -} -// Evaluates a value statement -func evalValue(artifact tparse.Node, ctx *TContext) interface{} { - vars := len(ctx.VarMap) - 1 -} - -// Evaluates a loop -func evalLoop(artifact tparse.Node, ctx *TContext) { - -} - -func evalIf(artifact tparse.Node, ctx *TContext) bool { - var scopeVars []string -} + for i := 0; i < len(a.Post); i++ { + if a.Post[i] != b.Post[i] { + return false + } + } -// Evaluate a block (Assume that all blocks have only one output for now) -func evalBlock(artifact tparse.Node, ctx *TContext) interface{} { - + return true; } +//################# +//# Runtime funcs # +//################# -// EvalTNSL starts the evaluation on the root TModule's main function with the given flags passed to the program -func EvalTNSL(root *TModule, f string) { - flags := strings.Split(f, " ") -} \ No newline at end of file -- cgit v1.2.3