Selaa lähdekoodia

hijack haxe.EntryPoint to deal with UV initialization

Simon Krajewski 6 vuotta sitten
vanhempi
commit
0fdd3e8e11
4 muutettua tiedostoa jossa 28 lisäystä ja 22 poistoa
  1. 8 3
      src/typing/finalization.ml
  2. 18 2
      std/haxe/EntryPoint.hx
  3. 2 6
      std/haxe/Timer.hx
  4. 0 11
      tests/asys/Main.hx

+ 8 - 3
src/typing/finalization.ml

@@ -33,11 +33,16 @@ let get_main ctx types =
 		let main = (try
 		let main = (try
 			let et = List.find (fun t -> t_path t = (["haxe"],"EntryPoint")) types in
 			let et = List.find (fun t -> t_path t = (["haxe"],"EntryPoint")) types in
 			let ec = (match et with TClassDecl c -> c | _ -> assert false) in
 			let ec = (match et with TClassDecl c -> c | _ -> assert false) in
-			let ef = PMap.find "run" ec.cl_statics in
 			let p = null_pos in
 			let p = null_pos in
 			let et = mk (TTypeExpr et) (TAnon { a_fields = PMap.empty; a_status = ref (Statics ec) }) p in
 			let et = mk (TTypeExpr et) (TAnon { a_fields = PMap.empty; a_status = ref (Statics ec) }) p in
-			let call = mk (TCall (mk (TField (et,FStatic (ec,ef))) ef.cf_type p,[])) ctx.t.tvoid p in
-			mk (TBlock [main;call]) ctx.t.tvoid p
+			let mk_call name =
+				let ef = PMap.find name ec.cl_statics in
+				mk (TCall (mk (TField (et,FStatic (ec,ef))) ef.cf_type p,[])) ctx.t.tvoid p
+			in
+			let init = mk_call "init" in
+			let run = mk_call "run" in
+			let close = mk_call "close" in
+			mk (TBlock [init;main;run;close]) ctx.t.tvoid p
 		with Not_found ->
 		with Not_found ->
 			main
 			main
 		) in
 		) in

+ 18 - 2
std/haxe/EntryPoint.hx

@@ -102,6 +102,12 @@ class EntryPoint {
 		return time;
 		return time;
 	}
 	}
 
 
+	@:keep public static function init() {
+		#if eval
+		eval.Uv.init();
+		#end
+	}
+
 	/**
 	/**
 		Start the main loop. Depending on the platform, this can return immediately or will only return when the application exits.
 		Start the main loop. Depending on the platform, this can return immediately or will only return when the application exits.
 	**/
 	**/
@@ -116,10 +122,10 @@ class EntryPoint {
 		#if nodejs
 		#if nodejs
 		setTimeoutNextTick();
 		setTimeoutNextTick();
 		#else
 		#else
-		if(js.Lib.typeof(js.Browser.window) != 'undefined') {
+		if (js.Lib.typeof(js.Browser.window) != 'undefined') {
 			var window:Dynamic = js.Browser.window;
 			var window:Dynamic = js.Browser.window;
 			var rqf:Dynamic = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
 			var rqf:Dynamic = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame;
-			if(rqf != null) {
+			if (rqf != null) {
 				rqf(run);
 				rqf(run);
 			} else {
 			} else {
 				setTimeoutNextTick();
 				setTimeoutNextTick();
@@ -130,6 +136,10 @@ class EntryPoint {
 		#end
 		#end
 		#elseif flash
 		#elseif flash
 		flash.Lib.current.stage.addEventListener(flash.events.Event.ENTER_FRAME, function(_) processEvents());
 		flash.Lib.current.stage.addEventListener(flash.events.Event.ENTER_FRAME, function(_) processEvents());
+		#elseif target.asys
+		#if eval
+		eval.Uv.run(RunDefault);
+		#end
 		#elseif sys
 		#elseif sys
 		while (true) {
 		while (true) {
 			var nextTick = processEvents();
 			var nextTick = processEvents();
@@ -142,4 +152,10 @@ class EntryPoint {
 		// no implementation available, let's exit immediately
 		// no implementation available, let's exit immediately
 		#end
 		#end
 	}
 	}
+
+	@:keep static public function close() {
+		#if eval
+		eval.Uv.close();
+		#end
+	}
 }
 }

+ 2 - 6
std/haxe/Timer.hx

@@ -23,12 +23,7 @@
 package haxe;
 package haxe;
 
 
 #if (target.asys)
 #if (target.asys)
-private typedef Native =
-	#if eval
-	eval.uv.Timer;
-	#else
-	#error "Missing asys implementation"
-	#end
+private typedef Native = #if eval eval.uv.Timer; #else #error "Missing asys implementation" #end
 #end
 #end
 
 
 /**
 /**
@@ -81,6 +76,7 @@ class Timer {
 		timer = new java.util.Timer();
 		timer = new java.util.Timer();
 		timer.scheduleAtFixedRate(task = new TimerTask(this), haxe.Int64.ofInt(time_ms), haxe.Int64.ofInt(time_ms));
 		timer.scheduleAtFixedRate(task = new TimerTask(this), haxe.Int64.ofInt(time_ms), haxe.Int64.ofInt(time_ms));
 		#elseif (target.asys)
 		#elseif (target.asys)
+		(null : haxe.EntryPoint); // TODO: Have to reference EntryPoint - cleaner way?
 		native = new Native(time_ms, () -> run());
 		native = new Native(time_ms, () -> run());
 		#else
 		#else
 		var dt = time_ms / 1000;
 		var dt = time_ms / 1000;

+ 0 - 11
tests/asys/Main.hx

@@ -3,17 +3,8 @@ import utest.ui.Report;
 
 
 import sys.FileSystem;
 import sys.FileSystem;
 
 
-#if hl
-import hl.Uv;
-#elseif eval
-import eval.Uv;
-#elseif neko
-import neko.Uv;
-#end
-
 class Main {
 class Main {
 	public static function main():Void {
 	public static function main():Void {
-		Uv.init();
 		if (FileSystem.exists("resources-rw")) {
 		if (FileSystem.exists("resources-rw")) {
 			function walk(path:String):Void {
 			function walk(path:String):Void {
 				for (f in FileSystem.readDirectory(path)) {
 				for (f in FileSystem.readDirectory(path)) {
@@ -34,7 +25,5 @@ class Main {
 		runner.onTestStart.add(test -> trace("running", Type.getClassName(Type.getClass(test.fixture.target)), test.fixture.method));
 		runner.onTestStart.add(test -> trace("running", Type.getClassName(Type.getClass(test.fixture.target)), test.fixture.method));
 		Report.create(runner);
 		Report.create(runner);
 		runner.run();
 		runner.run();
-		Uv.run(RunDefault);
-		Uv.close();
 	}
 	}
 }
 }