summaryrefslogtreecommitdiff
blob: 6203c077e0c8437ccdc42f27ba5f2d956e4ce4e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
diff -uNr ppx_optcomp-113.33.00/_oasis ppx_optcomp-113.33.00+4.03/_oasis
--- ppx_optcomp-113.33.00/_oasis	2016-03-09 16:44:54.000000000 +0100
+++ ppx_optcomp-113.33.00+4.03/_oasis	2016-03-22 15:13:51.000000000 +0100
@@ -1,8 +1,8 @@
 OASISFormat:      0.4
-OCamlVersion:     >= 4.02.3
+OCamlVersion:     >= 4.03.0
 FindlibVersion:   >= 1.3.2
 Name:             ppx_optcomp
-Version:          113.33.00
+Version:          113.33.00+4.03
 Synopsis:         Optional compilation for OCaml
 Authors:          Jane Street Group, LLC <opensource@janestreet.com>
 Copyrights:       (C) 2015-2016 Jane Street Group LLC <opensource@janestreet.com>
diff -uNr ppx_optcomp-113.33.00/opam ppx_optcomp-113.33.00+4.03/opam
--- ppx_optcomp-113.33.00/opam	2016-03-18 12:08:01.000000000 +0100
+++ ppx_optcomp-113.33.00+4.03/opam	2016-03-22 17:51:37.000000000 +0100
@@ -15,4 +15,4 @@
   "ppx_core"
   "ppx_tools"  {>= "0.99.3"}
 ]
-available: [ ocaml-version >= "4.02.3" ]
+available: [ ocaml-version >= "4.03.0" ]
diff -uNr ppx_optcomp-113.33.00/src/ppx_optcomp.ml ppx_optcomp-113.33.00+4.03/src/ppx_optcomp.ml
--- ppx_optcomp-113.33.00/src/ppx_optcomp.ml	2016-03-09 16:44:54.000000000 +0100
+++ ppx_optcomp-113.33.00+4.03/src/ppx_optcomp.ml	2016-03-22 15:13:51.000000000 +0100
@@ -169,12 +169,19 @@
   Location.raise_errorf ~loc:e.pexp_loc "optcomp: expression not supported"
 ;;
 
+let parse_int loc x =
+  match int_of_string x with
+  | v -> v
+  | exception _ ->
+    Location.raise_errorf ~loc "optcomp: invalid integer"
+;;
+
 let rec eval env e : Value.t =
   let loc = e.pexp_loc in
   match e.pexp_desc with
-  | Pexp_constant (Const_int     x    ) -> Int    x
-  | Pexp_constant (Const_char    x    ) -> Char   x
-  | Pexp_constant (Const_string (x, _)) -> String x
+  | Pexp_constant (Pconst_integer    (x, None)) -> Int (parse_int loc x)
+  | Pexp_constant (Pconst_char    x       ) -> Char x
+  | Pexp_constant (Pconst_string (x, _   )) -> String x
 
   | Pexp_construct ({ txt = Lident "true" ; _ }, None) -> Bool true
   | Pexp_construct ({ txt = Lident "false"; _ }, None) -> Bool false
@@ -192,7 +199,7 @@
 
   | Pexp_apply ({ pexp_desc = Pexp_ident { txt = Lident s; _ }; _ }, args) -> begin
       let args =
-        List.map args ~f:(fun (l, x) -> if l <> "" then not_supported e else x)
+        List.map args ~f:(fun (l, x) -> if l <> Asttypes.Nolabel then not_supported e else x)
       in
       match s, args with
       | "="  , [x; y] -> eval_cmp     env ( = )   x y
@@ -283,12 +290,13 @@
   | _ -> not_supported e
 
 and bind env patt value =
+  let loc = patt.ppat_loc in
   match patt.ppat_desc, value with
   | Ppat_any, _ -> env
 
-  | Ppat_constant (Const_int     x    ), Int    y when x = y -> env
-  | Ppat_constant (Const_char    x    ), Char   y when x = y -> env
-  | Ppat_constant (Const_string (x, _)), String y when x = y -> env
+  | Ppat_constant (Pconst_integer    (x, None)), Int    y when parse_int loc x = y -> env
+  | Ppat_constant (Pconst_char    x       ), Char   y when               x = y -> env
+  | Ppat_constant (Pconst_string (x, _   )), String y when               x = y -> env
 
   | Ppat_construct ({ txt = Lident "true" ; _ }, None), Bool true  -> env
   | Ppat_construct ({ txt = Lident "false"; _ }, None), Bool false -> env
@@ -506,7 +514,7 @@
           | Pexp_construct (x, Some y) ->
             let id = var_of_lid x in
             Let (ppat_var ~loc:id.loc id, y)
-          | Pexp_apply (x, [("", y)]) ->
+          | Pexp_apply (x, [(Nolabel, y)]) ->
             let id = var_of_expr x in
             Let (ppat_var ~loc:id.loc id, y)
           | _ ->
@@ -517,7 +525,7 @@
       | LIDENT "import" -> begin
           let e = get_expr () in
           match e.pexp_desc with
-          | Pexp_constant (Const_string (s, _)) -> Import s
+          | Pexp_constant (Pconst_string (s, _)) -> Import s
           | _ ->
             Location.raise_errorf ~loc:e.pexp_loc "optcomp: #import expect a string"
         end