From e70046f5e8a068369ac73aae47bf4aa7ec90d743 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 1 Nov 2021 21:49:17 -0400 Subject: [EXEC] flushout libtnsl stub a bit --- src/texec/eval.go | 7 +++++ src/texec/libtnsl.go | 76 +++++++++++++++++++++++++++++++++++++++++++++-- src/texec/world.go | 18 ++++++----- src/texec/worldbuilder.go | 4 +++ 4 files changed, 94 insertions(+), 11 deletions(-) (limited to 'src/texec') 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 +} -- cgit v1.2.3