diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-12-11 23:32:16 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-12-11 23:32:16 -0500 |
commit | dc8f1a06f086bda90e90a5386d4619d54efb1d0d (patch) | |
tree | 7850d7ce6a7c77ab817779cd8bf4b2c122252069 /src/texec/eval.go | |
parent | c3b9e4a8be18338ed5da223037d6259eaef54e8f (diff) |
[EVAL] Still needs some work
+ modules now define variables properly
+ fixed some bugs in eval.tnsl with type checking
~ Needs to support arrays and composites, but doesn't yet.
Diffstat (limited to 'src/texec/eval.go')
-rw-r--r-- | src/texec/eval.go | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index d1bf366..a360157 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -16,10 +16,11 @@ package texec -import "tparse" -import "fmt" - -import "strconv" +import ( + "tparse" + "fmt" + "strconv" +) /* So here's what I care to support at present: @@ -47,6 +48,14 @@ func errOut(msg string, place tparse.Token) { panic("EVAL ERROR") } +func errOutCTX(msg string, place tparse.Token, ctx TContext) { + fmt.Println("Error in eval:") + fmt.Println(msg) + fmt.Println(place) + fmt.Println(ctx) + panic("EVAL ERROR") +} + // Names of artifacts, finding artifacts func getDefNames(def tparse.Node) []string { @@ -127,33 +136,38 @@ func getArtifact(a TArtifact, root *TModule) *tparse.Node { // Type related stuff // Checking type equality +// Assumes a is an unknown type and b is a known good type. func equateTypePS(a, b TType, preskip int) 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) { + if len(a.T.Path) != len(b.T.Path) { + fmt.Println("thing 1") return false } for i := preskip; i < len(a.Pre); i++ { - if a.Pre[i] != b.Pre[i - preskip] { + if a.Pre[i] == "const" { + preskip++ + continue + } else if a.Pre[i] != b.Pre[i - preskip] { + fmt.Println("thing 3") return false } } for i := 0; i < len(a.T.Path); i++ { if a.T.Path[i] != b.T.Path[i] { + fmt.Println("thing 4") return false } } if a.T.Name != b.T.Name { + fmt.Println("thing 5") return false } - for i := 0; i < len(a.Post); i++ { - if a.Post[i] != b.Post[i] { - return false - } + if (a.Post == "`" && b.Post != "`") || (b.Post == "`" && a.Post != "`") { + fmt.Println("thing 6") + return false } return true; @@ -229,45 +243,50 @@ func getCharLiteral(v tparse.Node) byte { return byte(val) } -func getIntLiteral(v tparse.Node) int64 { +func getIntLiteral(v tparse.Node) int { i, err := strconv.ParseInt(v.Data.Data, 0, 64) if err != nil { errOut("Failed to parse integer literal.", v.Data) } - return i + return int(i) } -func getLiteral(v tparse.Node) (interface{}, TType) { - str, err := strconv.Unquote(v.Data.Data) +func getLiteralComposite(v tparse.Node) VarMap { + return VarMap{} +} - if err == nil { - return []byte(str), tString - } else { - val, mb, _, err := strconv.UnquoteChar(v.Data.Data, byte('\'')) - - if err == nil { - return byte(val), tCharp - } else { - i, err := strconv.ParseInt(v.Data.Data, 0, 64) +func getLiteral(v tparse.Node, t TType) interface{} { - if err == nil { - return i, tInt - } else { - errOut("Failed to parse literal in any way.", v.Data) - } - } + if equateType(t, tInt) { + return getIntLiteral(v) + } else if equateType(t, tCharp) { + return getCharLiteral(v) + } else if equateType(t, tString) { + return getStringLiteral(v) } - return nil, tNull + return getLiteralComposite(v) } + + //##################### //# Finding Artifacts # //##################### +func resolveModArtifact() *TVariable { + return nil +} + +func resolveArtifactCall() TVariable { + return TVariable{} +} +func resolveArtifact(a TArtifact, ctx *TContext, root *TModule) *TVariable { + return nil +} //################# //# Runtime funcs # @@ -278,4 +297,8 @@ func getLiteral(v tparse.Node) (interface{}, TType) { // Get a value from nodes. Must specify type of value to generate. func evalValue(v tparse.Node, t TType) TVariable { return TVariable{} -}
\ No newline at end of file +} + +func evalBlock(b tparse.Node, m TArtifact) TVariable { + return TVariable{tNull, nil} +} |