Skip to content

Commit b1e31fd

Browse files
committed
Untested: uncurried syntax for binary primitive ops (%cd) and derived operations (%op)
1 parent bcd89d3 commit b1e31fd

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/ppx_cd.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,12 @@ let translate (expr : expression) : result =
923923
[%e? lhs]
924924
([%e? rhs] ~projections:[%e? projections])] ->
925925
process_assign_unop ~accu_op ~lhs ~un_op:"id" ~rhs ~projections ~proj_in_scope:true ()
926+
| [%expr
927+
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
928+
[%e? lhs]
929+
([%e? { pexp_desc = Pexp_ident { txt = Lident bin_op; _ }; _ }]
930+
([%e? rhs1], [%e? rhs2])
931+
~logic:[%e? { pexp_desc = Pexp_constant (Pconst_string (spec, s_loc, _)); _ } as logic])]
926932
| [%expr
927933
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
928934
[%e? lhs]
@@ -981,6 +987,10 @@ let translate (expr : expression) : result =
981987
in
982988
let _, un_op = Hashtbl.find_exn unary_ops unop_ident loc in
983989
process_raw_unop ~accu_op ~lhs ~un_op ~rhs ~logic
990+
| [%expr
991+
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
992+
[%e? lhs]
993+
([%e? { pexp_desc = Pexp_ident { txt = Lident bin_op; _ }; _ }] ([%e? rhs1], [%e? rhs2]))]
984994
| [%expr
985995
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
986996
[%e? lhs]
@@ -1003,6 +1013,10 @@ let translate (expr : expression) : result =
10031013
| [%expr [%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }] [%e? lhs] [%e? rhs]]
10041014
when is_assignment accu_op && proj_in_scope ->
10051015
process_assign_unop ~accu_op ~lhs ~un_op:"id" ~rhs ~proj_in_scope ()
1016+
| [%expr
1017+
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
1018+
[%e? lhs]
1019+
([%e? { pexp_desc = Pexp_ident { txt = Lident bin_op; _ }; _ }] ([%e? rhs1], [%e? rhs2]))]
10061020
| [%expr
10071021
[%e? { pexp_desc = Pexp_ident { txt = Lident accu_op; _ }; _ }]
10081022
[%e? lhs]

lib/ppx_op.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ let rec translate ~num_configs ~is_toplevel ~has_config ?label expr =
157157
lift_config_vb ~loop ~num_configs ?label ~expr1 ~c_expr [ expr2 ]
158158
| [%expr [%e? expr1] ~config:[%e? c_expr]] ->
159159
lift_config_vb ~loop ~num_configs ?label ~expr1 ~c_expr []
160+
| [%expr
161+
[%e? { pexp_desc = Pexp_ident { txt = Lident op_ident; _ }; _ }] ([%e? expr2], [%e? expr3])]
162+
when Hashtbl.mem binary_ops op_ident ->
163+
let e1 = [%expr [%e expr] ?label:[%e opt_expr ~loc label]] in
164+
let vbs2, e2 = loop expr2 in
165+
let vbs3, e3 = loop expr3 in
166+
(reduce_vbss [ vbs2; vbs3 ], [%expr [%e e1] [%e e2] [%e e3]])
160167
| [%expr [%e? expr1] [%e? expr2] [%e? expr3]] ->
161168
let vbs1, e1 = loop ?label expr1 in
162169
let vbs2, e2 = loop expr2 in
@@ -260,8 +267,7 @@ let rec translate ~num_configs ~is_toplevel ~has_config ?label expr =
260267
let vbs, body = loop ?label body in
261268
(vbs, { expr with pexp_desc = Pexp_letmodule (name, module_expr, body) })
262269
| { pexp_desc = Pexp_ident { txt = Lident op_ident; _ }; _ }
263-
when is_primitive_op op_ident || is_operator op_ident
264-
->
270+
when is_primitive_op op_ident || is_operator op_ident ->
265271
(* FIXME: this heuristic is hacky... *)
266272
(no_vbs, [%expr [%e expr] ?label:[%e opt_expr ~loc label]])
267273
| expr -> (no_vbs, expr)

0 commit comments

Comments
 (0)