diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2021-12-03 18:25:03 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2021-12-03 18:25:03 -0500 |
commit | 1100ac865074effb3a4735c7449779f7193b7d0c (patch) | |
tree | 1a981ae33b1ba4a888c98640fed0e7fc74b18f57 /src/texec | |
parent | 8fd930180e5d7a610117299bb9c48e28409d3106 (diff) |
General updates
+ Fill out eval a little and make sure that this builds.
~ CF kinda broken in AST. Gonna have to fix that. Upcoming Parser update.
Diffstat (limited to 'src/texec')
-rw-r--r-- | src/texec/eval.go | 45 | ||||
-rw-r--r-- | src/texec/libtnsl.go | 18 | ||||
-rw-r--r-- | src/texec/world.go | 2 |
3 files changed, 51 insertions, 14 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index 93cbfdb..0542a97 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -160,6 +160,43 @@ func equateType(a, b TType) bool { // Generate a TType from a 'type' node func getType(t tparse.Node) TType { out := TType{} + i := 0 + + // Pre + for ; i < len(t.Sub); i++ { + if t.Sub[i].Data.Type == tparse.DEFWORD || t.Sub[i].Data.Type == tparse.KEYTYPE { + break + } else { + out.Pre = append(out.Pre, t.Sub[i].Data.Data) + } + } + + // T + for ; i < len(t.Sub); i++ { + if t.Sub[i].Data.Type == tparse.KEYTYPE { + out.T.Name = t.Sub[i].Data.Data + i++ + break + } else if t.Sub[i].Data.Type == tparse.DEFWORD { + if i < len(t.Sub) - 1 { + if t.Sub[i + 1].Data.Type == tparse.DEFWORD { + out.T.Path = append(out.T.Path, t.Sub[i].Data.Data) + } else { + out.T.Name = t.Sub[i].Data.Data + break + } + } else { + out.T.Name = t.Sub[i].Data.Data + } + } + } + + // Post + if i < len(t.Sub) { + if t.Sub[i].Data.Data == "`" { + out.Post = "`" + } + } return out } @@ -167,20 +204,20 @@ func getType(t tparse.Node) TType { // Value generation func getStringLiteral(v tparse.Node) []byte { - + return []byte{} } func getCharLiteral(v tparse.Node) byte { - + return 0 } func getIntLiteral(v tparse.Node) int { - + return 0 } // Get a literal value from nodes. Must specify type of literal to generate. func getLiteral(v tparse.Node, t TType) interface{} { - + return 0 } //################# diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index 000af7d..b1c1907 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -43,14 +43,14 @@ import ( // Generic in-built types var ( - tFile = TType{Pre: []string{}, T: TArtifact{Path: []string{"tnsl", "io"}, Name: "File"}, Post: []string{}} - tString = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: []string{}} - tInt = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"int"}, Post: []string{}} - tByte = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: []string{}} - tByteArray = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: []string{}} - tFloat = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"float"}, Post: []string{}} - tCharp = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: []string{}} - tNull = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "null"}, Post: []string{}} + tFile = TType{Pre: []string{}, T: TArtifact{Path: []string{"tnsl", "io"}, Name: "File"}, Post: ""} + tString = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: ""} + tInt = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"int"}, Post: ""} + tByte = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: ""} + tByteArray = TType{Pre: []string{"{}"}, T: TArtifact{Path: []string{}, Name:"uint8"}, Post: ""} + tFloat = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"float"}, Post: ""} + tCharp = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name:"charp"}, Post: ""} + tNull = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "null"}, Post: ""} ) // tells if the stub supports a function @@ -150,7 +150,7 @@ func tfile_write(file, in TVariable) { b := []byte{0} b[0] = (in.Data).(byte) (file.Data).(*os.File).Write(b) - } else if equateType(in.Type, tByteArray) { + } else if equateType(in.Type, tByteArray) || equateType(in.Type, tString) { (file.Data).(*os.File).Write((in.Data).([]byte)) } } else { diff --git a/src/texec/world.go b/src/texec/world.go index b1c6def..d0435a0 100644 --- a/src/texec/world.go +++ b/src/texec/world.go @@ -28,7 +28,7 @@ type TArtifact struct { type TType struct { Pre []string T TArtifact - Post []string + Post string } // TVariable represents a single variable in the program |