Skip to content

Commit e825719

Browse files
authored
Merge pull request #80 from hackwaly/ocaml-5.4
Add OCaml 5.4 support
2 parents 7dcc21a + 43e2d77 commit e825719

File tree

7 files changed

+68
-5
lines changed

7 files changed

+68
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- ubuntu-latest
2222
- macos-latest
2323
ocaml-compiler:
24+
- ocaml-base-compiler.5.4.0~beta2
2425
- 5.3.x
2526
- 5.2.x
2627
- 5.1.x

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.4 - 2025-09-20
2+
3+
### Added
4+
5+
* Add OCaml 5.4 support (#80).
6+
17
## 1.3.3 - 2024-11-10
28

39
### Added

src/debugger/inspect/types.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ let commu_ok = Cok
66
let row_fields row = row.row_fields
77
let row_field_repr = Btype.row_field_repr
88
[%%endif]
9+
10+
[%%if ocaml_version >= (5, 4, 0)]
11+
type constructor_tag = Data_types.constructor_tag =
12+
| Cstr_constant of int
13+
| Cstr_block of int
14+
| Cstr_unboxed
15+
| Cstr_extension of Path.t * bool
16+
[%%endif]

src/debugger/inspect/value_module.ml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,19 @@ let adopter scene typenv obj typ =
7878
Lwt.return
7979
(Some (new module_value ~scene ~typenv:typenv' ~obj ~path:(Path.Pident mid) ()))
8080
with _ -> Lwt.return (Some unknown_module_value) )
81-
| Tpackage (path, []) [@if ocaml_version >= (4, 13, 0)] -> (
81+
| Tpackage (path, []) [@if ocaml_version >= (4, 13, 0) && ocaml_version < (5, 4, 0)] -> (
82+
try
83+
let mty = typenv |> Typenv.find_modtype_expansion path in
84+
let mid =
85+
Ident.create_persistent
86+
(Printf.sprintf "M_%04x"
87+
(Float.to_int (Sys.time () *. 1e9) mod 0x10000))
88+
in
89+
let typenv' = typenv |> Typenv.add_module mid Types.Mp_present mty in
90+
Lwt.return
91+
(Some (new module_value ~scene ~typenv:typenv' ~obj ~path:(Path.Pident mid) ()))
92+
with _ -> Lwt.return (Some unknown_module_value) )
93+
| Tpackage {pack_path = path; pack_cstrs = []} [@if ocaml_version >= (5, 4, 0)] -> (
8294
try
8395
let mty = typenv |> Typenv.find_modtype_expansion path in
8496
let mid =

src/debugger/inspect/value_struct.ml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ class tuple_value ~scene ~typenv ~obj ?(pos = 0) ?(unboxed = false) ~members ()
3838
else "(‹1›, ‹2›, …)"
3939
end
4040

41+
class label_tuple_value ~scene ~typenv ~obj ?(pos = 0) ?(unboxed = false) ~members ()
42+
=
43+
let member_name i label =
44+
match label with
45+
| None -> "" ^ string_of_int (i + 1) ^ ""
46+
| Some label -> label
47+
in
48+
let members =
49+
members
50+
|> List.mapi (fun i (label, typ) -> (member_name i label, typ))
51+
in
52+
object (self)
53+
inherit struct_value ~scene ~typenv ~obj ~pos ~unboxed ~members
54+
55+
method to_short_string =
56+
let num_named = self#num_named in
57+
if num_named = 0 then "()"
58+
else if num_named = 1 then "‹1›"
59+
else if num_named = 2 then "(‹1›, ‹2›)"
60+
else if num_named = 3 then "(‹1›, ‹2›, ‹3›)"
61+
else "(‹1›, ‹2›, …)"
62+
end
63+
4164
class record_value ~scene ~typenv ~obj ?(pos = 0) ?(unboxed = false) ~members ()
4265
=
4366
object
@@ -200,8 +223,10 @@ let adopter scene typenv obj typ =
200223
Lwt.return (Some (new variant_value ~tag ?payload ~embed:true ()))
201224
in
202225
match Types.get_desc typ with
203-
| Ttuple tys ->
226+
| Ttuple tys [@if ocaml_version < (5, 4, 0)] ->
204227
Lwt.return (Some (new tuple_value ~scene ~typenv ~obj ~members:tys ()))
228+
| Ttuple tys [@if ocaml_version >= (5, 4, 0)] ->
229+
Lwt.return (Some (new label_tuple_value ~scene ~typenv ~obj ~members:tys ()))
205230
| Tconstr (path, type_args, _) -> (
206231
match typenv |> Typenv.find_type path with
207232
| exception Not_found -> Lwt.return None

src/debugger/misc/util.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,17 @@ module Path = struct
2929
in
3030
aux path
3131

32+
[%%if ocaml_version >= (5, 4, 0)]
33+
let lift_longident = Location.mknoloc
34+
[%%else]
35+
let lift_longident = Fun.id
36+
[%%endif]
37+
3238
let rec to_longident path =
3339
match path with
3440
| Pident id -> Longident.Lident (Ident.name id)
35-
| Pdot (p, d) -> Longident.Ldot (to_longident p, d)
36-
| Pextra_ty (p, Pcstr_ty d) [@if ocaml_version >= (5, 1, 0)] -> Longident.Ldot (to_longident p, d)
37-
| Papply (p1, p2) -> Longident.Lapply (to_longident p1, to_longident p2)
41+
| Pdot (p, d) -> Longident.Ldot (lift_longident (to_longident p), lift_longident d)
42+
| Pextra_ty (p, Pcstr_ty d) [@if ocaml_version >= (5, 1, 0)] -> Longident.Ldot (lift_longident (to_longident p), lift_longident d)
43+
| Papply (p1, p2) -> Longident.Lapply (lift_longident (to_longident p1), lift_longident (to_longident p2))
3844
| Pextra_ty (p, Pext_ty) [@if ocaml_version >= (5, 1, 0)] -> to_longident p
3945
end

src/typenv/types.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include Ocaml_common.Types
2+
3+
[%%if ocaml_version >= (5, 4, 0)]
4+
type constructor_description = Data_types.constructor_description
5+
[%%endif]

0 commit comments

Comments
 (0)