`SymbolAddressOutput` emits wrong data (bank end instead of symbol address)
- Dominant language
- Scala
- Stars
- 279
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
When using the `addr:symbol` format specifier in a platform `.ini` file, the emitted bytes are not the little‑endian address of the symbol, but rather the little‑endian representation of the **bank's end address** (`b.end`).
**How to reproduce:**
1. Define a platform with output format containing `addr:vbl` (where `vbl` is a valid label).
2. Compile a program for that platform.
3. Observe that instead of `0C 02` (for address `$020C`), the output contains e.g. `11 02` (if bank ends at `$0211`).
**Cause:**
In `OutputPackager.scala`, the `SymbolAddressOutput` class incorrectly references `b.end` instead of the resolved symbol address `x`.
Current (buggy) code:
```scala
case class SymbolAddressOutput(symbol: String, bonus: Int) extends OutputPackager {
def packageOutput(flc: FileLayoutCollector, mem: CompiledMemory, bank: String): Array[Byte] = {
val b = mem.banks(bank)
val x = mem.getAddress(symbol) + bonus
Array(b.end.toByte, b.end.>>(8).toByte) // <-- WRONG: uses b.end
}
}
```
**Expected behavior:**
It should use `x` (the resolved address) and emit it in little‑endian order.
**Fix:**
```scala
case class SymbolAddressOutput(symbol: String, bonus: Int) extends OutputPackager {
def packageOutput(flc: FileLayoutCollector, mem: CompiledMemory, bank: String): Array[Byte] = {
val b = mem.banks(bank)
val x = mem.getAddress(symbol) + bonus
Array(x.toByte, x.>>(8).toByte) // <-- CORRECT
}
}
```
**Affected files:**
`src/main/scala/millfork/output/OutputPackager.scala` (line approx. 135)
**Workaround:**
Use `addr_be:symbol` and manually swap the two bytes in the resulting binary.
Contributor guide
Research direction
Open src/main/scala/millfork/output/OutputPackager.scala and inspect SymbolAddressOutput around line 135, then reproduce the addr:symbol case with the platform .ini setup described in the issue. Verify that the emitted bytes match the resolved symbol address in little-endian order, rather than the bank end address.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100