Design for supporting meta-programming in ATS2


In the following project,
I outlined a design for supporting meta-programming in ATS2:

Broadly speaking, meta-programming means to write code that generates
code. There
two forms of codegen that I plan to support: external one and internal one.

(1) external codegen does code generation without need for internal
abstract syntax trees.

In lamcal_codegen.atxt, there are many atext-functions for external code
generation. For
instance, the following line


directs the generation of the following code (when it is processed by the
tool mytexting):

lt_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) < 0)
lte_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) <= 0)
gt_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) > 0)
gte_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) >= 0)
eq_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) = 0)
neq_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) != 0)

Of course, support for external codegen can be implemented in any
(scripting) language.
Using atexting is largely an experiment on my part. I am currently
thinking about trying out
PHP for this purpose.

(2) internal codegen does code generation that requires access to internal
abstract syntax trees.
For instance, the fprint-functions for tvar, term, and aterm are based on
code generated via internal
codegen. My hunch is that internal codegen can play a very big role in
support of domain-specific
programming (such as programming with session types, implementing hybrid
systems, etc.)