Design for supporting meta-programming in ATS2

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

https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/LAMCAL

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

##ats2impl_compare2cmpops(tvar)

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

implement
lt_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) < 0)
implement
lte_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) <= 0)
implement
gt_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) > 0)
implement
gte_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) >= 0)
implement
eq_tvar_tvar(x1, x2) = (compare_tvar_tvar(x1, x2) = 0)
implement
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.)

–Hongwei