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:
  • Other modules used:

Documentation on exports

PREDICATE
Macro provided in order to know meta-predicate specifications accessible from a module.

Usage: imports_meta_pred(Module,MetaSpec,AccessibleAt)

  • Description: 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.

PREDICATE
This predicate is the main translation tool. It navigates through a clause body, when a single goal appears, user-code is called in order to perform a translation. Whether user-code fails to translate the involved goal, it remains the same. Regardless that goal is translated or not, an argument expansion will be performed over all goals if applicable (see arg_expander/6 predicate).

Variable (unknown at compile time) goals will also be attempt to translate.
Meta-predicate with arguments: body_expander((pred 3),(pred 3),(pred 3),?,?,?).

Usage: body_expander(GoalTrans,FactTrans,SpecTrans,Module,Body,ExpandedBody)

  • Description: 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.

PREDICATE
This predicate is an auxiliary translation tool, which is used by body_expander/6 predicate. It remains exported as a macro. The predicate navigates through the meta-argument specification of a goal. Whether a goal,fact or spec argument appears, user-code is called in order to perform a translation. Whether user-code fails to translate the involved argument, it remains the same. Builtins as ','/2 or ';'/2 are treated as meta-predicates defining goal meta-arguments. When a goal meta-argument is located, body_expander/6 will be called in order to navigate through it. Notice that a goal meta-argument may be unified with another goal defining another meta-argument, so navigation is required. If arguments are not known to arg_expander/6, translation will not occur. This is posible whether goal or qualifing module are variables.
Meta-predicate with arguments: arg_expander((pred 3),(pred 3),(pred 3),?,?,?).

Usage: arg_expander(GoalTrans,FactTrans,SpecTrans,Module,Goal,ExpandedGoal)

  • Description: 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

PROPERTY

Usage: expander_pred(Pred)

  • Description: 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.