From 8fd930180e5d7a610117299bb9c48e28409d3106 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Tue, 23 Nov 2021 12:58:46 -0500 Subject: [EVAL] Stubcode v2 --- src/texec/eval.go | 26 ++++++++++++++++++++++++++ src/texec/world.go | 1 + src/texec/worldbuilder.go | 4 ++-- src/tparse/tokenize.go | 38 +++----------------------------------- src/tparse/type.go | 4 ++-- 5 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/texec/eval.go b/src/texec/eval.go index b6c0020..93cbfdb 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -157,6 +157,32 @@ func equateType(a, b TType) bool { return true; } +// Generate a TType from a 'type' node +func getType(t tparse.Node) TType { + out := TType{} + + return out +} + +// Value generation + +func getStringLiteral(v tparse.Node) []byte { + +} + +func getCharLiteral(v tparse.Node) byte { + +} + +func getIntLiteral(v tparse.Node) int { + +} + +// Get a literal value from nodes. Must specify type of literal to generate. +func getLiteral(v tparse.Node, t TType) interface{} { + +} + //################# //# Runtime funcs # //################# diff --git a/src/texec/world.go b/src/texec/world.go index 83c50fd..b1c6def 100644 --- a/src/texec/world.go +++ b/src/texec/world.go @@ -49,6 +49,7 @@ type TContext struct { type TModule struct { Name string Artifacts []tparse.Node + Defs VarMap Sub []TModule } diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go index d85f1ac..023c730 100644 --- a/src/texec/worldbuilder.go +++ b/src/texec/worldbuilder.go @@ -37,10 +37,10 @@ import ( // Returns generated value and general "type" of value (string, number) func evalPreLiteral(n tparse.Node) string { - r := tparse.StringAsRunes(n.Data.Data) + r := []rune(n.Data.Data) l := len(r) if r[0] == '"' || r[0] == '\'' { - return tparse.RunesAsString(r[1:l - 1]) + return string(r[1:l - 1]) } return "" } diff --git a/src/tparse/tokenize.go b/src/tparse/tokenize.go index 56e866f..8a79b04 100644 --- a/src/tparse/tokenize.go +++ b/src/tparse/tokenize.go @@ -22,7 +22,6 @@ import ( "os" "strings" "unicode" - "unicode/utf8" ) // Read in a number (may be a float) @@ -112,7 +111,7 @@ func charLiteral(r *bufio.Reader, line int, char *int) Token { func splitResRunes(str string, max, line, start int) []Token { out := []Token{} - rs := StringAsRunes(str) + rs := []rune(str) s, e := 0, max if max > len(rs) { @@ -120,8 +119,8 @@ func splitResRunes(str string, max, line, start int) []Token { } for e <= len(rs) && s < len(rs) { - if checkRuneGroup(RunesAsString(rs[s:e])) != -1 || e == s+1 { - tmp := RunesAsString(rs[s:e]) + if checkRuneGroup(string(rs[s:e])) != -1 || e == s+1 { + tmp := string(rs[s:e]) out = append(out, Token{Type: checkRuneGroup(tmp), Data: tmp, Line: line, Char: start + s}) s = e if s+max < len(rs) { @@ -340,34 +339,3 @@ func TokenizeFile(path string) []Token { return stripBlockComments(out) } - -// StringAsRunes returns a string as a rune slice -func StringAsRunes(s string) []rune { - out := []rune{} - var r rune - for i, j := 0, 0; i < len(s); i += j { - r, j = utf8.DecodeRuneInString(s[i:]) - out = append(out, r) - } - return out -} - -// BytesAsRunes returns a byte slice as a rune slice -func BytesAsRunes(b []byte) []rune { - out := []rune{} - for i, j := 0, 0; i < len(b); i += j { - r, w := utf8.DecodeRune(b[i:]) - out = append(out, r) - j = w - } - return out -} - -// RunesAsString returns a string from a slice of runes -func RunesAsString(rs []rune) string { - b := strings.Builder{} - for _, r := range rs { - b.WriteRune(r) - } - return b.String() -} diff --git a/src/tparse/type.go b/src/tparse/type.go index 329aec3..0027f1f 100644 --- a/src/tparse/type.go +++ b/src/tparse/type.go @@ -296,7 +296,7 @@ func maxResRunes() int { } func checkRuneGroup(s string) int { - rs := StringAsRunes(s) + rs := []rune(s) if len(rs) == 1 { return checkResRune(rs[0]) @@ -310,7 +310,7 @@ func checkRuneGroup(s string) int { } func checkToken(s string, pre bool) int { - rs := StringAsRunes(s) + rs := []rune(s) if len(rs) == 0 { return -1 -- cgit v1.2.3