diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2025-12-07 19:07:20 -0500 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2025-12-07 19:07:20 -0500 |
| commit | db29085af649f8a42958898aaf2c3bfcef67f385 (patch) | |
| tree | 1252cdb1947701541e4898b80898f51743809e44 | |
| parent | daedfe9e1684ae855e2a4cf21249e1274ff8484d (diff) | |
change how methods are resolved
| -rw-r--r-- | tnslc/compile/function.tnsl | 2 | ||||
| -rw-r--r-- | tnslc/compile/module.tnsl | 25 | ||||
| -rw-r--r-- | tnslc/compile/scope.tnsl | 7 | ||||
| -rw-r--r-- | tnslc/compile/struct.tnsl | 21 | ||||
| -rw-r--r-- | tnslc/compile/var.tnsl | 5 |
5 files changed, 32 insertions, 28 deletions
diff --git a/tnslc/compile/function.tnsl b/tnslc/compile/function.tnsl index 73188b8..d55579e 100644 --- a/tnslc/compile/function.tnsl +++ b/tnslc/compile/function.tnsl @@ -108,7 +108,7 @@ struct Function { # Add all params to the scope ~Var in /; loop (int i = 0; i < self.inputs.count) [i++] - inp = self.inputs.get(i) + in = self.inputs.get(i) out.mk_set_var(in) ;/ diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl index c7ceab6..8e1fedc 100644 --- a/tnslc/compile/module.tnsl +++ b/tnslc/compile/module.tnsl @@ -23,8 +23,8 @@ struct Module { } /; method Module - - /; init (~parse.Node mod, ~CompBuf buf) + + /; _init Var v Struct s Function f @@ -36,7 +36,10 @@ struct Module { self.structs.init(len s) self.funcs.init(len f) self.subs.init(len m) + ;/ + /; init (~parse.Node mod, ~CompBuf buf) + self._init() self.name = utils.strcpy(mod`.data) self.e = mod`._type == parse.NTYPE_EXPORT @@ -57,6 +60,22 @@ struct Module { ;/ ;/ + /; _create_methods (~uint8 name) [~Module] + utils.Vector n + n.from_cstr("_#\0") + n.push_cstr(name) + + Module m + m._init() + m.name = n.as_cstr() + m.e = self.e + self.subs.push(~m) + + int i = self.subs.count - 1 + ~Module out = self.subs.get(i) + return out + ;/ + /; _from_tree (~parse.Node mod, ~CompBuf buf) ~parse.Node sub /; loop (int i = 0; i < mod`.sub.count) [i++] @@ -73,8 +92,10 @@ struct Module { m.init(sub, buf) self.subs.push(~m) ;; else if (sub`._type == parse.NTYPE_STRUCT) + ~Module m = self._create_methods(sub) 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/scope.tnsl b/tnslc/compile/scope.tnsl index 7dcf0ea..6e4d44d 100644 --- a/tnslc/compile/scope.tnsl +++ b/tnslc/compile/scope.tnsl @@ -156,13 +156,6 @@ struct Scope { # - # Add variables to the scope - # - - /; mk_set_var(~Var v) - ;/ - - # # Label generation # diff --git a/tnslc/compile/struct.tnsl b/tnslc/compile/struct.tnsl index 780e8ad..24f14cf 100644 --- a/tnslc/compile/struct.tnsl +++ b/tnslc/compile/struct.tnsl @@ -84,10 +84,10 @@ struct Struct { _printf("}\n\0") ;/ - /; add_member(~Module parent, ~parse.Node tn, ~parse.Node id) + /; add_member(~parse.Node tn, ~parse.Node id) Var v v.init(tn, id) - v._resolve_type(parent) + v._resolve_type(self.methods) self.members.push(~v) ;/ @@ -117,7 +117,7 @@ struct Struct { return NULL ;/ - /; _compute_size (~Module parent) + /; _compute_size /; if (self.size !== 0) return ;/ @@ -137,7 +137,7 @@ struct Struct { tn = n # Find type, compute size, set add_size to type size - ~Struct ft = self._find_type(parent, n) + ~Struct ft = self._find_type(self.methods, n) /; if (ft == NULL) # Type not found @@ -167,7 +167,7 @@ struct Struct { _printf("\n\0") return ;/ - self.add_member(parent, tn, n) + self.add_member(tn, n) total = total + add_size ;/ ;/ @@ -175,7 +175,7 @@ struct Struct { self.size = total ;/ - /; _find_type (~Module parent, ~parse.Node tn) [~Struct] + /; _find_type (~parse.Node tn) [~Struct] # Init vector of strings utils.Vector sv @@ -197,14 +197,9 @@ struct Struct { ;/ # Find struct and compute its size - ~Struct out = parent`.find(SEARCH_STRUCT, ~sv) + ~Struct out = self.methods`.find(SEARCH_STRUCT, ~sv) /; if (out !== NULL && out`.size == 0) - sv.pop() - ~Module outp = parent - /; if (sv.count !== 0) - outp = parent`.find(SEARCH_SUB, ~sv) - ;/ - out`._compute_size(outp) + out`._compute_size() ;/ sv.end() return out diff --git a/tnslc/compile/var.tnsl b/tnslc/compile/var.tnsl index 33c3973..34c101a 100644 --- a/tnslc/compile/var.tnsl +++ b/tnslc/compile/var.tnsl @@ -114,11 +114,6 @@ struct Var { self._id = id ;/ - /; _is_reg_passed [bool] - /; if () - ;/ - ;/ - /; _print (int idt) _indent(idt) _printf("{ Var : \0") |