@@ -41,53 +41,56 @@ type t = {
41
41
block : J .block ;
42
42
value : J .expression option ;
43
43
finished : finished ;
44
- (* * When [finished] is true the block is already terminated, value does not make sense
45
- default is false, false is an conservative approach
46
- *)
44
+
47
45
}
48
46
49
- type cont = Lam_compile_context .cont
47
+ type continuation = Lam_compile_context .continuation
50
48
51
- let make ?value ?(finished =False ) block = {block ; value ; finished }
49
+ let make ?value ?(finished =False ) block =
50
+ { block ; value ; finished }
52
51
53
- let of_stmt ?value ?(finished = False ) stmt = {block = [stmt] ; value ; finished }
52
+ let of_stmt ?value ?(finished = False ) stmt =
53
+ { block = [stmt] ; value ; finished }
54
54
55
55
let of_block ?value ?(finished = False ) block =
56
- { block ; value ; finished }
56
+ { block ; value ; finished }
57
57
58
- let dummy = {value = None ; block = [] ; finished = Dummy }
58
+ let dummy =
59
+ {value = None ; block = [] ; finished = Dummy }
59
60
60
- let handle_name_tail
61
- (name : cont )
61
+ let output_of_expression
62
+ (continuation : continuation )
62
63
(should_return : Lam_compile_context.return_type )
63
- lam (exp : J.expression ) : t =
64
- begin match name , should_return with
64
+ ( lam : Lam.t ) (exp : J.expression ) : t =
65
+ begin match continuation , should_return with
65
66
| EffectCall , ReturnFalse ->
66
67
if Lam_analysis. no_side_effects lam
67
68
then dummy
68
69
else {block = [] ; value = Some exp ; finished = False }
69
- | EffectCall , ReturnTrue _ ->
70
- make [S. return_stmt exp] ~finished: True
71
70
| Declare (kind , n ), ReturnFalse ->
72
71
make [ S. define_variable ~kind n exp]
73
72
| Assign n ,ReturnFalse ->
74
73
make [S. assign n exp ]
74
+ | EffectCall , ReturnTrue _ ->
75
+ make [S. return_stmt exp] ~finished: True
75
76
| (Declare _ | Assign _ ), ReturnTrue _ ->
76
77
make [S. unknown_lambda lam] ~finished: True
77
- | NeedValue , _ -> {block = [] ; value = Some exp; finished = False }
78
+ | NeedValue , _ ->
79
+ {block = [] ; value = Some exp; finished = False }
78
80
end
79
81
80
- let handle_block_return
81
- (st : cont )
82
+ let output_of_block_and_expression
83
+ (continuation : continuation )
82
84
(should_return : Lam_compile_context.return_type )
83
85
(lam : Lam.t ) (block : J.block ) exp : t =
84
- match st, should_return with
86
+ match continuation, should_return with
87
+ | EffectCall , ReturnFalse -> make block ~value: exp
85
88
| Declare (kind ,n ), ReturnFalse ->
86
89
make (block @ [ S. define_variable ~kind n exp])
87
- | Assign n , ReturnFalse -> make (block @ [S. assign n exp])
88
- | (Declare _ | Assign _ ), ReturnTrue _ -> make [S. unknown_lambda lam] ~finished: True
89
- | EffectCall , ReturnFalse -> make block ~value: exp
90
+ | Assign n , ReturnFalse -> make (block @ [S. assign n exp])
90
91
| EffectCall , ReturnTrue _ -> make (block @ [S. return_stmt exp]) ~finished: True
92
+ | (Declare _ | Assign _ ), ReturnTrue _ ->
93
+ make [S. unknown_lambda lam] ~finished: True
91
94
| NeedValue , _ -> make block ~value: exp
92
95
93
96
let statement_of_opt_expr (x : J.expression option ) : J.statement =
0 commit comments