diff options
| author | Kai Gunger <kgunger12@gmail.com> | 2025-12-25 02:31:36 -0500 |
|---|---|---|
| committer | Kai Gunger <kgunger12@gmail.com> | 2025-12-25 02:31:36 -0500 |
| commit | 0c7403f5894d46f513f8b57fb6fabbd568c9f5af (patch) | |
| tree | 24c17573f3838234558bd6076fcb812650608999 /tnslc/compile/module.tnsl | |
| parent | 871bec579241882e8b05eb17cf177652e4f37781 (diff) | |
Add functions to member modules
Diffstat (limited to 'tnslc/compile/module.tnsl')
| -rw-r--r-- | tnslc/compile/module.tnsl | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tnslc/compile/module.tnsl b/tnslc/compile/module.tnsl index e46c219..437edff 100644 --- a/tnslc/compile/module.tnsl +++ b/tnslc/compile/module.tnsl @@ -118,6 +118,83 @@ struct Module { ;/ ;/ + /; _method_id (~uint8 id) [utils.Vector] + utils.Vector tmp + tmp.init(1) + utils.Vector out + out.init(8) + + ~uint8 str + + /; loop (id` !== 0) [id++] + /; if (id` == '.') + str = tmp.as_cstr() + out.push(~str) + tmp.init(1) + ;; else + tmp.push(id) + ;/ + ;/ + + str = tmp.as_cstr() + ~uint8 last = utils.stradd("_#\0", str) + _delete(str) + out.push(~last) + + return out + ;/ + + /; _method_id_end(~utils.Vector v) + ~~uint8 str + /; loop (int i = 0; i < v`.count) [i++] + str = v`.get(i) + _delete(str`) + ;/ + v`.end() + ;/ + + /; _collect_methods(~parse.Node m) + ~parse.Node sub + /; loop (int i = 0; i < m`.sub.count) [i++] + sub = m`.sub.get(i) + + /; if (sub`._type == parse.NTYPE_FUNCTION) + Function f + f.init(sub) + f.m = true + self.funcs.push(~f) + ;/ + ;/ + ;/ + + /; collect_methods (~parse.Node mod) + ~parse.Node sub + /; loop (int i = 0; i < mod`.sub.count) [i++] + sub = mod`.sub.get(i) + /; if (sub`._type == parse.NTYPE_METHOD) + utils.Vector id = self._method_id(sub`.data) + ~Module m = self.find(SEARCH_SUB, ~id) + /; if (m !== NULL) + _printf("Found module for method\n\0") + m`._collect_methods(sub) + ;; else + _printf("Failed to find module for method\n\0") + ;/ + _method_id_end(~id) + ;; else if (sub`._type == parse.NTYPE_MODULE) + ~Module m = self._find_sub(sub`.data) + /; if (m !== NULL) + m`.collect_methods(sub) + ;/ + ;; else if (sub`._type == parse.NTYPE_EXPORT) + ~Module m = self._find_sub(sub`.data) + /; if (m !== NULL) + m`.collect_methods(sub) + ;/ + ;/ + ;/ + ;/ + /; _decl (~parse.Node decl) /; if (decl`.sub.count < 1) return |