summaryrefslogtreecommitdiff
path: root/tnslc
diff options
context:
space:
mode:
authorKai Gunger <kgunger12@gmail.com>2025-12-08 21:59:55 -0500
committerKai Gunger <kgunger12@gmail.com>2025-12-08 21:59:55 -0500
commit38723762d5e3c61dab16d6e40bc905b53e21baca (patch)
treea8a3211b089f837d78ac5de714cb83b97262c0ea /tnslc
parent8bb2e3bdb00341dcd8b6fd4d272b2c96a708acb3 (diff)
fix memory issues with type resolution
Diffstat (limited to 'tnslc')
-rw-r--r--tnslc/compile/codegen.tnsl5
-rw-r--r--tnslc/compile/module.tnsl22
-rw-r--r--tnslc/compile/var.tnsl6
3 files changed, 22 insertions, 11 deletions
diff --git a/tnslc/compile/codegen.tnsl b/tnslc/compile/codegen.tnsl
index ef668c7..2dfe9d5 100644
--- a/tnslc/compile/codegen.tnsl
+++ b/tnslc/compile/codegen.tnsl
@@ -18,10 +18,10 @@
# Transform into a module tree
Module mod
mod.init(~ast, ~buffer)
+ _gen_prims(~mod)
mod.update_children()
# Compile code
- _gen_prims(~mod)
mod.compile(~buffer)
mod.print()
@@ -39,13 +39,12 @@
/; _gen_prim(~Module m, int size, ~uint8 id)
~Module mds = m`._create_methods(id)
- mds`.parent = m
Var t
Struct s
s.size = size
- s.methods = mds
+ s.methods = NULL
s.members.init(len t)
s.name = utils.strcpy(id)
s._up = NULL
diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl
index eb7ce47..a60533a 100644
--- a/tnslc/compile/module.tnsl
+++ b/tnslc/compile/module.tnsl
@@ -44,20 +44,29 @@ struct Module {
self.e = mod`._type == parse.NTYPE_EXPORT
self._from_tree(mod, buf)
-
- ~Module sub
- /; loop (int i = 0; i < self.subs.count) [i++]
- sub = self.subs.get(i)
- sub`.update_children()
- ;/
;/
/; update_children
~Module sub
/; loop (int i = 0; i < self.subs.count) [i++]
sub = self.subs.get(i)
+ sub`.update_children()
sub`.parent = ~self
;/
+
+ ~Struct str
+ utils.Vector n
+ /; loop (int i = 0; i < self.structs.count) [i++]
+ str = self.structs.get(i)
+
+ n.from_cstr("_#\0")
+ n.push_cstr(str`.name)
+
+ sub = self._find_sub(n.as_cstr())
+ str`.methods = sub
+
+ n.end()
+ ;/
;/
/; _create_methods (~uint8 name) [~Module]
@@ -95,7 +104,6 @@ struct Module {
~Module m = self._create_methods(sub`.data)
Struct s
s.init(sub)
- s.methods = m
self.structs.push(~s)
;; else if (sub`._type == parse.NTYPE_FUNCTION)
Function f
diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl
index 34c101a..69108ce 100644
--- a/tnslc/compile/var.tnsl
+++ b/tnslc/compile/var.tnsl
@@ -122,7 +122,11 @@ struct Var {
_indent(idt)
_printf(" type: \0")
- _printf(self._type`.name)
+ /; if (self._type !== NULL)
+ _printf(self._type`.name)
+ ;; else
+ _printf("(nil)\0")
+ ;/
_printf("\n\0")
_indent(idt)