Code translation utilities
Author(s): Angel Fernandez Pineda.
This library offers a general way to perform clause body expansions. Goal, fact and spec translation predicates are authomatically called when needed, while this utility navigates through the meta-argument specification of the body itself. All predicates within this library must be called at second-pass expansions, since it uses information stored at c_itf library.
Usage and interface
- Library usage:
This library is provided as a tool for those modules which performs source-to-source code translation, usually known as code expanders. It may be loaded as other modules using a use_module/1. Nothing special needs to be done. - Exports:
- Predicates:
imports_meta_pred/3, body_expander/6, arg_expander/6.
- Predicates:
- Imports:
- System library modules:
compiler/c_itf. - Packages:
prelude, nonpure, assertions, hiord.
- System library modules:
Documentation on exports
Usage:imports_meta_pred(Module,MetaSpec,AccessibleAt)
Tells whether MetaSpec meta-predicate specification is accessible from Module. AccessibleAt will be binded to '-' whether meta-predicate is a builtin one. If not, it will be unified with the module which defines the meta-predicate.
- The following properties should hold at call time:
(basic_props:atm/1)Module is an atom.
(basic_props:term/1)MetaSpec is any term.
Variable (unknown at compile time) goals will also be attempt to translate.
Usage:body_expander(GoalTrans,FactTrans,SpecTrans,Module,Body,ExpandedBody)
Translates Body to ExpandedBody by the usage of user-defined translators GoalTrans, FactTrans and SpecTrans. The module where the original body appears must be unified with Module argument.
- The following properties should hold at call time:
(expansion_tools:goal_expander/1)GoalTrans is a user-defined predicate which performs goal meta-type translation
(expansion_tools:fact_expander/1)FactTrans is a user-defined predicate which performs fact meta-type translation
(expansion_tools:spec_expander/1)SpecTrans is a user-defined predicate which performs spec meta-type translation
(basic_props:atm/1)Module is an atom.
(term_typing:var/1)ExpandedBody is a free variable.
Usage:arg_expander(GoalTrans,FactTrans,SpecTrans,Module,Goal,ExpandedGoal)
Translates Goal to ExpandedGoal by applying user-defined translators (GoalTrans, FactTrans and SpecTrans) to each meta-argument present at such goal. The module where the original goal appears must be unified with Module argument.
- The following properties should hold at call time:
(expansion_tools:goal_expander/1)GoalTrans is a user-defined predicate which performs goal meta-type translation
(expansion_tools:fact_expander/1)FactTrans is a user-defined predicate which performs fact meta-type translation
(expansion_tools:spec_expander/1)SpecTrans is a user-defined predicate which performs spec meta-type translation
(basic_props:atm/1)Module is an atom.
(term_typing:var/1)ExpandedBody is a free variable.
Documentation on internals
Usage:expander_pred(Pred)
Pred is a user-defined predicate used to perform code translations. First argument will be binded to the corresponding term to be translated. Second argument must be binded to the corresponding translation. Third argument will be binded to the current module were first argument appears. Additional arguments will be user-defined.
Known bugs and planned improvements
- pred(N) meta-arguments are not supported at this moment.