From 1de32dbcac6a7a9756df034b914a4a836ca5bbac Mon Sep 17 00:00:00 2001 From: Kai Gunger Date: Fri, 1 May 2026 02:09:47 -0400 Subject: [tnslc] self in method --- tnslc/breakdown.png | Bin 168313 -> 0 bytes tnslc/compile/function.tnsl | 34 ++++++++++++++++++++++++++++++++++ tnslc/compile/module.tnsl | 29 ++++++++++++++++++++++++++--- tnslc/compile/var.tnsl | 25 +++++++++++++++++++------ tnslc/layout_generator.png | Bin 338881 -> 0 bytes tnslc/test.tnsl | 23 ++++++++++++++++++++--- 6 files changed, 99 insertions(+), 12 deletions(-) delete mode 100644 tnslc/breakdown.png delete mode 100644 tnslc/layout_generator.png diff --git a/tnslc/breakdown.png b/tnslc/breakdown.png deleted file mode 100644 index dc5ce77..0000000 Binary files a/tnslc/breakdown.png and /dev/null differ diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index bde7d2c..f945479 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -25,6 +25,29 @@ struct Function { ~parse.Node n int reg = 1 int stack_up = 8 + + /; if (self.m == true) + ~Struct s = parent`.related_type() + Var p + p._init(s) + _delete(p.name) + p.name = utils.strcpy("self\0") + p.ptr_push(0) + p.loc = reg + reg++ + self.inputs.push(~p) + _printf("Generated self:\n\0") + p._print(0) + ;; else + _printf("Did not generate self for \"\0") + _printf(self.name) + _printf("\"\n\0") + ;/ + + /; if (dl == NULL) + return + ;/ + /; loop (int i = 0; i < dl`.sub.count) [i++] n = dl`.sub.get(i) /; if (n`._type == parse.NTYPE_TYPE) @@ -86,6 +109,9 @@ struct Function { /; _resolve_type (~Module parent) ~parse.Node _up = self._up /; if (_up`.sub.count < 1) + /; if (self.m == true) + self._resolve_dlist(parent, NULL) + ;/ return ;/ @@ -95,6 +121,8 @@ struct Function { /; if (_up`.sub.count > 1) lst = _up`.sub.get(1) ;/ + ;; else if (self.m == true) + self._resolve_dlist(parent, NULL) ;/ /; if (lst`._type == parse.NTYPE_TLIST) @@ -192,6 +220,12 @@ struct Function { ~Var in /; loop (int i = 0; i < self.inputs.count) [i++] in = self.inputs.get(i) + /; if (in.is_ref()) + ~int32 ptc = in.top_ptrc() + int32 set = 0 + set = set - 1 + ptc` = set + ;/ out.mk_set_var(in) ;/ diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl index 17e4984..d3deb2f 100644 --- a/tnslc/compile/module.tnsl +++ b/tnslc/compile/module.tnsl @@ -96,17 +96,40 @@ struct Module { return false ;/ - /; if (self.name{0} !== '_') + ~uint8 name = self.name + + /; if (name{0} !== '_') return false - ;; else if (self.name{1} !== '#') + ;; else if (name{1} !== '#') return false - ;; else if (self.name{2} == '#') + ;; else if (name{2} == '#') return false ;/ return true ;/ + /; related_type [~Struct] + /; if (self.is_method() == false) + return NULL + ;/ + + ~Module m = self.parent + ~Module match = ~self + ~Struct s + /; loop (int i = 0; i < m`.structs.count) [i++] + s = m`.structs.get(i) + /; if (s`.methods == match) + return s + ;/ + ;/ + + _printf("COMPILER ERROR: UNABLE to find a sutable struct for module \"\0") + _printf(self.name) + _printf("\"\n\0") + return NULL + ;/ + /; _from_tree (~parse.Node mod, ~CompBuf buf) ~parse.Node sub /; loop (int i = 0; i < mod`.sub.count) [i++] diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index cc5b409..f41d233 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -135,6 +135,8 @@ struct Var { self.offset = 0 self._type = _type self.parent = NULL + self._tn = NULL + self._id = NULL ;/ # Initial init function, requires type node and @@ -165,8 +167,14 @@ struct Var { # A copy without the pointer chain /; shallow_copy [Var] Var out - out.init(self._tn, self._id) - out._type = self._type + /; if (self._tn !== NULL) + out.init(self._tn, self._id) + out._type = self._type + ;; else + out._init(self._type) + _delete(out.name) + out.name = utils.strcpy(self.name) + ;/ out.loc = self.loc out.offset = self.offset return out @@ -215,7 +223,7 @@ struct Var { # Ref level /; max_ref [int] int out = 0 - /; loop (int i = 0; i < self.ptrc.count) + /; loop (int i = 0; i < self.ptrc.count) [i++] /; if (self.is_ptrc(i, 0) == true) out++ ;; else @@ -1089,6 +1097,9 @@ struct Var { out = utils.strcpy("[rdi]\0") ;/ + /; if (out{0} == '[') + ;/ + return out ;/ @@ -1212,10 +1223,11 @@ struct Var { int32 set = 0 set = set - 1 - max_depth = copy.ptrc.count - max_depth + max_depth = self.ptrc.count - max_depth + max_depth = max_depth + depth Var copy = self.copy() - ~int32 ptr = copy.ptrc.get(max_depth + depth) + ~int32 ptr = copy.ptrc.get(max_depth) ptr` = set copy.set(buf, other) copy.end() @@ -1662,7 +1674,8 @@ struct Var { out.loc = self.loc out.offset = out.offset + self.offset ;/ - + + # out._print(0) return out ;/ diff --git a/tnslc/layout_generator.png b/tnslc/layout_generator.png deleted file mode 100644 index 4e1c05c..0000000 Binary files a/tnslc/layout_generator.png and /dev/null differ diff --git a/tnslc/test.tnsl b/tnslc/test.tnsl index 3c89339..66091f7 100644 --- a/tnslc/test.tnsl +++ b/tnslc/test.tnsl @@ -1,7 +1,24 @@ +struct A { + int a, b +} -/; main [int] - int a = 0 - return a +/; method A + /; get_a [int] + return self.a + ;/ +;/ + +/; module mod + /; func1 [int] + return 4 + ;/ +;/ + +/; main (int argc, ~~uint8 argv) [int] + asm "mov r10, rdi" + asm "mov r11, rsi" + + return argc ;/ -- cgit v1.2.3