From 15eded2fdb4b039a1bcdc4d3094f708e6529c355 Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Wed, 24 Apr 2024 14:40:43 -0400 Subject: Module init and end --- tnslc/compile/ast.tnsl | 2 ++ tnslc/compile/compile.tnsl | 4 +++- tnslc/compile/function.tnsl | 10 ++++++++ tnslc/compile/lexer.tnsl | 0 tnslc/compile/module.tnsl | 58 ++++++++++++++++++++++++++++++++++++++++++--- tnslc/compile/variable.tnsl | 9 +++++++ tnslc/utils/algo.tnsl | 6 +++++ 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 tnslc/compile/ast.tnsl create mode 100644 tnslc/compile/function.tnsl delete mode 100644 tnslc/compile/lexer.tnsl create mode 100644 tnslc/compile/variable.tnsl diff --git a/tnslc/compile/ast.tnsl b/tnslc/compile/ast.tnsl new file mode 100644 index 0000000..139597f --- /dev/null +++ b/tnslc/compile/ast.tnsl @@ -0,0 +1,2 @@ + + diff --git a/tnslc/compile/compile.tnsl b/tnslc/compile/compile.tnsl index eca0247..ed13e00 100644 --- a/tnslc/compile/compile.tnsl +++ b/tnslc/compile/compile.tnsl @@ -1,7 +1,9 @@ /; module compile + :import "variable.tnsl" + :import "function.tnsl" :import "module.tnsl" :import "tokenizer.tnsl" - :import "lexer.tnsl" + :import "ast.tnsl" :import "generator.tnsl" :import "error.tnsl" ;/ diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl new file mode 100644 index 0000000..a2d764b --- /dev/null +++ b/tnslc/compile/function.tnsl @@ -0,0 +1,10 @@ +struct Function { + ~uint8 name +} + +/; method Function + + /; end + ;/ +;/ + diff --git a/tnslc/compile/lexer.tnsl b/tnslc/compile/lexer.tnsl deleted file mode 100644 index e69de29..0000000 diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl index b33ae58..41890b3 100644 --- a/tnslc/compile/module.tnsl +++ b/tnslc/compile/module.tnsl @@ -1,11 +1,63 @@ struct Module { + ~uint8 name, ~Module parent, - utils.Vector vars + utils.Vector vars, funcs, submods, + bool exported } /; method Module - /; init (~Module parent) + /; init (~uint8 name, ~Module parent, bool exported) self.parent = parent - self.vars.init(1) + self.exported = exported + self.name = utils.strclone(name) + + Variable v + self.vars.init(len v) + Function f + self.funcs.init(len f) + Module m + self.submods.init(len m) + ;/ + + # Assumes that variable will be freed by this module + /; add_var (~Variable v) + self.vars.push(v) + ;/ + + # Assumes that function will be freed by this module + /; add_func (~Function f) + self.funcs.push(f) + ;/ + + # Assumes that submod will be freed by this module + /; add_sub (~Module s) + self.submods.push(s) + ;/ + + # Free all contained substructures + /; end + _delete(self.name) + + ~Variable v + /; loop (int i = 0; i < self.vars.count) [i++] + v = self.vars.get(i) + v`.end() + ;/ + + ~Function f + /; loop (int i = 0; i < self.funcs.count) [i++] + f = self.funcs.get(i) + f`.end() + ;/ + + ~Module s + /; loop (int i = 0; i < self.submods.count) [i++] + s = self.submods.get(i) + s`.end() + ;/ + + self.vars.end() + self.funcs.end() + self.submods.end() ;/ ;/ diff --git a/tnslc/compile/variable.tnsl b/tnslc/compile/variable.tnsl new file mode 100644 index 0000000..af6f6c1 --- /dev/null +++ b/tnslc/compile/variable.tnsl @@ -0,0 +1,9 @@ +struct Variable { + ~uint8 name +} + +/; method Variable + + /; end + ;/ +;/ diff --git a/tnslc/utils/algo.tnsl b/tnslc/utils/algo.tnsl index 1668e15..8426f9d 100644 --- a/tnslc/utils/algo.tnsl +++ b/tnslc/utils/algo.tnsl @@ -194,3 +194,9 @@ return str ;/ +/; strclone(~uint8 cstr) [~uint8] + Vector out + out.from_cstr(cstr) + return out.as_cstr() +;/ + -- cgit v1.2.3