summaryrefslogtreecommitdiff
path: root/src/texec/libtnsl.go
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2022-04-09 05:55:03 -0400
committerKyle Gunger <kgunger12@gmail.com>2022-04-09 05:55:03 -0400
commit74aa33808dbe2630eb5fac427874428d55011267 (patch)
treecc5912214deea1a0f6453c67c6bce6eb586d23ab /src/texec/libtnsl.go
parentb76d0fe41b222acfa5348edecbe88277739cf3e9 (diff)
TINT v1 (PRE-ALPHA)
+ Added support for else/else if blocks + Fixed a bug with parsing string literals + Tested printing values to the cli + I think file writing/reading should work but it's a little hit or miss atm
Diffstat (limited to 'src/texec/libtnsl.go')
-rw-r--r--src/texec/libtnsl.go35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go
index 6fe431b..0f02f32 100644
--- a/src/texec/libtnsl.go
+++ b/src/texec/libtnsl.go
@@ -56,6 +56,9 @@ var (
// used only in module definintion
tEnum = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "enum"}, Post: ""}
tStruct = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "struct"}, Post: ""}
+
+ // Special types for if chain checking
+ tIF = TType{Pre: []string{}, T: TArtifact{Path: []string{}, Name: "if"}, Post: ""}
)
// tells if the stub supports a function
@@ -114,30 +117,28 @@ func tnslFileEval(file, in TVariable, function string) TVariable {
// Generic IO funcs
func tprint(in TVariable) {
- if equateType(in.Type, tString) {
- fmt.Print(in.Data.(string))
- } else if equateType(in.Type, tCharp) {
- fmt.Print(in.Data.(rune))
- } else {
- fmt.Print(in.Data)
- }
+ fmt.Print(in.Data)
}
func tprintln(in TVariable) {
- if equateType(in.Type, tString) {
- fmt.Println(in.Data.(string))
- } else if equateType(in.Type, tCharp) {
- fmt.Println(in.Data.(rune))
- } else {
- fmt.Println(in.Data)
+ fmt.Println(in.Data)
+}
+
+func datToString(dat interface{}) string {
+ out := []byte{}
+ in := dat.([]interface{})
+ for i := 0; i < len(in); i++ {
+ out = append(out, in[i].(byte))
}
+
+ return string(out)
}
func topenWriteFile(in TVariable) TVariable {
- if equateType(in.Type, tString) {
+ if !equateType(in.Type, tString) {
panic("Tried to open a file (for writing), but did not use a string type for the file name.")
}
- fd, err := os.Create(in.Data.(string))
+ fd, err := os.Create(datToString(in.Data))
if err != nil {
panic(fmt.Sprintf("Failed to open file (for writing) %v as requested by the program. Aborting.\n%v", in.Data, err))
}
@@ -145,10 +146,10 @@ func topenWriteFile(in TVariable) TVariable {
}
func topenReadFile(in TVariable) TVariable {
- if equateType(in.Type, tString) {
+ if !equateType(in.Type, tString) {
panic("Tried to open a file (for reading), but did not use a string type for the file name.")
}
- fd, err := os.Open(in.Data.(string))
+ fd, err := os.Open(datToString(in.Data))
if err != nil {
panic(fmt.Sprintf("Failed to open file (for reading) %v as requested by the program. Aborting.\n%v", in.Data, err))
}