Dan Korostelev преди 4 години
родител
ревизия
f61e9ed716
променени са 1 файла, в които са добавени 5 реда и са изтрити 0 реда
  1. 5 0
      src/optimization/analyzerTexprTransformer.ml

+ 5 - 0
src/optimization/analyzerTexprTransformer.ml

@@ -841,6 +841,11 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
 		in
 	let statecases = loop bb (get_next_state_id ()) (-1) [] [] in
 
+	(* TODO:
+		we can optimize while and switch in some cases:
+		 - if there's only one state (no suspensions) - don't wrap into while/switch, don't introduce state var
+		 - if there's no non-suspending state changes, we don't need while, because all suspensions exit the function with return
+	*)
 	let ethrow = mk (TThrow (make_string com.basic "Invalid coroutine state" p)) com.basic.tvoid p in
 	let eswitch = mk (TSwitch (estate, statecases, Some ethrow)) com.basic.tvoid p in
 	let eloop = mk (TWhile (make_bool com.basic true p, eswitch, DoWhile)) com.basic.tvoid p in