lutra-bin 0.5.1

Binary format library for Lutra: IR/RR encoding, decoding, and value representation
Documentation
submodule

type Program: {
  externals: [ExternalSymbol],
  main: Expr,
  defs: [project::ir::TyDef],
}

@derive(["Debug", "Clone", "PartialEq", "Eq", "Hash"])
type ExternalSymbol: {
  id: text,
  layout_args: [uint32],
}

type Expr: {
  kind: ExprKind,
}

@derive(["Debug", "Clone", "enum_as_inner::EnumAsInner"])
type ExprKind: enum {
  Pointer: Sid,
  Literal: [uint8],
  Call: Call,
  Function: Function,
  `Tuple`: `Tuple`,
  Array: Array,
  EnumVariant: EnumVariant,
  EnumEq: EnumEq,
  Offset: Offset,
  Deref: Deref,
  Binding: Binding,
  Switch: [SwitchBranch],
}

## Symbol id.
## - 0b00xxxxxx - external
## - 0b01xxxxxx - local bindings
## - 0b10xxxxxx - function scopes
## - 0b11xxxxxx - unused
@derive(["Debug", "Clone", "Copy", "PartialEq", "Eq", "Hash"])
type Sid: uint32

type Call: {
  function: Expr,
  args: [Expr],
}

type Function: {
  symbol_ns: Sid,

  # can contain function parameters prefixed with symbol_ns
  body: Expr,
}

type Tuple: {
  fields: [TupleField],
  field_layouts: [TyLayout]
}

type TupleField: {
  expr: Expr,
  unpack: uint8,
}

type Array: {
  item_layout: TyLayout,
  items: [Expr],
}

type EnumVariant: {
  tag: [uint8],
  inner_bytes: uint8,
  has_ptr: bool,
  padding_bytes: uint8,
  inner: Expr,
}

type EnumEq: {
  tag: [uint8],
  expr: Expr,
}

type Offset: {
  base: Expr,
  offset: uint32,
}

type Deref: {
  ptr: Expr,
}

type Binding: {
  symbol: Sid,
  expr: Expr,
  main: Expr,
}

type SwitchBranch: {
  condition: Expr,
  value: Expr,
}

@derive(["Debug", "Clone", "PartialEq", "Default"])
type TyLayout: {
  head_size: uint32,
  body_ptrs: [uint32],
}