From e18043e5ac4e09870e9f5b1498e0ef954064ee49 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 1 Nov 2021 22:08:55 -0400 Subject: [EXEC] evals --- src/texec/libtnsl.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/texec/libtnsl.go') diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index 8ab214b..bf5fcd5 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -54,16 +54,30 @@ func tnslResolve(callPath TPath) bool { } // evaluate a function call. -// out is the variable out (if any) // in is the variable in (if any) -// callPath is the function being called. -func tnslEval(out, in *TVariable, callPath TPath) { - +// out is the variable out (if any) +// function is the name of the function +func tnslEval(in, out *TVariable, function string) { + switch function { + case "print": + tprint(*in) + case "println": + tprintln(*in) + case "open_file": + topen_file(*in, out) + } } // evaluate a call on a file object -func tnslFileEval(file, out, in *TVariable, callPath TPath) { - +func tnslFileEval(file, in, out *TVariable, function string) { + switch function { + case "close": + tfile_close(file) + case "read": + tfile_read(file, out) + case "write": + tfile_write(file, in) + } } // Generic IO funcs @@ -88,18 +102,6 @@ func topen_file(in TVariable, out *TVariable) { 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 -- cgit v1.2.3