Skip to content

Fragments

Andrew Johnson edited this page May 26, 2024 · 30 revisions

Fragments are the main data structure in the compiler used to represent output code objects as they are rendered. A Fragment is modelled as a map from Strings to S-Expressions. Fragments are available transparently to the type-system, compiler, AND the programmer. Fragments may be used to model a wide variety of code objects, so the data structure is fundamentally dynamic. Dynamic pattern matching is then used by the rest of the compiler to manipulate these Fragments. Functions that manipulate Fragments are also be exposed to the programmer within the rendering context. This interplay between dynamic and static objects creates the fundamental compilation unit throughout the entire compilation process.

What is a Fragment Type?

Fragments can have several associated Types. Each individual Fragment should have a direct Type. Each key on each Fragment may have a Type. Each S-Expression may have a Type, including potentially any smaller S-Expression.

Fragment Types form a basis for modelling and shaping output objects. This part isn't really clearly formed yet in practice, but in theory it should work OK.

Declaring a Fragment Type

Fragments are declared, if at all, just like normal data structures.

fragment type Reg8  AL  | BL  | CL  | DL  | SIL | DIL | BPL | SPL | R8B | R9B | R10B | R11B | R12B | R13B | R14B | R15B; size Reg8 1;
fragment type Reg16 AX  | BX  | CX  | DX  | SI  | DI  | BP  | SP  | R8W | R9W | R10W | R11W | R12W | R13W | R14W | R15W; size Reg16 2;
fragment type Reg32 EAX | EBX | ECX | EDX | ESI | EDI | EBP | ESP | R8D | R9D | R10D | R11D | R12D | R13D | R14D | R15D; size Reg32 4;
fragment type Reg64 RAX | RBX | RCX | RDX | RSI | RDI | RBP | RSP | R8  | R9  | R10  | R11  | R12  | R13  | R14  | R15;  size Reg64 8;
Clone this wiki locally