summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Gunger <kgunger12@gmail.com>2021-11-01 21:49:17 -0400
committerKyle Gunger <kgunger12@gmail.com>2021-11-01 21:49:17 -0400
commite70046f5e8a068369ac73aae47bf4aa7ec90d743 (patch)
tree2878dc722c2eb9f82c5f8f4a75199e1af0f69ccf
parentb605d4f7cc28129975bcabd5e72715492244a6b8 (diff)
[EXEC] flushout libtnsl stub a bit
-rw-r--r--src/exec.go20
-rw-r--r--src/texec/eval.go7
-rw-r--r--src/texec/libtnsl.go76
-rw-r--r--src/texec/world.go18
-rw-r--r--src/texec/worldbuilder.go4
5 files changed, 97 insertions, 28 deletions
diff --git a/src/exec.go b/src/exec.go
index f92f435..dbdbf72 100644
--- a/src/exec.go
+++ b/src/exec.go
@@ -17,7 +17,6 @@
package main
import "fmt"
-import "tparse"
import "texec"
import "flag"
@@ -27,20 +26,7 @@ func main() {
flag.Parse()
- if err != nil {
- fmt.Println(err.Error())
- return
- }
-
- tokens := tparse.TokenizeFile(*inputFile)
-
- switch *writeLevel {
- case 0:
- fd.WriteString(fmt.Sprint(tokens) + "\n")
- case 1:
- tree := tparse.MakeTree(&tokens, *inputFile)
- fd.WriteString(fmt.Sprint(tree) + "\n")
- }
-
- fd.Close()
+ world := texec.BuildWorld(*inputFile)
+
+ texec.EvalTNSL(&world, *progFlags)
} \ No newline at end of file
diff --git a/src/texec/eval.go b/src/texec/eval.go
index 8b22f01..9d2e64d 100644
--- a/src/texec/eval.go
+++ b/src/texec/eval.go
@@ -15,3 +15,10 @@
*/
package texec
+
+import "strings"
+
+// EvalTNSL starts the evaluation on the World's main function with the given flags passed to the program
+func EvalTNSL(world *TWorld, f string) {
+ flags := strings.Split(f, " ")
+} \ No newline at end of file
diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go
index 7bf4848..8ab214b 100644
--- a/src/texec/libtnsl.go
+++ b/src/texec/libtnsl.go
@@ -16,7 +16,10 @@
package texec
-import "fmt"
+import (
+ "fmt"
+ "os"
+)
/**
libtnsl module stub. Contains only parts of the io sub-module.
@@ -54,6 +57,73 @@ func tnslResolve(callPath TPath) bool {
// out is the variable out (if any)
// in is the variable in (if any)
// callPath is the function being called.
-func tnslEval(out, in *TVaraiable, callPath TPath) {
+func tnslEval(out, in *TVariable, callPath TPath) {
-} \ No newline at end of file
+}
+
+// evaluate a call on a file object
+func tnslFileEval(file, out, in *TVariable, callPath TPath) {
+
+}
+
+// Generic IO funcs
+
+func tprint(in TVariable) {
+ fmt.Printf("%v", in.Data)
+}
+
+func tprintln(in TVariable) {
+ fmt.Printf("%v\n", in.Data)
+}
+
+func topen_file(in TVariable, out *TVariable) {
+ if in.Type != "string" {
+ panic("Tried to open a file, but did not use a string type for the file name.")
+ }
+ fd, err := os.Create(in.Data.(string))
+ if err != nil {
+ panic(fmt.Sprintf("Failed to open file %v as requested by the program. Aborting.\n%v", in.Data, err))
+ }
+ out.Type = "tnsl.io.File"
+ out.Data = fd
+}
+
+func tclose_file(in TVariable, out *TVariable) {
+ if in.Type != "string" {
+ panic("Tried to open a file, but did not use a string type for the file name.")
+ }
+ fd, err := os.Create(in.Data.(string))
+ if err != nil {
+ panic(fmt.Sprintf("Failed to open file %v as requested by the program. Aborting.\n%v", in.Data, err))
+ }
+ out.Type = "tnsl.io.File"
+ out.Data = fd
+}
+
+
+// File API
+
+// tnsl.io.File.close
+func tfile_close(file *TVariable) {
+ if (*file).Type == "tnsl.io.File" {
+ ((*file).Data).(*os.File).Close()
+ }
+}
+
+// tnsl.io.File.read
+func tfile_read(file, out *TVariable) {
+ b := []byte{1}
+ (file.Data).(*os.File).Read(b)
+ if out.Data == "uint8" || out.Data == "int8" {
+ out.Data = b[0]
+ }
+}
+
+// tnsl.io.File.write
+func tfile_write(file, in *TVariable) {
+ b := []byte{1}
+ if in.Data == "uint8" || in.Data == "int8" {
+ b[0] = (in.Data).(byte)
+ }
+ (file.Data).(*os.File).Write(b)
+}
diff --git a/src/texec/world.go b/src/texec/world.go
index 79cc88c..d87119d 100644
--- a/src/texec/world.go
+++ b/src/texec/world.go
@@ -16,7 +16,9 @@
package texec
-// TVaraiable represents a single variable in the program
+import "tparse"
+
+// TVariable represents a single variable in the program
type TVariable struct {
Type string
Data interface{}
@@ -25,27 +27,27 @@ type TVariable struct {
// TPath represents a pointer to the current module and file
// that the thread is working in.
type TPath struct {
- Module []string,
+ Module []string
Artifact string
}
// TContext represents a single thread.
type TContext struct {
- CallStack []Node,
- CallEnv []TPath,
+ CallStack []tparse.Node
+ CallEnv []TPath
VarMap []map[string]TVariable
}
// TModule represents a collection of files and sub-modules in a program
type TModule struct {
- Files []Node,
+ Files []tparse.Node
Globals []map[string]TVariable
Sub []TModule
}
// TWorld represents the full program
type TWorld struct {
- Modules []TModule,
- MainPath TPath,
- MainFunc Node
+ Modules []TModule
+ MainPath TPath
+ MainFunc tparse.Node
}
diff --git a/src/texec/worldbuilder.go b/src/texec/worldbuilder.go
index 37f05db..54f87f3 100644
--- a/src/texec/worldbuilder.go
+++ b/src/texec/worldbuilder.go
@@ -22,3 +22,7 @@ import "tparse"
worldbuilder.go - take in a file name and construct a TWorld based on it.
*/
+// BuildWorld creates a new TWorld by parsing a main file and recursively parsing imports.
+func BuildWorld(file string) *TWorld {
+ return nil
+}