From 495aaeb6c074606747970e4fc98c387e6cda1a7c Mon Sep 17 00:00:00 2001 From: Mattias Hansson Date: Mon, 27 Oct 2025 19:43:33 +0100 Subject: [PATCH] Changed the delimiter between scope name and variable name to underscore and updated tests --- internal/compiler/symboltable.go | 4 ++-- internal/compiler/symboltable_test.go | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/compiler/symboltable.go b/internal/compiler/symboltable.go index d32877e..39e0fef 100644 --- a/internal/compiler/symboltable.go +++ b/internal/compiler/symboltable.go @@ -50,14 +50,14 @@ func (s *Symbol) IsWord() bool { return s.Has(FlagWord) } func (s *Symbol) IsConst() bool { return s.Has(FlagConst) } func (s *Symbol) IsAbsolute() bool { return s.Has(FlagAbsolute) } func (s *Symbol) IsZeroPage() bool { return s.Has(FlagZeroPage) } -func (s *Symbol) IsZeroPagePointer() bool { return s.HasAll(FlagAbsolute | FlagZeroPage) } +func (s *Symbol) IsZeroPagePointer() bool { return s.HasAll(FlagAbsolute | FlagZeroPage | FlagWord) } // FullName returns the fully qualified name (scope.name or just name) func (s *Symbol) FullName() string { if s.Scope == "" { return s.Name } - return s.Scope + "." + s.Name + return s.Scope + "_" + s.Name } // SymbolTable manages variable and constant declarations diff --git a/internal/compiler/symboltable_test.go b/internal/compiler/symboltable_test.go index 03932f5..3a02991 100644 --- a/internal/compiler/symboltable_test.go +++ b/internal/compiler/symboltable_test.go @@ -88,8 +88,8 @@ func TestSymbolFullName(t *testing.T) { expected string }{ {"global", "counter", "", "counter"}, - {"local", "temp", "main", "main.temp"}, - {"nested", "var", "outer.inner", "outer.inner.var"}, + {"local", "temp", "main", "main_temp"}, + {"nested", "var", "outer_inner", "outer_inner_var"}, } for _, tt := range tests { @@ -275,7 +275,7 @@ func TestLookup(t *testing.T) { st.AddVar("local", "main", KindByte, 0) // Local in nested function - st.AddVar("inner", "main.helper", KindByte, 0) + st.AddVar("inner", "main_helper", KindByte, 0) tests := []struct { name string @@ -303,21 +303,21 @@ func TestLookup(t *testing.T) { searchName: "local", currentScopes: []string{"main"}, expectFound: true, - expectFull: "main.local", + expectFull: "main_local", }, { name: "shadow global with local", searchName: "local", currentScopes: []string{"main"}, expectFound: true, - expectFull: "main.local", + expectFull: "main_local", }, { name: "find inner from nested scope", searchName: "inner", - currentScopes: []string{"main", "main.helper"}, + currentScopes: []string{"main", "main_helper"}, expectFound: true, - expectFull: "main.helper.inner", + expectFull: "main_helper_inner", }, { name: "not found", @@ -359,7 +359,7 @@ func TestExpandName(t *testing.T) { currentScopes []string expected string }{ - {"expand local", "local", []string{"main"}, "main.local"}, + {"expand local", "local", []string{"main"}, "main_local"}, {"expand global", "global", []string{"main"}, "global"}, {"no expansion needed", "notfound", []string{}, "notfound"}, } @@ -648,7 +648,7 @@ func TestGenerateScopedVariables(t *testing.T) { st.AddVar("global", "", KindByte, 0) st.AddVar("local", "main", KindByte, 0) - st.AddVar("nested", "main.helper", KindByte, 0) + st.AddVar("nested", "main_helper", KindByte, 0) lines := GenerateVariables(st) output := strings.Join(lines, "\n") @@ -657,10 +657,10 @@ func TestGenerateScopedVariables(t *testing.T) { if !strings.Contains(output, "global\t!8") { t.Error("expected global variable") } - if !strings.Contains(output, "main.local\t!8") { + if !strings.Contains(output, "main_local\t!8") { t.Error("expected scoped variable with full name") } - if !strings.Contains(output, "main.helper.nested\t!8") { + if !strings.Contains(output, "main_helper_nested\t!8") { t.Error("expected nested scoped variable with full name") } }