define-transform ( word quot n -- )
Factor handbook » The language » Macros

Prev:MACRO:


Vocabulary
stack-checker.transforms

Inputs
worda word
quota quotation taking n inputs from the stack and producing another quotation as output
na non-negative integer


Outputs
None

Word description
Defines a compiler transform for the optimizing compiler. When a call to word is being compiled, the compiler first checks that the top n stack values are literal, and if so, calls the quotation with those inputs at compile time. The quotation can output a new quotation, or f.

If the quotation outputs f, or if not all inputs are literal, a call to the word is compiled as usual, or compilation fails if the word does not have a static stack effect.

Otherwise, if the transform output a new quotation, the quotation replaces the word's call site.

Examples
The cond word compiles to efficient code because it is transformed using cond>quot:
\ cond [ cond>quot ] 1 define-transform


Definition