A datcontag-function is very similar to a datcon-function. Given a datatype, its datcontag-function is the one that takes a value of the datatype and then returns the tag (which is a small integer) assigned to the (outmost) constructor in the construction of the value. We can use the following directive to indicate (to the ATS compiler) that the datcontag-function for the datatype expr needs to be generated:
By default, the name of the generated function is datcontag_expr_. If a different name is needed, it can be supplied as the third argument of the #codegen2-directive. For instance, the following directive indicates that the generated function is of the given name my_datcontag_expr: The following ATS code is expected to be generated that implements datcontag_expr_:(* ****** ****** *) // implement {}(*tmp*) datcontag_expr_ (arg0) = ( case+ arg0 of | Int _ => 0 | Var _ => 1 | Add _ => 2 | Sub _ => 3 | Mul _ => 4 | Div _ => 5 | Ifgtz _ => 6 | Ifgtez _ => 7 ) // (* ****** ****** *)
Please find on-line the entirety of this presented example plus a Makefile (for illustrating the code generation process).