cc65: ca65: .include is broken somehow

I was using a macro in older sources of mine that doesn’t work any longer:

        .macpack cpu
        .macro  pfinc   what
                .if (.cpu .bitand CPU_ISET_65816)
                        .out .sprintf("Including %s-65816.inc", what)
                        .include .sprintf("%s-65816.inc", what)
                .else
                        .out .sprintf("Including %s-6502.inc", what)
                        .include .sprintf("%s-6502.inc", what)
                .endif
        .endmacro

        pfinc   "math"

After some digging, I found PR #1477 and PR #1503 and learned that this was broken deliberately. I don’t like it, but probably have to live with it.

I titled this “.include is broken” not because of the change but:

  1. The behavior now differs from what is described in the docs. Chapter 12 for example says “If that name is used in the source file, the macro is “expanded”, that is, it is replaced by the tokens that were specified when the macro was defined.”. This is no longer true. Chapter 10.5 describes how to use .concat with .include. But this does no longer work in macros. There are probably more places that need to get fixed.
  2. The behavior is inconsistent. Inside of a macro, almost none of the builtin functions work together with .include. Not .sprintf, not .concat, not .left, .right, .string, … Outside of a macro they work. This is bad and software should not work like this. Before the change, all this worked and was consistent. I consider this inconsistency a bug that should be fixed. Until then, all these problems should be documented. Breaking old code is bad enough, so the new solution should at least be ok.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Sure, that much we know already 😃 As i said - it will require a more sophisticated patch. Actually i think what @spiro-trikaliotis hinted at that he is working on - enabling the assembler to write the full generated code into the listing file - would involve some things that are also required for this one.