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

Variable Declarations

VarDecl ::= Type ident ';'
Type    ::= PrimitiveType | 'ptr' '<' Type '>' | StructName

A variable declaration introduces one named value at PD-global scope or inside an event body. The bare Type ident; form is the only shape supported today; an initialiser (Type ident = expr;) is reserved but not yet parsed.

🚧 Initialiser syntax (= expr) is reserved but unparsed — see #105. For now, initialise locals from inside the body, and globals from the Constructor block or the imported source’s init() function.

Scopes

Variables can appear in two positions inside a .fi file:

  • Global — at the top level of the file, alongside Mapping and import declarations. Globals are visible everywhere in the PD, read/write inside event bodies and the constructor.
  • Local — inside a computation event body, between the : and end. Locals shadow globals of the same name. Their scope ends with the end of the enclosing event.

Process bodies cannot declare variables; any state needed by guards or process expressions must be promoted to a global.

The full scope-resolution order inside an event body is:

local → carrier → global

Carriers are the read-only inputs declared in the event header — see Event Blocks.

Primitive types

The primitive types accepted in declarations are:

GroupTokens
Signed integersint, int8, int16, int32, int64
Unsigned integersuint, uint8, uint16, uint32, uint64
Booleanbool
Byte aliasbyte (8-bit)
Empty typevoid

int and uint without a width default to 32-bit. byte is an alias for uint8.

Pointer and struct types

ptr<int>            // pointer to int
ptr<ptr<int>>       // pointer to pointer
struct rbd          // user-defined struct (parser support pending)

Pointer parsing exists in the grammar as 'ptr' '<' Type '>'; struct type parsing is reserved for a later revision and is gated on the struct-declaration grammar.

Examples

// Global declarations, top of a .fi file.
int counter;
bool ready;
uint64 last_irq_ts;

// Local declarations inside an event body.
Event handle_packet.|size: int|:
    int local_buf;            // local
    bool ok;                  // local
    local_buf = eth.alloc();  // assignment uses globals/locals/carriers
end

Validation

  • A variable name is unique within its enclosing scope (multiple globals with the same name are rejected; a local may legally shadow a global).
  • The type must be a recognised primitive, a pointer to a recognised type, or a declared struct (struct support pending).