diff options
| author | Kyle Gunger <kgunger12@gmail.com> | 2021-11-01 22:08:55 -0400 | 
|---|---|---|
| committer | Kyle Gunger <kgunger12@gmail.com> | 2021-11-01 22:08:55 -0400 | 
| commit | e18043e5ac4e09870e9f5b1498e0ef954064ee49 (patch) | |
| tree | bd4c86f2aec128d9b95e5edbcb3c1876688288bf /src | |
| parent | eed8e74d18235bc61ed66435c935bbbc5337f953 (diff) | |
[EXEC] evals
Diffstat (limited to 'src')
| -rw-r--r-- | src/texec/libtnsl.go | 38 | 
1 files changed, 20 insertions, 18 deletions
| 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 |