From 234c99226ca1699832d411d0c326120607620ece Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Thu, 7 Mar 2024 04:53:40 -0500 Subject: fix a couple issues with dot eval --- .gitignore | 1 - compiler.c | 11 +++++++---- tests/test_method | 23 ----------------------- tests/test_method.tnsl | 23 +++++++++++++++++++++++ tests/test_module.tnsl | 7 +++++++ 5 files changed, 37 insertions(+), 28 deletions(-) delete mode 100644 tests/test_method create mode 100644 tests/test_method.tnsl create mode 100644 tests/test_module.tnsl diff --git a/.gitignore b/.gitignore index e19a730..14f23a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ ctc out -*.tnsl diff --git a/compiler.c b/compiler.c index b2ddcf9..7bab5c8 100644 --- a/compiler.c +++ b/compiler.c @@ -3435,6 +3435,8 @@ void p1_resolve_types(Module *root) { for (size_t i = 0; i < root->vars.count; i++) { Variable *v = vect_get(&root->vars, i); + // when created, the module was on the stack. Make sure it is not anymore. + v->mod = root; char *n_end = strchr(v->name, ' '); if (n_end == NULL) { @@ -3973,29 +3975,30 @@ Variable _eval_dot(Scope *s, CompData *data, Vector *tokens, size_t start, size_ return v; } - Variable v = {0}; - v.name = NULL; + Variable v = scope_get_var(s, &name); // Match with first possible variable start = tnsl_next_non_nl(tokens, start); for (; start < end; start = tnsl_next_non_nl(tokens, start)) { // Try match variable - v = scope_get_var(s, &name); - if (v.name != NULL) { + art_end(&name); + name = art_from_str("", '.'); break; } // Try expand artifact, or call t = vect_get(tokens, start); if (tok_str_eq(t, ".")) { + start++; t = vect_get(tokens, start); if (t->type != TT_DEFWORD) { printf("ERROR: Expected defword after '.' operator but found \"%s\" (%d:%d)\n\n", t->data, t->line, t->col); return v; } art_add_str(&name, t->data); + v = scope_get_var(s, &name); } else if (tok_str_eq(t, "(")) { // Call break; diff --git a/tests/test_method b/tests/test_method deleted file mode 100644 index 0f79400..0000000 --- a/tests/test_method +++ /dev/null @@ -1,23 +0,0 @@ -struct Vector { - ~void data, - int - size, - count, - _el_sz -} - -/; method Vector - - /; init - self.size = 69 - ;/ -;/ - -/; main [int] - - Vector a - a.init() - - return a.size - -;/ diff --git a/tests/test_method.tnsl b/tests/test_method.tnsl new file mode 100644 index 0000000..0f79400 --- /dev/null +++ b/tests/test_method.tnsl @@ -0,0 +1,23 @@ +struct Vector { + ~void data, + int + size, + count, + _el_sz +} + +/; method Vector + + /; init + self.size = 69 + ;/ +;/ + +/; main [int] + + Vector a + a.init() + + return a.size + +;/ diff --git a/tests/test_module.tnsl b/tests/test_module.tnsl new file mode 100644 index 0000000..394662b --- /dev/null +++ b/tests/test_module.tnsl @@ -0,0 +1,7 @@ +/; module Mod + int i = 69 +;/ + +/; main [int] + return Mod.i +;/ -- cgit v1.2.3