sasq64 / bass

Advanced 6502 assembler
23 stars 4 forks source link

error out on accessed label redefinition #39

Closed antis81 closed 1 year ago

antis81 commented 1 year ago

Boils down to is_redefinable returning true when it should not…

Debugging Info

Running bass with debugging options shows the issue (surprisingly already in PASS 1):

builds/debug/bass tests/err_access_def_redef.asm --no-cache --show-undefined --symbols --max-passes=1 |less -RN

Outputs

      1 * PARSING
      2 * PASS 1
      3 Access undefined 'testlabel'
      4 Defined testlabel
      5 Redefined testlabel from 4 to 6
      6 :0: error: Max number of passes

(where 4 and 6 are the correct byte offsets to nop respectively rts)

Running with more passes results in 6 and 4 being exchanged endlessly…

antis81 commented 1 year ago

Interesting… removing line symbol_table:161 kind of improves situation and detects the error. However the testlabel value still changes (4 -> 6). Plus… this breaks the bcc target in our (new) section_move test (5 vs 255).

Noteworthy that the undefined list becomes only(!) relevant together with accessed context. Maybe we should rename "final" to "has_value" or something…? This is how I at least understand it… :slightly_smiling_face:

antis81 commented 1 year ago

Wait a second… Can't we rather check on the section (label?) explicitly in this case when a section is "yet to be defined"? For the section_move test this relates to section.util.start and/or section.main.end (both equal in this case). In pseudo code:

SymbolTable::set(std::string s) {
  // … handle other preconditions on the symbol …

  // insert symbol into "syms" set
  auto& sym = syms[s];  

  // Symbol gets a value at this point
  sym.value = "some value"; // always assigning the value may help with debugging>

  // If section (label) is not in a final state, every address label inside also cannot be final (in this current PASS)
  auto const& current_section = get_current_section(); // How to reteive?
  sym.final = current_section.final;  // maybe the "final" state should be completely moved to section…??
}

Sounds not too bad don't you think?

sasq64 commented 1 year ago

Well, the symbol table does not know anything about the assembler and its workings so that wouldn't fly.

The main problem is that I have not clearly defined how things should work with undefined & redefined symbols.

One issue is what the type should be of an undefined symbol? Right now it always becomes a number.

Another problem is how to support dot-symbols.

Was there a specific use case/example you where trying to solve?

antis81 commented 1 year ago

Was there a specific use case/example you where trying to solve?

Yeah now it's becoming history… :slightly_smiling_face: Originally bass from master (d2bb375) fails against my project code with "max number passes"… Removing the mentioned "undefined.insert…" line worked "good enough".

sasq64 commented 1 year ago

So now the tests work. You are not allowed to redefine symbols normally. Final should be the default really, but this was an easier fix for now.