Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions compiler/lib/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,12 @@ let rec constant_of_const : _ -> Code.constant =
| Const_float_array sl ->
let l = List.map ~f:(fun f -> Code.Float (float_of_string f)) sl in
Tuple (Obj.double_array_tag, Array.of_list l, Unknown)
(*
For bucklescript,
- uncomment the two branches below
- and comment out the two last ones
{[
| Const_pointer (i,_) ->
Int (Int32.of_int i)
| Const_block (tag,_,l) ->
let l = Array.of_list (List.map l ~f:constant_of_const) in
Tuple (tag, l, Unknown)
]}
*)
| Const_pointer i -> Int (Int32.of_int i)
| Const_block (tag, l) ->
| ((Const_pointer (i, _))[@if BUCKLESCRIPT]) -> Int (Int32.of_int i)
| ((Const_block (tag, _, l))[@if BUCKLESCRIPT]) ->
let l = Array.of_list (List.map l ~f:constant_of_const) in
Tuple (tag, l, Unknown)
| ((Const_pointer i)[@ifnot BUCKLESCRIPT]) -> Int (Int32.of_int i)
| ((Const_block (tag, l))[@ifnot BUCKLESCRIPT]) ->
let l = Array.of_list (List.map l ~f:constant_of_const) in
Tuple (tag, l, Unknown)

Expand Down
27 changes: 25 additions & 2 deletions compiler/ppx/ppx_optcomp_light.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,31 @@ let keep loc (attrs : attributes) =
try
let keep =
List.for_all attrs ~f:(function
| { Location.txt = "if"; _ }, attr_payload -> (
| { Location.txt = ("if" | "ifnot") as ifnot; _ }, attr_payload -> (
let norm =
match ifnot with
| "if" -> fun x -> x
| "ifnot" -> fun x -> not x
| _ -> assert false
in
match attr_payload with
| PStr
[ { pstr_desc =
Pstr_eval
( { pexp_desc = Pexp_construct ({ txt = Lident ident; _ }, None)
; _
}
, [] )
; _
}
] ->
let b =
match bool_of_string (Sys.getenv ident) with
| true -> true
| false -> false
| exception _ -> false
in
norm b
| PStr
[ { pstr_desc =
Pstr_eval
Expand Down Expand Up @@ -123,7 +146,7 @@ let keep loc (attrs : attributes) =
let op = get_op op in
let a = eval a in
let b = eval b in
op (Version.compare a b) 0
norm (op (Version.compare a b) 0)
| _ -> raise Invalid)
| _ -> true)
in
Expand Down