From: Jean Privat Date: Wed, 15 Oct 2014 20:15:47 +0000 (-0400) Subject: Merge: transform loops X-Git-Tag: v0.6.10~30 X-Git-Url: http://nitlanguage.org Merge: transform loops In order to activate more optimizations and simplify code generators and analysis, the `while` and `for` loops must be transformed into simpler forms (in fact in complex forms but with simpler elements) However, to do such a transformation, the escaping mechanism (break/continue/goto) must be rewrote. Previously, for each loop control structure (loop for, while), a single EscapeMark was generated and breaks and continues are associated to the same mark, even if they branch in distinct points (so each escapemark had 2 branching mechanisms) Now, with the first commits, two escapemarks are generated for each loop control structure, and breaks and continues are associated to a different one. The advantage is that each mark only have a single branching mechanism and that once associated to their mark, there is no need to distinguish break and continue (both become simple gotos). The transformations of loops can be then implemented. The `while` ~~~ while cond do block ~~~ is transformed into ~~~ loop if cond then block else break ~~~ and `for` ~~~ for i in col do block ~~~ is transformed into ~~~ var it = col.iterator loop if it.is_ok then var i = it.item do block # ^ `continue` in the block it attached to the `do` # this is why the transformation of escape-marks where needed in fact. # and break is associated to the main loop it.next else break end end it.finish ~~~ Note that these transformations are basically what is currently implemented in rta, niti and nitg. Except that, now with a single transformation point, those three workers does not need to do their own transformation and basically can just rely on the one done on the AST level. Pull-Request: #818 Reviewed-by: Lucas Bajolet --- 380d22070188dd1a255dbc3e33a0f2881242aab2 diff --cc src/compiler/abstract_compiler.nit index 0a11d32,2897ed9..f111e0d --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@@ -27,43 -26,41 +27,41 @@@ import mixi # Add compiling options redef class ToolContext # --output - var opt_output: OptionString = new OptionString("Output file", "-o", "--output") + var opt_output = new OptionString("Output file", "-o", "--output") # --dir - var opt_dir: OptionString = new OptionString("Output directory", "--dir") + var opt_dir = new OptionString("Output directory", "--dir") # --no-cc - var opt_no_cc: OptionBool = new OptionBool("Do not invoke C compiler", "--no-cc") + var opt_no_cc = new OptionBool("Do not invoke C compiler", "--no-cc") # --no-main - var opt_no_main: OptionBool = new OptionBool("Do not generate main entry point", "--no-main") + var opt_no_main = new OptionBool("Do not generate main entry point", "--no-main") # --cc-paths - var opt_cc_path: OptionArray = new OptionArray("Set include path for C header files (may be used more than once)", "--cc-path") + var opt_cc_path = new OptionArray("Set include path for C header files (may be used more than once)", "--cc-path") # --make-flags - var opt_make_flags: OptionString = new OptionString("Additional options to make", "--make-flags") + var opt_make_flags = new OptionString("Additional options to make", "--make-flags") # --compile-dir - var opt_compile_dir: OptionString = new OptionString("Directory used to generate temporary files", "--compile-dir") + var opt_compile_dir = new OptionString("Directory used to generate temporary files", "--compile-dir") # --hardening - var opt_hardening: OptionBool = new OptionBool("Generate contracts in the C code against bugs in the compiler", "--hardening") + var opt_hardening = new OptionBool("Generate contracts in the C code against bugs in the compiler", "--hardening") - # --no-shortcut-range - var opt_no_shortcut_range = new OptionBool("Always insantiate a range and its iterator on 'for' loops", "--no-shortcut-range") # --no-check-covariance - var opt_no_check_covariance: OptionBool = new OptionBool("Disable type tests of covariant parameters (dangerous)", "--no-check-covariance") + var opt_no_check_covariance = new OptionBool("Disable type tests of covariant parameters (dangerous)", "--no-check-covariance") # --no-check-attr-isset - var opt_no_check_attr_isset: OptionBool = new OptionBool("Disable isset tests before each attribute access (dangerous)", "--no-check-attr-isset") + var opt_no_check_attr_isset = new OptionBool("Disable isset tests before each attribute access (dangerous)", "--no-check-attr-isset") # --no-check-assert - var opt_no_check_assert: OptionBool = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert") + var opt_no_check_assert = new OptionBool("Disable the evaluation of explicit 'assert' and 'as' (dangerous)", "--no-check-assert") # --no-check-autocast - var opt_no_check_autocast: OptionBool = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast") + var opt_no_check_autocast = new OptionBool("Disable implicit casts on unsafe expression usage (dangerous)", "--no-check-autocast") # --no-check-null - var opt_no_check_null: OptionBool = new OptionBool("Disable tests of null receiver (dangerous)", "--no-check-null") + var opt_no_check_null = new OptionBool("Disable tests of null receiver (dangerous)", "--no-check-null") # --no-check-all - var opt_no_check_all: OptionBool = new OptionBool("Disable all tests (dangerous)", "--no-check-all") + var opt_no_check_all = new OptionBool("Disable all tests (dangerous)", "--no-check-all") # --typing-test-metrics - var opt_typing_test_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all type tests", "--typing-test-metrics") + var opt_typing_test_metrics = new OptionBool("Enable static and dynamic count of all type tests", "--typing-test-metrics") # --invocation-metrics - var opt_invocation_metrics: OptionBool = new OptionBool("Enable static and dynamic count of all method invocations", "--invocation-metrics") + var opt_invocation_metrics = new OptionBool("Enable static and dynamic count of all method invocations", "--invocation-metrics") # --isset-checks-metrics - var opt_isset_checks_metrics: OptionBool = new OptionBool("Enable static and dynamic count of isset checks before attributes access", "--isset-checks-metrics") + var opt_isset_checks_metrics = new OptionBool("Enable static and dynamic count of isset checks before attributes access", "--isset-checks-metrics") # --stacktrace - var opt_stacktrace: OptionString = new OptionString("Control the generation of stack traces", "--stacktrace") + var opt_stacktrace = new OptionString("Control the generation of stack traces", "--stacktrace") # --no-gcc-directives var opt_no_gcc_directive = new OptionArray("Disable a advanced gcc directives for optimization", "--no-gcc-directive") # --release