Merge: Introducing the do ... catch ... end structure
authorJean Privat <jean@pryen.org>
Thu, 14 Apr 2016 01:03:06 +0000 (21:03 -0400)
committerJean Privat <jean@pryen.org>
Thu, 14 Apr 2016 01:03:06 +0000 (21:03 -0400)
This PR is a first step in trying to handle exceptions in Nit, replacing the behaviour of `abort` if it happens within a do ... catch ... end.

In the compiler, setjmp() et longjmp() are used to jump directly from the `abort` to the nearest `catch` bloc.

Pull-Request: #2011
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

1  2 
src/interpreter/naive_interpreter.nit
src/parser/parser_nodes.nit
src/semantize/scope.nit

@@@ -117,9 -121,16 +117,16 @@@ class NaiveInterprete
        # Set this mark to skip the evaluation until a labeled statement catch it with `is_escape`
        var escapemark: nullable EscapeMark = null
  
+       # Is an abort being executed ?
+       # Set this mark to return to the last `catch` bloc or effectively aborting if there isn't any
+       var catch_mark = new EscapeMark
+       # The count of `catch` blocs that have been encountered and can catch an abort
+       var catch_count = 0
        # Is a return or a break or a continue executed?
        # Use this function to know if you must skip the evaluation of statements
 -      fun is_escaping: Bool do return returnmark != null or escapemark != null
 +      fun is_escaping: Bool do return escapemark != null
  
        # The value associated with the current return/break/continue, if any.
        # Set the value when you set a escapemark.
Simple merge
Simple merge