Straight-line stack effects
Factor handbook » The language » Stack effect checking

Next:Combinator stack effects

The simplest case is when a piece of code does not have any branches or recursion, and just pushes literals and calls words.

Pushing a literal has stack effect ( -- x ). The stack effect of most words is always known statically from the declaration. Stack effects of inline words and Macros, may depend on literals pushed on the stack prior to the call, and this case is discussed in Combinator stack effects.

The stack effect of each element in a code snippet is composed. The result is then the stack effect of the snippet.

An example:
[ 1 2 3 ] infer.
( -- x x x )

Another example:
[ 2 + ] infer.
( x -- x )