Sfoglia il codice sorgente

added uncaught exceptions handling.

Nicolas Cannasse 19 anni fa
parent
commit
b2e4b8c51f
3 ha cambiato i file con 30 aggiunte e 0 eliminazioni
  1. 20 0
      genswf8.ml
  2. 4 0
      std/flash/Boot.hx
  3. 6 0
      std/flash/Lib.hx

+ 20 - 0
genswf8.ml

@@ -539,6 +539,12 @@ and gen_try_catch ctx retval e catchs =
 		let next_catch = (match t with
 		| None -> 
 			end_throw := false;
+			(* @exc.pop() *)			
+			push ctx [VInt 0;VStr "@exc"];
+			write ctx AEval;
+			push ctx [VStr "pop"];
+			call ctx VarObj 0;
+			write ctx APop;
 			push ctx [VStr name;VReg 0];
 			write ctx ALocalAssign;
 			gen_expr ctx retval e;			
@@ -549,6 +555,12 @@ and gen_try_catch ctx retval e catchs =
 			call ctx VarStr 2;
 			write ctx ANot;
 			let c = cjmp ctx in
+			(* @exc.pop() *)
+			push ctx [VInt 0;VStr "@exc"];
+			write ctx AEval;
+			push ctx [VStr "pop"];
+			call ctx VarObj 0;
+			write ctx APop;
 			push ctx [VStr name; VReg 0];
 			write ctx ALocalAssign;
 			gen_expr ctx retval e;
@@ -930,7 +942,15 @@ and gen_expr_2 ctx retval e =
 	| TSwitch (e,cases,def) ->
 		gen_switch ctx retval e cases def
 	| TThrow e ->
+		(* call @exc.push(e) *)
 		gen_expr ctx true e;
+		write ctx (ASetReg 0);
+		push ctx [VInt 1; VStr "@exc"];
+		write ctx AEval;
+		push ctx [VStr "push"];
+		call ctx VarObj 1;
+		write ctx APop;
+		push ctx [VReg 0];
 		write ctx AThrow;
 		no_value ctx retval
 	| TTry (e,catchs) ->

+ 4 - 0
std/flash/Boot.hx

@@ -26,6 +26,8 @@ package flash;
 
 class Boot {
 
+	private static var exc : Array<Dynamic>;
+
 	private static function __string_rec(o,s) {
 		untyped {
 			if( s.length >= 20 )
@@ -290,6 +292,8 @@ class Boot {
 			// prevent closure creation by setting untyped
 			current["@instanceof"] = untyped __instanceof;
 			current["@closure"] = untyped __closure;
+			exc = new Array();
+			current["@exc"] = exc;
 		}
 	}
 

+ 6 - 0
std/flash/Lib.hx

@@ -71,6 +71,12 @@ class Lib {
 		untyped _global["Object"].registerClass(name,cl);
 	}
 
+	public static function throwException() {
+		var exc : Array<Dynamic> = untyped Boot.exc;
+		if( exc.length != 0 )
+			throw(exc.pop());
+	}
+
 }