TC-E Samples
This example demonstrates the computation and display of escaping variables (and formal arguments). By default, all the variables must be considered as escaping, since it is safe to put a non escaping variable onto the stack, while the converse is unsafe.
let
var one := 1
var two := 2
function incr(x: int) : int = x + one
in
incr(two)
end
$ tc -XEAeEA variable-escapes.tig
/* == Abstract Syntax Tree. == */
function _main() =
(
let
var /* escaping */ one := 1
var /* escaping */ two := 2
function incr(/* escaping */ x : int) : int =
x + one
in
incr(two)
end;
()
)
/* == Abstract Syntax Tree. == */
function _main() =
(
let
var /* escaping */ one := 1
var two := 2
function incr(x : int) : int =
x + one
in
incr(two)
end;
()
)
$ echo $?
0
Compute the escapes after binding, so that the AST is known to be sane
enough (type checking is irrelevant): the EscapeVisitor
should
not bother with undeclared entities.
undeclared
$ tc -e undefined-variable.tig
undefined-variable.tig:1.1-10: undeclared variable: undeclared
$ echo $?
4
Run your compiler on merge.tig
and study its output. There is a
number of silly mistakes that people usually make on TC-E: they are all
easy to defeat when you do have a reasonable test suite, and once you
understood that torturing your project is a good thing to do.