1
+ (* Copyright (C) 2020- Authors of BuckleScript
2
+ *
3
+ * This program is free software: you can redistribute it and/or modify
4
+ * it under the terms of the GNU Lesser General Public License as published by
5
+ * the Free Software Foundation, either version 3 of the License, or
6
+ * (at your option) any later version.
7
+ *
8
+ * In addition to the permissions granted to you by the LGPL, you may combine
9
+ * or link a "work that uses the Library" with a publicly distributed version
10
+ * of this file to produce a combined library or application, then distribute
11
+ * that combined work under the terms of your choosing, with no requirement
12
+ * to comply with the obligations normally placed on you by section 4 of the
13
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
14
+ * should you choose to use a later version).
15
+ *
16
+ * This program is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU Lesser General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU Lesser General Public License
22
+ * along with this program; if not, write to the Free Software
23
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24
+
25
+
26
+
27
+ let make_test_sequence_variant_constant
28
+ (fail : Lambda.lambda option ) (arg : Lambda.lambda )
29
+ (int_lambda_list : (int * (string * Lambda.lambda) ) list ) : Lambda.lambda =
30
+ match int_lambda_list, fail with
31
+ | (_ , (_ ,act )) :: rest , None ->
32
+ Ext_list. fold_right rest act (fun (hash1 ,(name ,act1 )) acc ->
33
+ Lifthenelse (Lprim (Pintcomp Ceq ,
34
+ [arg; Lconst ((Const_pointer (hash1, Pt_variant {name})))], Location. none),
35
+ act1, acc
36
+ )
37
+ )
38
+ | _ , Some fail ->
39
+ Ext_list. fold_right int_lambda_list fail (fun (hash1 ,(name ,act1 )) acc ->
40
+ Lifthenelse (Lprim (Pintcomp Ceq ,
41
+ [arg; Lconst (Const_pointer (hash1, Pt_variant {name}))], Location. none),
42
+ act1, acc
43
+ )
44
+ )
45
+ | [] , None -> assert false
46
+
47
+ let call_switcher_variant_constant
48
+ (_loc : Location.t )
49
+ (fail : Lambda.lambda option )
50
+ (arg : Lambda.lambda )
51
+ (int_lambda_list : (int * (string * Lambda.lambda) ) list )
52
+ (_names : Lambda.switch_names option ) =
53
+ Ext_log. dwarn ~__POS__ " %a@." Ext_obj. pp_any _names;
54
+ match int_lambda_list, fail with
55
+ | (_ , (_ ,act )) :: rest , None ->
56
+ Ext_list. fold_right rest act (fun (hash1 ,(name ,act1 )) acc ->
57
+ Lifthenelse (Lprim (Pintcomp Ceq ,
58
+ [arg; Lconst (Const_pointer (hash1, Pt_variant {name}))], Location. none),
59
+ act1, acc
60
+ )
61
+ )
62
+ | _ , Some fail ->
63
+ Ext_list. fold_right int_lambda_list fail (fun (hash1 ,(name ,act1 )) acc ->
64
+ Lifthenelse (Lprim (Pintcomp Ceq ,
65
+ [arg; Lconst (Const_pointer (hash1, Pt_variant {name}))], Location. none),
66
+ act1, acc
67
+ )
68
+ )
69
+ | [] , None -> assert false
70
+
71
+
72
+ let call_switcher_variant_constr
73
+ (loc : Location.t )
74
+ (fail : Lambda.lambda option )
75
+ (arg : Lambda.lambda )
76
+ int_lambda_list
77
+ (names : Lambda.switch_names option ) : Lambda.lambda =
78
+ let v = Ident. create " variant" in
79
+ Llet (Alias , Pgenval , v, Lprim (Pfield (0 , Fld_poly_var_tag ), [arg], loc),
80
+ call_switcher_variant_constant
81
+ loc fail (Lvar v) int_lambda_list names)
0 commit comments