diff --git a/src/optimization/analyzerCoro.ml b/src/optimization/analyzerCoro.ml index fb711d748..b620da7eb 100644 --- a/src/optimization/analyzerCoro.ml +++ b/src/optimization/analyzerCoro.ml @@ -13,6 +13,10 @@ let block_to_texpr_coroutine ctx bb vcontinuation vresult verror p = let eerror = make_local verror null_pos in + let mk_array t = + TInst ((mk_class null_module ([], "Array") null_pos null_pos), [ t ]) + in + let mk_int i = make_int com.basic i null_pos in let mk_assign estate eid = @@ -32,10 +36,11 @@ let block_to_texpr_coroutine ctx bb vcontinuation vresult verror p = let set_excstate id = mk_assign eexcstate (mk_int id) in let tstatemachine = tfun [t_dynamic; t_dynamic] com.basic.tvoid in - let vstatemachine = alloc_var VGenerated "_hx_stateMachine" tstatemachine p in + let tstatemachine_arr = mk_array tstatemachine in + let vstatemachine = alloc_var VGenerated "_hx_stateMachine" tstatemachine_arr p in add_var_flag vstatemachine VCaptured; declare_var ctx.graph vstatemachine bb; - let estatemachine = make_local vstatemachine p in + let array_access = mk (TArray ((mk (TLocal vstatemachine) tstatemachine null_pos), (mk_int 0))) tstatemachine p in let get_next_state_id = let counter = ref 0 in @@ -73,7 +78,7 @@ let block_to_texpr_coroutine ctx bb vcontinuation vresult verror p = die "Unexpected coroutine type" __LOC__ in let efun = { call.efun with etype = tfun } in - let args = call.args @ [ estatemachine ] in + let args = call.args @ [ array_access ] in let ecreatecoroutine = mk (TCall (efun, args)) tcoroutine call.pos in let enull = make_null t_dynamic p in mk (TCall (ecreatecoroutine, [enull; enull])) com.basic.tvoid call.pos @@ -373,6 +378,7 @@ let block_to_texpr_coroutine ctx bb vcontinuation vresult verror p = None )) com.basic.tvoid p in + let array_def = mk (TArrayDecl [ (make_null com.basic.tvoid null_pos) ]) tstatemachine_arr p in let estatemachine_def = mk (TFunction { tf_args = [(vresult,None); (verror,None)]; tf_type = com.basic.tvoid; @@ -385,6 +391,7 @@ let block_to_texpr_coroutine ctx bb vcontinuation vresult verror p = let shared_vars = List.rev (excstate_var :: state_var :: shared_vars) in mk (TBlock (shared_vars @ [ - mk (TVar (vstatemachine, Some estatemachine_def)) com.basic.tvoid p; - mk (TReturn (Some estatemachine)) com.basic.tvoid p; + mk (TVar (vstatemachine, Some array_def)) com.basic.tvoid p; + mk_assign array_access estatemachine_def; + mk (TReturn (Some array_access)) com.basic.tvoid p; ])) com.basic.tvoid p