Concatenative topics
Concatenative meta
Other languages
Meta
Type inference in concatenative languages is often done by checking the stack effect declarations of words, against the sum of stack changes predicted to occur based on the items in their bodies.
Words that do not pass the stack-checker are generating a warning, and so essentially this defines a very basic and permissive type system that nevertheless catches some invalid programs and enables compiler optimizations.
The simplest case is when a piece of code does not have any branches or recursion, and merely 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.
@add ( a* b* -- c* ) Warning: Imbalance in @add of +2 DUP2 ADD2 JMP2r
This revision created on Wed, 6 Sep 2023 03:17:38 by entaloneralie (Created page)