From d228a388e5c95c703cff9f3050bb47e19078484a Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Mon, 1 Nov 2021 12:59:19 -0400 Subject: [EXEC] Flush out some things + Some initial stub code for tnsl + Finalize structs (for now) + Add a key type to the parser --- src/texec/eval.go | 17 +++++++++++++++++ src/texec/libtnsl.go | 40 ++++++++++++++++++++++++++++++++++++++-- src/texec/world.go | 7 ++++--- src/tparse/token.go | 20 ++++++++++---------- src/tparse/type.go | 7 ++++--- 5 files changed, 73 insertions(+), 18 deletions(-) create mode 100644 src/texec/eval.go diff --git a/src/texec/eval.go b/src/texec/eval.go new file mode 100644 index 0000000..8b22f01 --- /dev/null +++ b/src/texec/eval.go @@ -0,0 +1,17 @@ +/* + Copyright 2020 Kyle Gunger + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package texec diff --git a/src/texec/libtnsl.go b/src/texec/libtnsl.go index c77bd25..7bf4848 100644 --- a/src/texec/libtnsl.go +++ b/src/texec/libtnsl.go @@ -16,8 +16,44 @@ package texec +import "fmt" + /** - This file represents the 'tnsl' module and a key few functions. - These functions should be all that is needed to use the compiler, and no more. + libtnsl module stub. Contains only parts of the io sub-module. + Parts included: + - io.print + - io.println + - io.open_file + - io.File API for file objects */ +// tells if the stub supports a function +func tnslResolve(callPath TPath) bool { + l := len(callPath.Module) + if l < 2 || l > 3 || callPath.Module[0] != "tnsl" || callPath.Module[1] != "io" { + return false + } + if l > 2 && callPath.Module[2] != "File" { + return false + } + + if l > 2 { + if callPath.Artifact == "write" || callPath.Artifact == "read" || callPath.Artifact == "close" { + return true; + } + } else { + if callPath.Artifact == "print" || callPath.Artifact == "println" || callPath.Artifact == "open_file" { + return true; + } + } + + return false +} + +// 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 *TVaraiable, callPath TPath) { + +} \ No newline at end of file diff --git a/src/texec/world.go b/src/texec/world.go index 7f51c13..6fa6327 100644 --- a/src/texec/world.go +++ b/src/texec/world.go @@ -25,13 +25,14 @@ type TVariable struct { // TPath represents a pointer to the current module and file // that the thread is working in. type TPath struct { - module []string, - file string + Module []string, + Artifact string } // TContext represents a single thread. type TContext struct { CallStack []Node, + CallEnv []TPath, VarMap []map[string]TVariable } @@ -47,4 +48,4 @@ type TWorld struct { Modules []TModule, MainPath TPath, MainFunc Node -} \ No newline at end of file +} diff --git a/src/tparse/token.go b/src/tparse/token.go index 6c84c72..b358568 100644 --- a/src/tparse/token.go +++ b/src/tparse/token.go @@ -1,17 +1,17 @@ /* - Copyright 2020 Kyle Gunger + Copyright 2020 Kyle Gunger - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package tparse diff --git a/src/tparse/type.go b/src/tparse/type.go index 8a38527..329aec3 100644 --- a/src/tparse/type.go +++ b/src/tparse/type.go @@ -71,9 +71,10 @@ func checkPreWord(s string) int { // RESWORD represents all the reserved words and what type of tokens they are. var RESWORD = map[string]int{ - "bool": KEYTYPE, - "char": KEYTYPE, - "charp": KEYTYPE, + "bool": KEYTYPE, + "char": KEYTYPE, + "charp": KEYTYPE, + "string": KEYTYPE, "int": KEYTYPE, "int8": KEYTYPE, -- cgit v1.2.3