# CodeGen (`codegen.txt` 1746 lines, `CODEGEN.DEF/MOD`) MCode emitter with peephole folding + 2KB sliding window on the output file (`Scanner.global4`) + fixup queue for jumps. Opcodes: see `CODEGEN.MOD` const block (`OPLLD=08H ... OPCALL=0EDH ...`), consumed by `MCode_specification/*.mod`. ## State | old | proposed | |---|---| | global2/3/4 | `nextEmit/winBase/winLimit` (init 16/0/4096) | | global5 | `emitEnabled` | | global6 | `window[0..2047]` (`= ADR(Scanner.global21)`) | | global7/8/9/10 | `pendMode/pendSize/pendDisp/pendOff` | | global11/12 | `fixQueue[0..15]/fixCount` (`{kind,word1/word2\|ptr\|long}`) | | global14/15 | `pendFlag/checkOverflow` (`execute=4`) | ## Procedures (proposed) | old | proposed | |---|---| | Emit1/Emit2/EmitWord/EmitString | same (guard `OverflowGuard`, flush if full) | | proc19/20 | `PeekByte/PokeByte` (window or `SetPos+Read/WriteByte`) | | proc23 | `FlushWindow` (write 2048, slide tail) | | proc28 | `SeekWindow` (512-align, refill) | | proc29 | `OverflowGuard` (`nextEmit >= ComLine.codepos -> RAISE 281`) | | proc26 | `Assert` | | proc22/24 | `OpenEmit/InitCode` | | proc4 | `DiscardPend` | | proc5/30/31/32 | `SetPend/FlushPendOp/BaseOp/FlushQueue` (peephole: `LDIX/LONGREAL/LI/LB...`) | | proc8/9 | `QueueConst/QueueLong` | | proc6 | `EmitOp(sub,type)` (fold `NEG/power2/AND/EQ0`, types 0..5: long/short/DCOMP/REALCMP/set/extern) | | proc7 | `EmitExt` | | proc10 | `EmitStd` (`LIMIT` fold) | | proc11 | `EmitMisc` | | proc17/18 | `EmitSys/EmitExt3` | | proc12/13/14/15/16 | `OpenFix/CloseFix/InsertFix/AdjustFix/MarkFix` (short `224`-case vs word fixups) |