Browse Source

slightly change init code for hot reload

Nicolas Cannasse 3 years ago
parent
commit
525bd3513e
2 changed files with 12 additions and 2 deletions
  1. 8 1
      src/generators/genhl.ml
  2. 4 1
      std/hl/_std/Type.hx

+ 8 - 1
src/generators/genhl.ml

@@ -3437,7 +3437,9 @@ let generate_static_init ctx types main =
 
 	let gen_content() =
 
-		op ctx (OCall0 (alloc_tmp ctx HVoid, alloc_fun_path ctx ([],"Type") "init"));
+		let is_init = alloc_tmp ctx HBool in
+		op ctx (OCall0 (is_init, alloc_fun_path ctx ([],"Type") "init"));
+		hold ctx is_init;
 
 		(* init class values *)
 		List.iter (fun t ->
@@ -3609,6 +3611,11 @@ let generate_static_init ctx types main =
 				()
 
 		) types;
+
+		let j = jump ctx (fun d -> OJTrue (is_init,d)) in
+		op ctx (ORet (alloc_tmp ctx HVoid));
+		j();
+		free ctx is_init;
 	in
 	(* init class statics *)
 	let init_exprs = ref [] in

+ 4 - 1
std/hl/_std/Type.hx

@@ -38,8 +38,11 @@ class Type {
 	static inline function get_allTypes():hl.types.BytesMap
 		return untyped $allTypes();
 
-	@:keep static function init():Void {
+	@:keep static function init():Bool {
+		if( allTypes != null )
+			return false;
 		untyped $allTypes(new hl.types.BytesMap());
+		return true;
 	}
 
 	@:keep static function initClass(ct:hl.Type, t:hl.Type, name:hl.Bytes):hl.BaseType.Class@:privateAccess {