Skip to content

Commit 6eaf032

Browse files
committedOct 11, 2024
PoC: generic infix operators
1 parent 5f5917e commit 6eaf032

15 files changed

+470
-394
lines changed
 

‎compiler/core/lam_convert.ml

+11
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
232232
| Pduprecord -> prim ~primitive:Pduprecord ~args loc
233233
| Plazyforce -> prim ~primitive:Plazyforce ~args loc
234234
| Praise _ -> prim ~primitive:Praise ~args loc
235+
| Pinfix _ -> assert false
235236
| Pobjcomp x -> prim ~primitive:(Pobjcomp x) ~args loc
236237
| Pobjorder -> prim ~primitive:Pobjorder ~args loc
237238
| Pobjmin -> prim ~primitive:Pobjmin ~args loc
@@ -475,6 +476,16 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) :
475476
| Lprim (Pimport, args, loc) ->
476477
let args = Ext_list.map args (convert_aux ~dynamic_import:true) in
477478
lam_prim ~primitive:Pimport ~args loc
479+
| Lprim (Pinfix (Inf_custom (mod_, op)), args, loc) ->
480+
let fn = Lam.var (Ident.create_persistent op) in
481+
let args = Ext_list.map args (convert_aux ~dynamic_import) in
482+
let ap_info : Lam.ap_info =
483+
{ap_loc = loc; ap_status = App_na; ap_inlined = Lambda.Default_inline}
484+
in
485+
Lam.apply fn args ap_info
486+
| Lprim (Pinfix Inf_invariant, args, loc) ->
487+
(* TODO : invariant *)
488+
assert false
478489
| Lprim (primitive, args, loc) ->
479490
let args = Ext_list.map args (convert_aux ~dynamic_import) in
480491
lam_prim ~primitive ~args loc

‎compiler/ml/lambda.ml

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ type immediate_or_pointer = Immediate | Pointer
175175

176176
type is_safe = Safe | Unsafe
177177

178+
type infix_info = Inf_custom of string * string | Inf_invariant
179+
178180
type primitive =
179181
| Pidentity
180182
| Pignore
@@ -198,6 +200,8 @@ type primitive =
198200
| Pccall of Primitive.description
199201
(* Exceptions *)
200202
| Praise of raise_kind
203+
(* Infix *)
204+
| Pinfix of infix_info
201205
(* object operations *)
202206
| Pobjcomp of comparison
203207
| Pobjorder

‎compiler/ml/lambda.mli

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ type pointer_info =
138138
| Pt_shape_none
139139
| Pt_assertfalse
140140

141+
type infix_info = Inf_custom of string * string | Inf_invariant
142+
141143
type primitive =
142144
| Pidentity
143145
| Pignore
@@ -161,6 +163,8 @@ type primitive =
161163
| Pccall of Primitive.description
162164
(* Exceptions *)
163165
| Praise of raise_kind
166+
(* Infix *)
167+
| Pinfix of infix_info
164168
(* object primitives *)
165169
| Pobjcomp of comparison
166170
| Pobjorder

‎compiler/ml/printlambda.ml

+2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ let primitive ppf = function
125125
| Plazyforce -> fprintf ppf "force"
126126
| Pccall p -> fprintf ppf "%s" p.prim_name
127127
| Praise k -> fprintf ppf "%s" (Lambda.raise_kind k)
128+
| Pinfix (Inf_custom (mod_, op)) -> fprintf ppf "%s.%s" mod_ op
129+
| Pinfix Inf_invariant -> fprintf ppf "invariant"
128130
| Pobjcomp Ceq -> fprintf ppf "=="
129131
| Pobjcomp Cneq -> fprintf ppf "!="
130132
| Pobjcomp Clt -> fprintf ppf "<"

0 commit comments

Comments
 (0)