Prolog /
AboutExpansionECLiPSe Expansion mechanisms
read-macrosDone after every read (within the compiler or not). Defined for
Only terms that result directly from reading are transformed. This means no fixpointing, since the result of a transformation does not itself result from reading. Terms are transformed bottom-up, so that each transformation sees terms whose arguments have already been transformed. Nevertheless, a transformation predicate could recursively call the expansion on the result of its own transformation if so desired (e.g. if it is intended to simulate parsed input). There is an option to prevent transformation of arguments - this is probably only useful to implement a "quoting" functor. The latter is often needed in code that manipulates pre-expansion terms, e.g. the transformation itself. goal expansion (inlining)Applied to goals in clause bodies before compilation. Visibility of the expansion is linked to the visibility of a predicate, i.e. it is local, exported, imported along with the predicate definition. Transformation is top-down, automatically recognizing only the basic control structures. Arguments of meta-predicates are not automatically transformed. If this is wanted, the programmer has to define a transformation for the metapredicate that recursively invokes transformation on the meta-arguments. Goal expansion is not applied to meta-called goals! The reasoning behind this is that it is considered an optimization, so that expanded and unexpanded code are supposed to behave identically. In other words, a predicate cannot be implemented by expansion alone, it always needs clauses that do the same job. In the simplest case, the predicate code can consist of a clause that invokes the expansion explicitly, and metacalls the result. The toplevel has an option to expand its goals before execution. This can help with debugging of expansion-related issues. clause expansionApplied to clauses that belong to a particular functor and are compiled into a particular module. No issues with transformation order and fixpointing, as clauses cannot be not nested. This is the expansion that is used to implement grammar rules, CHRs, etc. Source informationAll 3 expansions can optionally handle and transform the source location annotation provided by the parser. |