mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-19 07:45:09 +00:00
Estimated hours taken: 30 Modify the MLDS back-end to support the `--no-gcc-nested-functions' option. compiler/ml_elim_nested.m: New module. Contains an MLDS->MLDS transformation pass to eliminated nested functions. compiler/mercury_compile.m: Call the new pass. compiler/notes/compiler_design.html: Mention the new module. compiler/ml_code_gen.m: If --no-gcc-nested-functions is specified, then pass environment pointers to the nested continuation functions. Note that most of the work of converting nested functions into non-nested functions is deferred to the ml_elim_nested pass. But the passing of environment pointers affects the calling convention, and so it really needs to be done here -- it can't be done in any semantics-preserving MLDS transformation later one. Also it is easier to do it in this pass anyway. Also fix a bug where it was miscalculating the set of variables to declare. compiler/mlds.m: - Add a new alternative `mlds__generic_env_ptr_type', used for environment pointers. - Add a new alternative `mlds__class_type' to the `mlds__type' discriminated union, so that types can include user-defined types. This is needed so that we can define struct types for the nested function enviroments. As part of that change, rename `mlds__class' as `mlds__class_defn'. - Change the argument type for the `do_commit' and `try_commit' instructions from `var' to `rval'/`lval'. This is needed so that these instructions can refer to references defined in the containing function via the environment pointer. compiler/mlds_to_c.m: - Changed to reflect the renaming of `mlds__class' as `mlds__class_defn'. - Changed to reflect the change to the `do_commit' and `try_commit' argument types. - For the `mlds__cont_type' type, output it as either `MR_NestedCont' or `MR_Cont', depending on whether the `--gcc-nested-functions' option is enabled. - Fix a bug where it would incorrectly parenthesizing the left-hand operand of `->'. - Insert some additional blank lines in the output, for readability. runtime/mercury_types.h: - Rename the old `Cont' type as `MR_NestedCont', and add a new `MR_Cont' type.