ocaml/ocaml — pull request #98 by chambart (2014-09-04 15:49:51+00:00)
Title: Extended static exceptions: preparation for local functions

The Cmm and Mach intermediate representations can't express a lot of control flow without going through functions or exceptions. This patch series propose to extend the static exception mechanism.

The proposed features are:
* allowing (mutually-)recursive static exceptions:
( this is pseudo code, the patch contains no change before the cmm passes )
````ocaml
let fact x =
static_try
exit 0 (x, 1)
with 0 (x, acc) ->
if x = 0
then acc
else exit 0 (x-1, acc * x)
````
* indirect exit construction and static exception variables
````
let fact x =
static_try
exit 0 (x, 1) 0
with 0 (x, acc) k ->
if x = 0
then acc
else indirect_exit k (x-1, acc * x) k
````

This will allow to provide a cheap encoding of local functions: non-escaping tail-called functions.

Notes: the original loop constructions are removed from cmm and mach, and there is a cleaner implementation for allowing static exception to jump out of try/with. A few examples are provided in testsuite/tests/asmcomp/

The patch has been tested on amd64 and i386 on linux and lightly tested on arm(v7) and arm64 in qemu linux.