ATS has a fairly sophisticated macro system, which, unfortunately, has barely been
documented.
Say I want to prettify Chiris Double's code:
https://github.com/doublec/openssl/blob/ats/ssl/d1_both.datsI can first introduce the following macros:
macdef int(x) = $UN.cast2int(,(x))
macdef ucharptr_succ (p) = ptr0_succ<char> (,(p))
macdef ucharptr_get (p) = $UN.ptr0_get<uchar> (,(p))
macdef ucharptr_set (p, c) = $UN.ptr0_set<uchar> (,(p), ,(c))
Instead of writing $UN.cast2int(payload), I can write (int)payload, which a C programmer
would probably prefer.
Similarly, a C programmer probably prefers ucharptr_set(p, c) over $UN.ptr0_set<uchar> (p, c).
Actually, n2s and s2n in Chris's code can take advantage of the support for call-by-reference
in ATS:
fun n2s (p: &ptr >> _): usint
fun s2n (p: &ptr >> _, x: usint): void
We can have the following if p is a left-value:
macdef ucharptr_incby1 (p) =
,(p) := ptr0_succ<char> (,(p))