10.7. Boost package for macro manipulations

The MACRO_BOOST module provides utility macros for macro authors, including pattern matching on AST nodes, code generation helpers, and common transformation patterns used when writing compile-time code.

All functions and symbols are in “macro_boost” module, use require to get access to it.

require daslib/macro_boost

10.7.1. Structures

CapturedVariable

Stored captured variable together with the ExprVar which uses it

Fields:
  • variable : Variable? - captured variable

  • expression : ExprVar? - expression which uses the variable

  • eref : bool - this one indicates if its used by reference and does not come from argument. its only used in JIT

10.7.2. Function annotations

MacroVerifyMacro

Converts macro_verify(expr, message, prog, at) to equivalent inline code.

10.7.3. Implementation details

macro_verify(expr: bool; prog: ProgramPtr; at: LineInfo; message: string )

Same as verify, only the check will produce macro error, followed by return [[ExpressionPtr]]

Arguments:

10.7.4. Block analysis

capture_block(expr: ExpressionPtr ): array<CapturedVariable>

Collect all captured variables in the expression.

Arguments:
collect_finally(expr: ExpressionPtr; alwaysFor: bool = false; skipTryCatch: bool = false ): array<ExprBlock?>

Collect all finally blocks in the expression - array of ExprBlock? with a finally section. Does not go into ‘make_block’ expression, such as lambda, or ‘block’ expressions; skipTryCatch also stops at a try/recover arm, for a consumer emitting each arm as its own block

Arguments:
collect_labels(expr: ExpressionPtr; skipTryCatch: bool = false ): array<int>

Collect all labels in the expression. Returns array of integer with label indices. Does not go into ‘make_block’ expression, such as lambda, or ‘block’ expressions; skipTryCatch also stops at a try/recover arm, for a consumer emitting each arm as its own block

Arguments:

10.7.5. Expression analysis

has_sideeffects(expr: Expression? ): bool

Conservative side-effect detection. Returns true when the expression has — or might have — side effects. Returns false ONLY when provably pure (no function calls, no heap allocation, no container mutation).

Arguments: