Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data Layer: Structs and Constants

StructDecl ::= Attr? 'struct' ident '{' Field* '}'
Attr       ::= '@attr' '(' 'packed' (',' 'packed')* ')'
Field      ::= ident ':' Type ';'
Type       ::= BaseType ('[' ArrayLen ']')?
BaseType   ::= ScalarType | ident            // ident names a declared struct
ArrayLen   ::= integer-literal | ident       // ident names a declared constant
ConstDecl  ::= 'const' ident ':' Type '=' Expr ';'

The data layer is the system-wide vocabulary of payload struct types and layout constants. It is shared by every protection domain — and, through generated type headers, by the external low-level implementations (C, Pancake) too, so the model and the code agree on one definition. It lives as flat, top-level items in the .fis file: like the rest of the system description, declarations are visible to every .fi program with no import ceremony.

const PACKET_BUFFER_SIZE: int = 2 * 1024;

struct Packet {
    length:  uint16;                    // valid bytes in payload (≤ capacity)
    payload: byte[PACKET_BUFFER_SIZE];  // fixed-capacity buffer
}

const RING_BYTES: uint = 64 * sizeof(Packet);

Structs

  • Names use UpperCamelCase by convention.
  • Fields are flat — primitives, other declared structs, or fixed-size arrays of those; no pointers.
  • Fixed-size arrays T[N]: the length N is an integer literal or a declared integer const (e.g. byte[PACKET_BUFFER_SIZE]), so the size stays statically known: sizeof(T[N]) = N * sizeof(T).
  • No recursion: a struct may not contain itself, directly or indirectly. This guarantees sizeof is computable at compile time by recursive field traversal.
  • Fields must have fixed-width types so the layout is well-defined: int, uint and Address have no fixed size and are rejected in a struct (uint32, not uint), as is a struct nesting one that has none. An array has one length: T[N], not T[N][M].
  • Field names within a struct are distinct.
  • Layout is C’s on the target, fields in declaration order: each field at the next offset that is a multiple of its alignment (a scalar’s is its size, an array’s its element’s, a struct’s its largest field’s), and the size rounded up to the struct’s alignment, so { a: uint64; b: uint16; } is 16 bytes with b at 8. The generated headers assert it (a _Static_assert on each struct’s size in types.h), so a C compiler that would lay the struct out differently fails the build.
  • @attr(packed) before struct packs it, as C’s __attribute__((packed)): no padding, each field right after the one before, alignment 1, so @attr(packed) struct W { a: uint8; b: uint32; } is 5 bytes with b at 1. A struct nested in it keeps its own padding. Packing is for wire formats: a misaligned field is slower to read, and on device memory or under an atomic, an aarch64 fault.
  • Struct names are usable wherever a type is expected — variable declarations, typed channel buffers (via buf<Packet>), and sizeof.

Constants

  • Names use SCREAMING_SNAKE_CASE by convention (any identifier is accepted); a declared type is required. Unlike a struct field, a constant may have an unsized type such as int or uint.
  • The right-hand side is a full expression, folded at compile time (rustc-style, before any lowering). The const subset covers: literals, references to previously declared constants, sizeof(T), and unary/binary arithmetic, bitwise, shift, comparison, and logical operators.
  • Function calls, runtime variables, and field access are rejected in const position. Forward references between constants are errors — declare in dependency order.
  • The folded value must match the declared type (bool constants take boolean values; integer-family types take integers).

One home for structs

Every struct is declared in the .fis. A program names them as any other type, for its locals and body variables, and so do the C and Pancake files it imports.

fic writes the structs and constants to include/gen/types.h (and, for Pancake, the constants to include/gen/types.pnk), included as "gen/types.h" with <project>/include on the include path.

Global state

The data layer declares types and constants, not mutable state. A program’s own variables are its protection domain’s state (see Variable Declarations); state shared across domains is exactly the channel-buffer view: mutable data lives in declared memory regions, mapped explicitly into the PDs that may touch it and labelled for information flow. A shared scalar is a typed slot of a declared region — never an ambient global.