Browse Source

add expand_coro_type

Simon Krajewski 1 year ago
parent
commit
913e74a1d3

+ 6 - 0
src/context/common.ml

@@ -1219,3 +1219,9 @@ let get_entry_point com =
 		let e = Option.get com.main.main_expr in (* must be present at this point *)
 		let e = Option.get com.main.main_expr in (* must be present at this point *)
 		(snd path, c, e)
 		(snd path, c, e)
 	) com.main.main_class
 	) com.main.main_class
+
+let expand_coro_type basic args ret =
+	let tcontinuation = tfun [ret; t_dynamic] basic.tvoid in
+	let args = args @ [("_hx_continuation",false,tcontinuation)] in
+	let ret = tfun [t_dynamic; t_dynamic] basic.tvoid in
+	(args,ret)

+ 0 - 6
src/context/typecore.ml

@@ -699,12 +699,6 @@ let safe_mono_close ctx m p =
 		Unify_error l ->
 		Unify_error l ->
 			raise_or_display ctx l p
 			raise_or_display ctx l p
 
 
-(* TODO: this is wrong *)
-let coroutine_type ctx args ret =
-	let args = args @ [("_hx_continuation",false,(tfun [ret; t_dynamic] ctx.com.basic.tvoid))] in
-	let ret = ctx.com.basic.tvoid in
-	TFun(args,ret)
-
 let relative_path ctx file =
 let relative_path ctx file =
 	ctx.com.class_paths#relative_path file
 	ctx.com.class_paths#relative_path file
 
 

+ 1 - 2
src/generators/genjvm.ml

@@ -1518,8 +1518,7 @@ class texpr_to_jvm
 			| NotCoro (TFun(tl,tr)) ->
 			| NotCoro (TFun(tl,tr)) ->
 				tl,return_of_type gctx tr
 				tl,return_of_type gctx tr
 			| Coro(args,ret) ->
 			| Coro(args,ret) ->
-				let args = args @ [("_hx_continuation",false,(tfun [ret; t_dynamic] gctx.com.basic.tvoid))] in
-				let ret = (tfun [t_dynamic; t_dynamic] gctx.com.basic.tvoid) in
+				let args,ret = expand_coro_type gctx.com.basic args ret in
 				args,return_of_type gctx ret
 				args,return_of_type gctx ret
 			| _ ->
 			| _ ->
 				List.map (fun e -> ("",false,e.etype)) el,Some (object_sig)
 				List.map (fun e -> ("",false,e.etype)) el,Some (object_sig)

+ 7 - 13
src/optimization/analyzerTypes.ml

@@ -83,20 +83,14 @@ module BasicBlock = struct
 		ss_exhaustive : bool;
 		ss_exhaustive : bool;
 	}
 	}
 
 
-	and suspend_call = {
-		efun : texpr;      (* coroutine function expression *)
-		args : texpr list; (* call arguments without the continuation *)
-		pos : pos;         (* call position *)
-	}
-
 	and terminator_kind =
 	and terminator_kind =
-	| TermNone
-	| TermCondBranch of texpr
-	| TermReturn of pos
-	| TermReturnValue of texpr * pos
-	| TermBreak of pos
-	| TermContinue of pos
-	| TermThrow of texpr * pos
+		| TermNone
+		| TermCondBranch of texpr
+		| TermReturn of pos
+		| TermReturnValue of texpr * pos
+		| TermBreak of pos
+		| TermContinue of pos
+		| TermThrow of texpr * pos
 
 
 	and t = {
 	and t = {
 		bb_id : int;                          (* The unique ID of the block *)
 		bb_id : int;                          (* The unique ID of the block *)

+ 1 - 2
src/typing/typer.ml

@@ -1733,8 +1733,7 @@ and type_call_access ctx e el mode with_type p_inline p =
 
 
 and type_call_builtin ctx e el mode with_type p =
 and type_call_builtin ctx e el mode with_type p =
 	let create_coroutine e args ret p =
 	let create_coroutine e args ret p =
-		let args = args @ [("_hx_continuation",false,(tfun [ret; t_dynamic] ctx.com.basic.tvoid))] in
-		let ret = (tfun [t_dynamic; t_dynamic] ctx.com.basic.tvoid) in
+		let args,ret = expand_coro_type ctx.t args ret in
 		let el = unify_call_args ctx el args ctx.t.tvoid p false false false in
 		let el = unify_call_args ctx el args ctx.t.tvoid p false false false in
 		let e = mk e.eexpr (TFun(args,ret)) p in
 		let e = mk e.eexpr (TFun(args,ret)) p in
 		mk (TCall (e, el)) ret p
 		mk (TCall (e, el)) ret p

+ 3 - 1
src/typing/typerDisplay.ml

@@ -289,7 +289,9 @@ let rec handle_signature_display ctx e_ast with_type =
 				| (EField (e,("start" | "create"),_),p) ->
 				| (EField (e,("start" | "create"),_),p) ->
 					let e = type_expr ctx e WithType.value in
 					let e = type_expr ctx e WithType.value in
 					(match follow_with_coro e.etype with
 					(match follow_with_coro e.etype with
-						| Coro(args,ret) -> {e with etype = coroutine_type ctx args ret}
+						| Coro(args,ret) ->
+							let args,ret = expand_coro_type ctx.t args ret in
+							{e with etype = TFun(args,ret)}
 						| _ -> def ())
 						| _ -> def ())
 				| _ ->	def()
 				| _ ->	def()
 			in
 			in