Skip to content

Commit

Permalink
Upgrade to OCaml 4.13
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Jul 26, 2024
1 parent 6a4e595 commit e765106
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 26 deletions.
3 changes: 1 addition & 2 deletions learn-ocaml-client.opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ depends: [
"ipaddr" {= "2.9.0" }
"lwt" {>= "4.0.0"}
"lwt_ssl"
"ocaml" {(>= "4.12") & (< "4.13~")}
"ocaml" {(>= "4.12") & (< "4.14~")}
"ocamlfind" {build}
"ocp-indent-nlfork"
"ocplib-json-typed" {>= "0.7"}
Expand All @@ -43,7 +43,6 @@ depends: [
"ppx_inline_test"
"ppx_fields_conv"
"ppx_sexp_conv"
"ppx_tools"
"ssl" {= "0.5.12"}
"vg"
]
Expand Down
24 changes: 15 additions & 9 deletions learn-ocaml-client.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ depends: [
"conf-pkg-config" {= "2"}
"cppo" {= "1.6.8"}
"csexp" {= "1.5.1"}
"cstruct" {= "5.2.0"}
"cstruct" {= "6.2.0"}
"digestif" {= "1.1.0"}
"dune" {= "2.9.3"}
"dune-configurator" {= "2.9.3"}
Expand All @@ -69,14 +69,14 @@ depends: [
"menhirSdk" {= "20220210"}
"mmap" {= "1.1.0"}
"num" {= "1.4"}
"ocaml" {= "4.12.1"}
"ocaml" {= "4.13.1"}
"ocaml-compiler-libs" {= "v0.12.4"}
"ocaml-config" {= "2"}
"ocaml-options-vanilla" {= "1"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocamlbuild" {= "0.14.1"}
"ocamlfind" {= "1.9.3"}
"ocp-indent-nlfork" {= "1.5.4"}
"ocp-indent-nlfork" {= "1.5.5"}
"ocp-ocamlres" {= "0.4"}
"ocplib-endian" {= "1.2"}
"ocplib-json-typed" {= "0.7.1"}
Expand All @@ -90,16 +90,15 @@ depends: [
"ppx_compare" {= "v0.14.0"}
"ppx_derivers" {= "1.2.1"}
"ppx_enumerate" {= "v0.14.0"}
"ppx_expect" {= "v0.14.0"}
"ppx_fields_conv" {= "v0.14.1"}
"ppx_expect" {= "v0.14.2"}
"ppx_fields_conv" {= "v0.14.2"}
"ppx_hash" {= "v0.14.0"}
"ppx_here" {= "v0.14.0"}
"ppx_inline_test" {= "v0.14.1"}
"ppx_js_style" {= "v0.14.1"}
"ppx_optcomp" {= "v0.14.0"}
"ppx_sexp_conv" {= "v0.14.1"}
"ppx_tools" {= "6.4"}
"ppxlib" {= "0.15.0"}
"ppx_optcomp" {= "v0.14.3"}
"ppx_sexp_conv" {= "v0.14.3"}
"ppxlib" {= "0.25.1"}
"re" {= "1.10.3"}
"result" {= "1.5"}
"seq" {= "base"}
Expand All @@ -120,3 +119,10 @@ depends: [
]
build: ["dune" "build" "@install" "-p" name "-j" jobs]
dev-repo: "git+https://github.com/ocaml-sf/learn-ocaml"
pin-depends: [
["asak.0.4" "git+https://github.com/nobrakal/asak#922ceed"]
[
"ocp-indent-nlfork.1.5.5"
"git+ssh://git@github.com/OCamlPro/ocp-indent#nlfork"
]
]
4 changes: 1 addition & 3 deletions learn-ocaml.opam
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ depends: [
"magic-mime"
"markup"
"markup-lwt"
"ocaml" {(>= "4.12") & (< "4.13~")}
"ocaml" {(>= "4.13") & (< "4.14~")}
"ocamlfind" {build}
"ocp-indent-nlfork" {>= "1.5.5"}
"ocplib-json-typed" {>= "0.7"}
Expand All @@ -61,8 +61,6 @@ depends: [
"ppx_expect"
"ppx_inline_test"
"ppx_sexp_conv"
"ppx_tools"
"ppx_tools_versioned"
"re"
"ssl" {= "0.5.12"}
"uutf" {>= "1.0" }
Expand Down
26 changes: 16 additions & 10 deletions learn-ocaml.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ depends: [
"conf-pkg-config" {= "2"}
"cppo" {= "1.6.8"}
"csexp" {= "1.5.1"}
"cstruct" {= "5.2.0"}
"cstruct" {= "6.2.0"}
"decompress" {= "0.8.1"}
"digestif" {= "1.1.0"}
"dune" {= "2.9.3"}
Expand Down Expand Up @@ -77,14 +77,14 @@ depends: [
"menhirSdk" {= "20220210"}
"mmap" {= "1.1.0"}
"num" {= "1.4"}
"ocaml" {= "4.12.1"}
"ocaml" {= "4.13.1"}
"ocaml-compiler-libs" {= "v0.12.4"}
"ocaml-config" {= "2"}
"ocaml-options-vanilla" {= "1"}
"ocaml-syntax-shims" {= "1.0.0"}
"ocamlbuild" {= "0.14.1"}
"ocamlfind" {= "1.9.3"}
"ocp-indent-nlfork" {= "1.5.4"}
"ocp-indent-nlfork" {= "1.5.5"}
"ocp-ocamlres" {= "0.4"}
"ocplib-endian" {= "1.2"}
"ocplib-json-typed" {= "0.7.1"}
Expand All @@ -100,19 +100,17 @@ depends: [
"ppx_base" {= "v0.14.0"}
"ppx_cold" {= "v0.14.0"}
"ppx_compare" {= "v0.14.0"}
"ppx_cstruct" {= "5.2.0"}
"ppx_cstruct" {= "6.2.0"}
"ppx_derivers" {= "1.2.1"}
"ppx_enumerate" {= "v0.14.0"}
"ppx_expect" {= "v0.14.0"}
"ppx_expect" {= "v0.14.2"}
"ppx_hash" {= "v0.14.0"}
"ppx_here" {= "v0.14.0"}
"ppx_inline_test" {= "v0.14.1"}
"ppx_js_style" {= "v0.14.1"}
"ppx_optcomp" {= "v0.14.0"}
"ppx_sexp_conv" {= "v0.14.1"}
"ppx_tools" {= "6.4"}
"ppx_tools_versioned" {= "5.4.0"}
"ppxlib" {= "0.15.0"}
"ppx_optcomp" {= "v0.14.3"}
"ppx_sexp_conv" {= "v0.14.3"}
"ppxlib" {= "0.25.1"}
"re" {= "1.10.3"}
"react" {= "1.2.2"}
"reactiveData" {= "0.2.2"}
Expand Down Expand Up @@ -149,3 +147,11 @@ This contains the binaries forming the engine for the learn-ocaml platform, and
the common files. A demo exercise repository is also provided as example.
"""
run-test: [make "test"]
depexts: ["lsof"] {os-distribution = "alpine"}
pin-depends: [
["asak.0.4" "git+https://github.com/nobrakal/asak#922ceed"]
[
"ocp-indent-nlfork.1.5.5"
"git+ssh://git@github.com/OCamlPro/ocp-indent#nlfork"
]
]
151 changes: 151 additions & 0 deletions src/ppx-metaquot/ast_convenience.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
(* This file is part of the ppx_tools package. It is released *)
(* under the terms of the MIT license (see LICENSE file). *)
(* Copyright 2013 Alain Frisch and LexiFi *)

open Parsetree
open Asttypes
open Location
open Ast_helper


module Label = struct

type t = Asttypes.arg_label

type desc = Asttypes.arg_label =
Nolabel
| Labelled of string
| Optional of string

let explode x = x

let nolabel = Nolabel
let labelled x = Labelled x
let optional x = Optional x

end

module Constant = struct
type t = Parsetree.constant =
Pconst_integer of string * char option
| Pconst_char of char
#if OCAML_VERSION >= (4, 11, 0)
| Pconst_string of string * Location.t * string option
#else
| Pconst_string of string * string option
#endif
| Pconst_float of string * char option

let of_constant x = x

let to_constant x = x

end

let may_tuple ?loc tup = function
| [] -> None
| [x] -> Some x
| l -> Some (tup ?loc ?attrs:None l)

#if OCAML_VERSION >= (4, 13, 0)
let may_pat_tuple ?loc tup = function
| [] -> None
| [x] -> Some ([], x)
| l -> Some ([], tup ?loc ?attrs:None l)
#else
let may_pat_tuple ?loc tup x = may_tuple ?loc tup x
#endif

let lid ?(loc = !default_loc) s = mkloc (Longident.parse s) loc [@ocaml.warning "-3"]
let constr ?loc ?attrs s args = Exp.construct ?loc ?attrs (lid ?loc s) (may_tuple ?loc Exp.tuple args)
let nil ?loc ?attrs () = constr ?loc ?attrs "[]" []
let unit ?loc ?attrs () = constr ?loc ?attrs "()" []
let tuple ?loc ?attrs = function
| [] -> unit ?loc ?attrs ()
| [x] -> x
| xs -> Exp.tuple ?loc ?attrs xs
let cons ?loc ?attrs hd tl = constr ?loc ?attrs "::" [hd; tl]
let list ?loc ?attrs l = List.fold_right (cons ?loc ?attrs) l (nil ?loc ?attrs ())
#if OCAML_VERSION >= (4, 11, 0)
let str ?(loc = !default_loc) ?attrs s = Exp.constant ~loc ?attrs (Pconst_string (s, loc, None))
#else
let str ?loc ?attrs s = Exp.constant ?loc ?attrs (Pconst_string (s, None))
#endif
let int ?loc ?attrs x = Exp.constant ?loc ?attrs (Pconst_integer (string_of_int x, None))
let int32 ?loc ?attrs x = Exp.constant ?loc ?attrs (Pconst_integer (Int32.to_string x, Some 'l'))
let int64 ?loc ?attrs x = Exp.constant ?loc ?attrs (Pconst_integer (Int64.to_string x, Some 'L'))
let char ?loc ?attrs x = Exp.constant ?loc ?attrs (Pconst_char x)
let float ?loc ?attrs x = Exp.constant ?loc ?attrs (Pconst_float (string_of_float x, None))
let record ?loc ?attrs ?over l =
Exp.record ?loc ?attrs (List.map (fun (s, e) -> (lid ~loc:e.pexp_loc s, e)) l) over
let func ?loc ?attrs l = Exp.function_ ?loc ?attrs (List.map (fun (p, e) -> Exp.case p e) l)
let lam ?loc ?attrs ?(label = Label.nolabel) ?default pat exp = Exp.fun_ ?loc ?attrs label default pat exp
let app ?loc ?attrs f l = if l = [] then f else Exp.apply ?loc ?attrs f (List.map (fun a -> Label.nolabel, a) l)
let evar ?loc ?attrs s = Exp.ident ?loc ?attrs (lid ?loc s)
let let_in ?loc ?attrs ?(recursive = false) b body =
Exp.let_ ?loc ?attrs (if recursive then Recursive else Nonrecursive) b body

let sequence ?loc ?attrs = function
| [] -> unit ?loc ?attrs ()
| hd :: tl -> List.fold_left (fun e1 e2 -> Exp.sequence ?loc ?attrs e1 e2) hd tl

let pvar ?(loc = !default_loc) ?attrs s = Pat.var ~loc ?attrs (mkloc s loc)
let pconstr ?loc ?attrs s args = Pat.construct ?loc ?attrs (lid ?loc s) (may_pat_tuple ?loc Pat.tuple args)
let precord ?loc ?attrs ?(closed = Open) l =
Pat.record ?loc ?attrs (List.map (fun (s, e) -> (lid ~loc:e.ppat_loc s, e)) l) closed
let pnil ?loc ?attrs () = pconstr ?loc ?attrs "[]" []
let pcons ?loc ?attrs hd tl = pconstr ?loc ?attrs "::" [hd; tl]
let punit ?loc ?attrs () = pconstr ?loc ?attrs "()" []
let ptuple ?loc ?attrs = function
| [] -> punit ?loc ?attrs ()
| [x] -> x
| xs -> Pat.tuple ?loc ?attrs xs
let plist ?loc ?attrs l = List.fold_right (pcons ?loc ?attrs) l (pnil ?loc ?attrs ())

#if OCAML_VERSION >= (4, 11, 0)
let pstr ?(loc = !default_loc) ?attrs s = Pat.constant ~loc ?attrs (Pconst_string (s, loc, None))
#else
let pstr ?loc ?attrs s = Pat.constant ?loc ?attrs (Pconst_string (s, None))
#endif
let pint ?loc ?attrs x = Pat.constant ?loc ?attrs (Pconst_integer (string_of_int x, None))
let pchar ?loc ?attrs x = Pat.constant ?loc ?attrs (Pconst_char x)
let pfloat ?loc ?attrs x = Pat.constant ?loc ?attrs (Pconst_float (string_of_float x, None))

let tconstr ?loc ?attrs c l = Typ.constr ?loc ?attrs (lid ?loc c) l

let get_str = function
#if OCAML_VERSION >= (4, 11, 0)
| {pexp_desc=Pexp_constant (Pconst_string (s, _, _)); _} -> Some s
#else
| {pexp_desc=Pexp_constant (Pconst_string (s, _)); _} -> Some s
#endif
| _ -> None

let get_str_with_quotation_delimiter = function
#if OCAML_VERSION >= (4, 11, 0)
| {pexp_desc=Pexp_constant (Pconst_string (s, _, d)); _} -> Some (s, d)
#else
| {pexp_desc=Pexp_constant (Pconst_string (s, d)); _} -> Some (s, d)
#endif
| _ -> None

let get_lid = function
| {pexp_desc=Pexp_ident{txt=id;_};_} ->
Some (String.concat "." (Longident.flatten id))
| _ -> None

let find_attr s attrs =
try Some ((List.find (fun {attr_name=x;_} -> x.txt = s) attrs).attr_payload)
with Not_found -> None

let expr_of_payload = function
| PStr [{pstr_desc=Pstr_eval(e, _); _}] -> Some e
| _ -> None

let find_attr_expr s attrs =
match find_attr s attrs with
| Some e -> expr_of_payload e
| None -> None

let has_attr s attrs =
find_attr s attrs <> None
Loading

0 comments on commit e765106

Please sign in to comment.