diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2024-03-07 04:53:40 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2024-03-07 04:53:40 -0500 |
commit | 234c99226ca1699832d411d0c326120607620ece (patch) | |
tree | 441a02b058960ad3a58edb9d699660a0413e370f | |
parent | 567eed5e49a927a31b2692c586da1246519fb1a9 (diff) |
fix a couple issues with dot eval
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | compiler.c | 11 | ||||
-rw-r--r-- | tests/test_method.tnsl (renamed from tests/test_method) | 0 | ||||
-rw-r--r-- | tests/test_module.tnsl | 7 |
4 files changed, 14 insertions, 5 deletions
@@ -1,3 +1,2 @@ ctc out -*.tnsl @@ -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.tnsl index 0f79400..0f79400 100644 --- a/tests/test_method +++ b/tests/test_method.tnsl 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 +;/ |