lutra-bin 0.5.1

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

type Program: {
  main: Expr,
  defs: [TyDef]
}

type Expr: {
  kind: ExprKind,
  ty: Ty,
}

@derive(["Debug", "Clone", "enum_as_inner::EnumAsInner"])
type ExprKind: enum {
  Pointer: Pointer,
  Literal: Literal,
  Call: Call,
  Function: Function,
  Tuple: [TupleField],
  Array: [Expr],
  EnumVariant: EnumVariant,
  EnumEq: EnumEq,
  EnumUnwrap: EnumUnwrap,
  TupleLookup: TupleLookup,
  Binding: Binding,
  Switch: [SwitchBranch],
}

@derive(["Debug", "Clone", "enum_as_inner::EnumAsInner"])
type Pointer: enum {
  External: ExternalPtr,
  Binding: uint32,
  Parameter: ParameterPtr,
}

type ExternalPtr: {
  id: text,
}

@derive(["Debug", "Clone"])
type ParameterPtr: {
  function_id: uint32,
  param_position: uint8
}

@derive(["Debug", "Clone", "PartialEq", "enum_as_inner::EnumAsInner"])
type Literal: enum {
  bool: bool,
  int8: int8,
  int16: int16,
  int32: int32,
  int64: int64,
  uint8: uint8,
  uint16: uint16,
  uint32: uint32,
  uint64: uint64,
  float32: float32,
  float64: float64,
  text: text,
}

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

type Function: {
  id: uint32,
  body: Expr,
}

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

type EnumVariant: {
  tag: uint64,
  inner: Expr,
}

type EnumEq: {
  subject: Expr,
  tag: uint64,
}

type EnumUnwrap: {
  subject: Expr,
  tag: uint64,
}

type TupleLookup: {
  base: Expr,
  position: uint16,
}

type Binding: {
  id: uint32,
  expr: Expr,
  main: Expr,
}

# Contract: switch is guaranteed to match at least one branch
type SwitchBranch: {
  condition: Expr,
  value: Expr,
}

type TyDef: {
  name: Path,
  ty: Ty,
}

@derive(["Debug", "Clone"])
type Ty: {
  kind: TyKind,
  layout: enum { None, Some: TyLayout },
  name: enum { None, Some: text },
  variants_recursive: [uint16],
}

@derive(["Debug", "Clone", "PartialEq", "enum_as_inner::EnumAsInner"])
type TyKind: enum {
  Primitive: TyPrimitive,

  Tuple: [TyTupleField],

  Array: Ty,

  Enum: [TyEnumVariant],

  Function: TyFunction,

  Ident: Path,
}

@derive(["Debug", "Clone", "Copy", "PartialEq", "Eq", "Hash"])
type TyPrimitive: enum {
  bool,
  int8,
  int16,
  int32,
  int64,
  uint8,
  uint16,
  uint32,
  uint64,
  float32,
  float64,
  text,
}

@derive(["Debug", "Clone", "PartialEq"])
type TyTupleField: {
  name: enum { None, Some: text},
  ty: Ty,
}

@derive(["Debug", "Clone", "PartialEq"])
type TyEnumVariant: {
  name: text,
  ty: Ty,
}

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

@derive(["Debug", "Clone", "PartialEq"])
type TyFunction: {
  params: [Ty],
  body: Ty
}

@derive(["Debug", "Clone", "PartialEq", "Eq", "PartialOrd", "Ord", "Hash"])
type Path: [text]

type Module: {
  decls: [{name: text, decl: Decl}],
}

type Decl: enum {
  Module: Module,
  Type: Ty,
  Var: Ty,
}