These are ideas from a discussion on 2026-10-31. Nothing here is decided or
planned; open items are in TODO.md. Everything here comes after the
current work: readable names, documentation, the error check area fixes,
and fixing the original bugs. Those make the compiler's code clear enough
to extend.
New language features mean a "BB2 next" variant, not the faithful port. New keywords need token numbers, and tokenised sources should stay exchangeable with the original.
The last four sections, "Tooling: blitz2 on the host", "The compiler in a process of its own", "Tests: the TED A/B scripts without the CD" and "TED: a screen model of line positions", are no language changes.
- Varargs OS calls (ReAction): possibly the first step (section 0, discussion of 2026-10-31). A compiler change, so "BB2 next". Usable for ReAction only together with the constants of 1.
- C header import: independent, needs no compiler change for types and constants (functions do need library numbers, below), useful at once.
- Objects (OOP): a prerequisite for generics with constraints.
- Compilation units: independent of 1 and 2, but the most infrastructure (object format, link step, libraries). Much smaller if the Blitz libraries become hunk objects (below).
- Generics: last, building on 2.
Shared by 0, 1 (function libraries), 2 (Extends, New) and 4
(List<T>): new token and library numbers. A rule for how "BB2 next"
assigns them without breaking the exchange of tokenised sources with the
original might be the first building block of all.
ReAction (the BOOPSI classes of AmigaOS 3.2) builds its windows as trees
of objects with nested NewObject() calls and tag lists. BB2 supports
only the tag list forms well (NewObjectA_, SetAttrsA_ in deflibs).
Today (stmts.c stamigalib, blitz2.s:3879): every argument of an
OS call is evaluated left to right onto the stack, then popped into the
registers in reverse. So the arguments are on the stack already, but in
the wrong order for a tag list (tag 0 at the highest address).
- Fix of the order: after pushing, a small loop at run time reverses
the n longwords; then
a7is the tag list. The alternatives do not fit: evaluating right to left does not suit the parser; reserving a frame first and storing into it fails becausepevalpushes its own intermediate values. - Nesting works by itself: an inner call runs completely inside
peval(frame, call, stack cleanup), itsd0is the next argument.
Open: where the varargs go.
- A (preferred so far): a property of the OS call entry in deflibs
("the last register = a pointer to the remaining arguments"), with
names of their own such as
NewObject_,SetAttrs_,OpenWindowTags_. Fits the existing model; the call owns its stack frame.- The register byte of an entry uses bit 4 (address register) and bits
0-2 (number),
$ffends the list. An old compiler would read a new flag bit as a plain register and silently generate wrong code: such a deflibs needs the new compiler.
- The register byte of an entry uses bit 4 (address register) and bits
0-2 (number),
- B: a general expression such as
Tags(...)that gives a tag list on the stack to any existing...A_call. More flexible (e.g. a tag list kept in a variable?), but the lifetime of a stack area in the middle of apevalevaluation is tricky, and it needs a new keyword token.
Further open questions:
- Strings as tag values: what does
pevalwithT_LONGgive for"Ok"ora$(an address of 0-terminated data, or an error)? To check in the code. - Issue #344 (d2-d5 not saved for an Amiga library call in an
expression): nested
NewObject_expressions make it the normal case, so varargs depend on fixing it. TAG_END: written by the programmer, as in C, or appended by the compiler?DoMethod(RA_OpenWindow,RA_HandleInputinreaction/reaction_macros.h) is no LVO but an amiga.lib function: needs a routine of its own, orCallHookPkt(utility.library) with the class of the object (OCLASS(obj)). Its message is a varargs list as well.- The class libraries (
WINDOW_GetClass(),LAYOUT_GetClass(), ...): FD files are in the NDK (window_lib.fd,layout_lib.fd, ...), so they would become deflibs-like libraries, with library numbers. - The tag constants (
WINDOW_Layout,GA_Text, ...) exist only as C headers (gadgets/of the NDK: 30.h, only 3.i), as chains of#define NAME (OTHER + 0x...)across headers (REACTION_DummyisTAG_USER + 0x5000000): needs the C header import (1), at least its constants. reaction_macros.h(LayoutObject,ButtonObject,End) could become Blitz macros in a resident (residents hold macros).
[varargs OS calls] -----+
(compiler, deflibs) |
+--> [ReAction usable]
[constants from .h] -----+ ^
(host tool) |
[class libraries from FD] ----------+ (library numbers)
[DoMethod routine] -----------------+
Part of it exists: tools/blitzres writes residents with constants from
FD, EQU and LVO files. A C header import would add:
- Structs → NEWTYPE:
- field offsets by the m68k rules (2-byte alignment);
- unions, bitfields, nested structs, pointers.
- The resident format already holds types.
- Unions fit: a field in a resident has its offset stored, so overlapping offsets are possible (although NEWTYPE syntax cannot write them).
- Bitfields do not: there is no bit type. Possibly the enclosing word plus constants for the masks.
- Constants:
#define NAME value, enums; a small preprocessor for macros with expressions. - Functions: a prototype is not enough. Amiga library calls need the
LVO offset and the registers, from
.fd/.sfdor theproto/inlineheaders.blitzresalready reads FD files.- A resident holds only types, macros and constants. OS calls are
entries of type 6 in a library like deflibs (
docs/libs/deflibs.md,BLITZ_OSCALL), so imported functions mean a deflibs-like library with a library number and tokens (the token question above).
- A resident holds only types, macros and constants. OS calls are
entries of type 6 in a library like deflibs (
- Implementation: a host tool in C with its own small declaration parser. libclang is an alternative (Apache-2.0 with LLVM exception, compatible with GPL-3), but it is a heavy dependency.
- The compiler: unchanged for types and constants. The result is a
resident that
blitz2already loads. - A test exists already:
amigalibs.resof the CD is in effect an imported NDK (359 types, 98 macros, 4551 constants; fields as in the C headers,ln_Succa pointer to typeNode). Generating it again from the NDK and comparing with the CD's file checks the import. The comparison also shows the renaming rules: e.g.IntuiMessagehas_Qualifier,_MouseX(probably names that clash with BB2 tokens); a general import needs the same rule. - Open: the input.
- Assembler includes (
.i):STRUCTURE/APTR/UWORD/LABELgive the offsets mechanically, no C preprocessor;blitzresreads.ialready (--equ). Enough to reproduceamigalibs.res. - C headers (
.h): needed for third party libraries and for ReAction (its tag constants exist only as.h, section 0). - Possibly both:
.ifirst, withamigalibs.resas the test, then.h.
- Assembler includes (
"Objects" already means the library objects in BB2 (Shape, Screen,
...). Here it means object-oriented programming. The base exists:
NEWTYPE with field access through \, and procedures with locals. New
would be:
- Methods: procedures with an implicit
this(the object as the first parameter), called e.g. asa\Draw{x,y}. That must fit with today's\field access (parser). - Inheritance:
NEWTYPE .B Extends .A. The fields of.Aare the start of.B, so a pointer to.Bworks as an.A. - Virtual methods: a pointer to a method table in the object; the compiler emits the tables as data.
- Creation:
New/Freethrough memlib, possibly constructors.
This mainly touches the parser, the type handling and the code generation
of procedures (parse.c, compile.c, stmts.c).
Today blitz2 writes the executable directly:
- it pulls in the libraries itself (
fixjsrs); - it computes the object maxima for the whole program (
calcmaxs); INCLUDEis textual.
Separate units need:
- Object files:
HUNK_UNITwithHUNK_EXT, i.e. exported symbols and external references. vlink links Amiga hunk objects. - Visibility:
Public/Externfor variables, procedures and labels. Globals live in one block with fixed offsets today; across units the offsets must be resolved at link time (relocations). - Maxima and start-up:
- the object counts (
calcmaxs) and the start-up initialisation are merged over all units at the end; - so are the debugger and line information.
- the object counts (
- The Blitz libraries: vlink does not understand the Blitz library format, so they become hunk objects (next section).
Our build already makes the libraries as hunk objects. gcc writes a
.c.obj per file; only libs/blitzlib.ld and the post-processing turn
them into the one-hunk Blitz library format. The intermediate objects
would get metadata instead of being converted.
- Metadata (tokens,
!subs, library number, object definitions, maxima):- a data section of its own, e.g.
HUNK_DATAnamed.blitzmeta, that no symbol refers to; - the compiler and TED read it from the object file by its name
(
HUNK_NAME); - linking with garbage collection drops it, in debug and normal builds alike, so it never ends up as debug information.
- Not
HUNK_DEBUG: a debug link would carry it into the program as debug information. - A companion file per library (like today's token lists) would be the alternative.
- a data section of its own, e.g.
- init/finit: vlink's constructor/destructor collection (vbcc's
convention: functions named
__INIT_<prio>_<name>and__EXIT_<prio>_<name>become lists the start-up code calls). The priority replaces today's order of the libraries. - Commands as symbols:
- each command is an exported symbol, e.g.
_blitz_<lib>_<token>, and the compiler emits references instead of today'sfixjsrs; - with one section per routine (
-ffunction-sections) and vlink's garbage collection only what is used gets linked. Today a library always comes whole.
- each command is an exported symbol, e.g.
- Input validation (the error check area):
- its own sections: the check routines (
!subssuch asprescreen) and the error texts go in sections of their own, e.g..text.blitzcheck.prescreenvia__attribute__((section(...))); - why not
.text: garbage collection works per section, so in the same.textsection as the command, every reference to the command keeps the checks; - with "Runtime Errors": the compiler emits a call to the check before the command; the reference keeps the section;
- without: there is no reference, and the linker drops the checks. That is today's leaving out of the error check area, with no special logic;
- the 73 jumps per set from normal code into the error check area
(the
blitzlib checkwarnings) would simply be references and keep the check sections, silently. So they must be fixed first (TODO.md). A check that a link without "Runtime Errors" leaves no.text.blitzcheck.*section would succeedblitzlib check.
- its own sections: the check routines (
- Final link: vlink merges the many small sections into one code hunk (its option to merge sections).
- Limits:
- register conventions: the Blitz conventions (a3/a4/a5 fixed, parameters in d0-d5) stay an agreement between compiler and library; the linker does not check them;
- the original libraries: they exist only in the Blitz format and
need a converter, Blitz library → hunk object.
blitzlib checkandblitzlib comparealready read the format; - compatibility:
blitz2must read both formats, so olduserlibskeep working.
- To check in the vlink documentation:
- the exact garbage collection option (
-gc-all/-gc-empty); - the constructor naming and option;
- the option to merge sections;
- whether unreferenced data sections are dropped as expected.
- the exact garbage collection option (
Without a JIT, C#-style generics come down to shared code plus type information at run time:
- Shared code: a method of
List<T>is compiled once and works with a type descriptor (size, copy, compare, and for.sstrings the memory handling). C++, in contrast, makes a copy of the code per type. - Type checking at compile time:
List<.w>only takes words. - Constraints (
where T : IComparable) need interfaces, i.e. objects (2). - Value types: C# specialises the code per value type. Without a JIT the choice is boxing (slower) or still one specialisation per size.
This needs a real type system with type parameters. BB2 has none today:
types are suffixes (.b .w .l .q .f .s) and NEWTYPEs.
The idea: blitz2 runs as a console program on Linux, macOS or Windows and writes Amiga executables, as a cross-compiler. The compiler tests would then run without Amiberry, in seconds.
What blitz2 needs from the Amiga today:
- 68k code at compile time: constant expressions are compiled and run
(
eval.candlibcall.c, throughcallregs), with the float routines of the libraries (ffplib); float constants usemathffp(ffpcall). Byte-identical output needs a bit-exact FFP. - 32-bit big-endian memory: pointers are kept in
ULONGin many places, and the code buffer, the loaded libraries and the residents are read and written in place. - OS calls: dos (
Open,Read,Write,Seek,Lock,Examine,ExNext,CurrentDir),AllocMem/FreeMem,LoadSegfor residents;Supervisor/VBR,CacheClearU,CreateProc,Signal/Wait. - TED: blitz2 loads the editor and is called back by it; Run and the
debugger run the program in memory. On the host only "source in,
executable out" is left, as
ab3clidoes for blitz2-ab3. blitz2 itself would need a command line entry of the same kind.
Ways:
- A: run the unchanged 68k blitz2 in a user-mode runtime (a 68k CPU,
a flat big-endian memory, a hunk loader, the exec and dos calls mapped
to the host,
mathffp). The output equals the Amiga's by construction. volamos is such a runtime (Rust, Apache-2.0 OR MIT, before 1.0): dos withLoadSeg, exec, a realmathffp, volumes and assigns mapped to host directories; intuition is a stub, so only programs without TED. As an optional external program found throughPATH(like Amiberry; tests return 77 without it) it stays outside the build. Open: whether its JIT handles code generated and run at compile time (--no-jitotherwise). - B: build blitz2 natively for the host: the Amiga-side data in a
virtual 32-bit memory with accessors instead of pointers, a bit-exact
FFP in C, an embedded 68k CPU for the constant evaluation (or that
evaluation rewritten in C), an OS layer next to
glue_direct.c, and no editor, Run, debugger, supervisor or cache calls. Much more work, and every change must keep the Amiga build byte-identical.
A first step would be a spike outside the repository: ab3cli with
blitz2-ab3 under volamos on some ab3 and corpus programs, comparing the
executables with the ones from Amiberry.
The idea: TED starts the compile in a process of its own
(CreateNewProc) and stays responsive meanwhile, instead of running the
compiler in its own task through the menu routine until the compile ends.
What it would bring:
- Cancelling by a flag instead of an exception: TED sends the
compiler process
SIGBREAKF_CTRL_Cand the compiler checks it withCheckSignalinnextlineand stops cleanly, the AmigaOS counterpart of a cancellation token. Today the STOP gadget works through an exec exception (tc_ExceptCode,stopcode_cincompile.c) that interrupts the compiler anywhere. - TED stays responsive: it refreshes its windows and handles the STOP gadget in its own loop.
- Progress as messages: the progress of the compile (the comdata call
of the change
compile-progress-via-ted) becomes a message TED reads in its loop and draws when its screen is shown.
What makes it hard:
- The calls into TED: the compiler calls TED's services
synchronously (error requester, tokenising, file requester,
getinput, more than twenty entries ofcomdata). TED is not reentrant (global state, its own stack), so from another process each call has to become a message to TED and a wait for its answer. - Run and the debugger: blitz2 runs the compiled program from memory
(
CreateProcinmain.c) and catches its runtime errors; that depends on the task blitz2 runs in. - The original compiler with TED-C: it can only run synchronously in TED's task, so TED-C would need both ways.
- Stack and memory: the compiler sets its stack size itself
(
stackfuck); a process of its own gets its stack from TED.
No pthreads are needed: processes and message ports are native to AmigaOS.
15 TED A/B scripts load real sources from the CD (; @source K ...,
for example examples/blitzmode/blitzballs.bb2), so ctest --preset all skips them without the CD. Their value is that the sources are
real: long lines, Includes, many different tokens, old style.
- Own sources next to the CD's: for each script, a source of our own
that has what the script tests, and a variant of the script that uses
it in
all; the variant with the CD source stays inoriginals. Then nothing is missing without the CD, and the check on real sources stays. - The work: per script, find out what it needs from its source, write that source, record the expectation once from the original.
TED keeps a copy of the screen, chmap: one byte per cell with the
character already written out (a keyword as its letters, bit 7 meaning
"token colour"), and redraws from it - refresh, the two columns a
horizontal blitter scroll uncovers, a deleted character. A literal
character ($90 cc) does not fit that byte, so chmap holds a marker, and
the change ted-latin1-glyphs adds a whole-screen map of the literal
codes beside it.
The idea (user, 2026-11-13): store per cell not the character but where it comes from - the index of the element of the line (character or token) and, for a token, the offset into its name (0 for a character); a function maps a column of a line to that element. Everything is rendered once, scrolling uses the blitter as now, and a function redraws the dirty areas that scrolling or an overlap leave, by looking the cells up in the line. Characters, literals and tokens are then handled alike, and the screen can never show anything else than the line.
Cost: a rework of TED's screen model - every reader and writer of chmap
(typing in the cursor row, delete, the chmap scroll and erase in
core/tokit.c, loading, the mouse) - and a redraw that needs a valid line
also while the cursor row or a block operation changes it. It moves TED-C
away from the structure of ted.s that the comments, the TED A/B tests
and the host tests follow, so it is a change of its own.