|
@@ -777,6 +777,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
|
|
|
(* TODO: maybe merge this into block_to_texpr somehow, and only introduce new states when there is a suspension point *)
|
|
|
|
|
|
+ print_endline "---";
|
|
|
let rec loop bb state_id back_state_id statecases current_el =
|
|
|
let p = bb.bb_pos in
|
|
|
(* TODO: only do this in the end, avoid unnecessary List.rev *)
|
|
@@ -789,6 +790,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
match bb.bb_syntax_edge with
|
|
|
| SESuspend (call, bb_next) ->
|
|
|
let next_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf "suspend cur:%d,next:%d,back:%d" state_id next_state_id back_state_id);
|
|
|
let statecases = loop bb_next next_state_id back_state_id statecases [] in
|
|
|
let args = call.args @ [ estatemachine ] in
|
|
|
|
|
@@ -808,6 +810,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
mk_case (current_el @ el @ [esetstate; ecallcoroutine; ereturn]) :: statecases
|
|
|
|
|
|
| SENone ->
|
|
|
+ print_endline (Printf.sprintf "none cur:%d,back:%d" state_id back_state_id);
|
|
|
let esetstate = set_state back_state_id in
|
|
|
if back_state_id = -1 then begin
|
|
|
(* function exit *)
|
|
@@ -825,11 +828,13 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
end
|
|
|
|
|
|
| SEMerge bb_next ->
|
|
|
+ print_endline (Printf.sprintf "merge cur:%d,back:%d" state_id back_state_id);
|
|
|
loop bb_next state_id back_state_id statecases (current_el @ el)
|
|
|
|
|
|
| SESubBlock (bb_sub,bb_next) ->
|
|
|
let sub_state_id = get_next_state_id () in
|
|
|
let next_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf "sub cur:%d,sub:%d,next:%d,back:%d" state_id sub_state_id next_state_id back_state_id);
|
|
|
let statecases = loop bb_next next_state_id back_state_id statecases [] in
|
|
|
let statecases = loop bb_sub sub_state_id next_state_id statecases [] in
|
|
|
mk_case (current_el @ el @ [set_state sub_state_id]) :: statecases
|
|
@@ -839,6 +844,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
| econd :: el ->
|
|
|
let then_state_id = get_next_state_id () in
|
|
|
let next_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf "if-then cur:%d,then:%d,next:%d,back:%d" state_id then_state_id next_state_id back_state_id);
|
|
|
let statecases = loop bb_then then_state_id next_state_id statecases [] in
|
|
|
let statecases = loop bb_next next_state_id back_state_id statecases [] in
|
|
|
let eif = mk (TIf (econd, set_state then_state_id, Some (set_state next_state_id))) com.basic.tint p in
|
|
@@ -851,6 +857,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
let then_state_id = get_next_state_id () in
|
|
|
let else_state_id = get_next_state_id () in
|
|
|
let next_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf "if-then cur:%d,then:%d,else:%d,next:%d,back:%d" state_id then_state_id else_state_id next_state_id back_state_id);
|
|
|
let statecases = loop bb_then then_state_id next_state_id statecases [] in
|
|
|
let statecases = loop bb_else else_state_id next_state_id statecases [] in
|
|
|
let statecases = loop bb_next next_state_id back_state_id statecases [] in
|
|
@@ -862,10 +869,12 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
(match List.rev el with
|
|
|
| esubj :: el ->
|
|
|
let next_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf "switch cur:%d,next:%d,back:%d" state_id next_state_id back_state_id);
|
|
|
let statecases = ref statecases in
|
|
|
let ecases = List.map (fun (patterns,bb) ->
|
|
|
(* TODO: variable capture and other fancy things O_o *)
|
|
|
let case_state_id = get_next_state_id () in
|
|
|
+ print_endline (Printf.sprintf " case %d" case_state_id);
|
|
|
statecases := loop bb case_state_id next_state_id !statecases [];
|
|
|
patterns, set_state case_state_id
|
|
|
) cases in
|
|
@@ -877,6 +886,7 @@ and block_to_texpr_coroutine ctx bb vcontinuation vresult p =
|
|
|
| None ->
|
|
|
next_state_id
|
|
|
in
|
|
|
+ print_endline (Printf.sprintf " default %d" default_state_id);
|
|
|
let eswitch = mk (TSwitch (esubj,ecases,Some (set_state default_state_id))) com.basic.tvoid p in
|
|
|
let statecases = loop bb_next next_state_id back_state_id !statecases [] in
|
|
|
mk_case (current_el @ (List.rev el) @ [eswitch]) :: statecases
|