Taking the address of a direct struct instance in static initializer data
(pointer arrays and pointer-typed struct fields) worked on 6502 only. The
typed `&&` operator already provides the needed type, but the IR path broke
on targets without symbol prefixes:
- The virtual target skips symbol prefixing, so address-of symbols kept
their plain scoped names (`main.p1`) while the struct instance storage is
registered as `prog8_struct_instances.main_p1`. IRUnusedCodeRemover then
crashed with "no chunk with label 'main.p1'" (only when optimizing).
StConvert now resolves both the plain scoped form and the p8i_->p8v_
prefixed form used on 6502 and m68k targets.
- Both symbol prefixers rebuilt PtAddressOf nodes for static initializer
elements without their typed/msb flags; the flags are now preserved.
Allow `Point p` declarations with direct field access, initialization and
whole-struct copy (`q = p` lowers to sys.memcopy) on 32-bit and virtual
targets. 6502 targets reject with a clear error and keep using pointers or
arrays of struct instances.
Direct variables are represented as StStructInstance nodes with static
storage; field access resolves via PtrDereference and address-of/field
addresses use the struct-instances symbol labels. Adds array-literal-to-
struct-initializer lowering and avoids false frame-address-escape warnings.
- multi-value returns containing floats crashed the compiler: the FPx
return slots were routed through the int-register store path (passing
a -1 register number), and float forwarding ("return multi(...)") threw
"unexpected FP return register". Route FPx through the float path and
handle them in the generic load/store forwarding.
- the fp0 float staging register is also the first float return slot, so
storing later float return values clobbered an already-written fp0.
Defer the FP0-targeted float store until all other return stores are done.
- per-subroutine vreg renumbering compacted ints and floats into the same
numbers, and the A5 frame spill slots are keyed by number only, so an
int vreg and a float vreg could share one frame slot. Renumber floats
into a range disjoint from the ints.
- m68k codegen: multi-value returns were corrupted because the caller's
capture moves and the callee's epilogue both clobbered the return
registers d2-d4. Record the hardware return slots on the call site,
force-spill the transfer temporaries on both sides, and exclude a
subroutine's own return registers from its save set.
Fixes:
- M68K optimizer: prove index-register liveness before deleting scale
instructions in optimizeIndexedPointerLea.
- M68K optimizer: reject staged-add pair fold when the staged register is
also the add destination.
- M68K optimizer: prove removed flag-setting moves are dead before folding
staged adds or replacing pushes with pea.
- M68K optimizer: only treat full .l writes as redefinitions in the deadness
proof; byte/word partial writes keep the staged value live.
- M68K optimizer: treat add/sub/addq/subq to address registers as flag-
preserving (ADDA/SUBA semantics).
- M68K FPO: reject subroutines whose inline assembly mentions A5 (reads as
well as writes) and subroutines containing PUSH/POP/PUSHST/POPST.
- ADPCM wavc example: stop byte-swapping already-native m68k decoder output;
add deinterleave_16bit_stereo_be helper.
- M68K/new6502 backends and IR codec: preserve ImmediateOperand.SymbolAddress
offsets instead of dropping them; fix codec round-trip with type suffix.
- Clean up M68kMnemonics allFlagOverwriters classification for address-register
arithmetic.
- Remove unnecessary d1-d2 register saves in deinterleave_16bit_stereo_be.
A multi-assign returning one status flag plus register values used to
read the registers first, wrapped in PUSHST/POPST. That crashes the
68000 backend, which cannot save/restore CCR, and wastes two
instructions everywhere else. Extract the flag first instead: nothing
can clobber the status bits before it is captured, so no
preservation is needed. Multi-flag calls keep the old behavior.
add 8 IR opcodes (LOADMZ/LOADMS/LOADMZL/LOADMSL and the indexed
LOADI variants) and a peephole fusion pass that replaces
loadm/indexload followed by ext/exts/extl/extls with a single
extending load. Implemented for m68k, new6502 and the VM; run
deduplicateAddressComputations before fusion so it still sees the
unfused loadm+ext pairs.
appendSpillSlotsToFrame() now builds a per-subroutine type map because
renumberVregsPerSubroutine() reuses vreg numbers across subroutines with
different types. Using the global virtualRegisterTypes map caused spilled
pointer vregs to be sized as byte/word, producing unaligned stack slots
like -9(a5) and crashing 68000 / corrupting saved registers on 68020.