Skip to content

Commit

Permalink
Add support for global_ and nonlocal_ constructor arguments (ocam…
Browse files Browse the repository at this point in the history
  • Loading branch information
riaqn committed Nov 21, 2022
1 parent e7dd740 commit 988306d
Show file tree
Hide file tree
Showing 40 changed files with 17,797 additions and 15,475 deletions.
305 changes: 129 additions & 176 deletions boot/menhir/menhirLib.ml

Large diffs are not rendered by default.

269 changes: 117 additions & 152 deletions boot/menhir/menhirLib.mli

Large diffs are not rendered by default.

31,842 changes: 16,846 additions & 14,996 deletions boot/menhir/parser.ml

Large diffs are not rendered by default.

Binary file modified boot/ocamlc
Binary file not shown.
Binary file modified boot/ocamllex
Binary file not shown.
8 changes: 4 additions & 4 deletions ocamldoc/odoc_sig.ml
Expand Up @@ -384,7 +384,7 @@ module Analyser =
in
let vc_args =
match cd_args with
| Cstr_tuple l -> Cstr_tuple (List.map (Odoc_env.subst_type env) l)
| Cstr_tuple l -> Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type env ty) l)
| Cstr_record l ->
Cstr_record (List.map (get_field env name_comment_list) l)
in
Expand Down Expand Up @@ -421,7 +421,7 @@ module Analyser =
let open Typedtree in
function
| Cstr_tuple l ->
Odoc_type.Cstr_tuple (List.map tuple l)
Odoc_type.Cstr_tuple (List.map (fun (ty, _) -> tuple ty) l)
| Cstr_record l ->
let comments = Record.(doc typedtree) pos_end l in
Odoc_type.Cstr_record (List.map (record comments) l)
Expand Down Expand Up @@ -847,7 +847,7 @@ module Analyser =
let xt_args =
match types_ext.ext_args with
| Cstr_tuple l ->
Cstr_tuple (List.map (Odoc_env.subst_type new_env) l)
Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type new_env ty) l)
| Cstr_record l ->
let docs = Record.(doc types ext_loc_end) l in
Cstr_record (List.map (get_field new_env docs) l)
Expand Down Expand Up @@ -891,7 +891,7 @@ module Analyser =
let ex_args =
let pos_end = Loc.end_ types_ext.ext_loc in
match types_ext.ext_args with
| Cstr_tuple l -> Cstr_tuple (List.map (Odoc_env.subst_type env) l)
| Cstr_tuple l -> Cstr_tuple (List.map (fun (ty, _) -> Odoc_env.subst_type env ty) l)
| Cstr_record l ->
let docs = Record.(doc types) pos_end l in
Cstr_record (List.map (get_field env docs) l)
Expand Down
12 changes: 6 additions & 6 deletions parsing/builtin_attributes.ml
Expand Up @@ -496,12 +496,6 @@ let has_local_opt attrs =
let has_curry attrs =
has_attribute ["extension.curry"; "ocaml.curry"; "curry"] attrs

let has_global attrs =
has_attribute ["extension.global"; "ocaml.global"; "global"] attrs

let has_nonlocal attrs =
has_attribute ["extension.nonlocal"; "ocaml.nonlocal"; "nonlocal"] attrs

(* extension.* is generated by the parser and not usually written directly,
so does not have a short form. An error is reported if it is seen when
the extension is disabled *)
Expand All @@ -518,6 +512,12 @@ let check_local ext_names other_names attr =
let has_local attr =
check_local ["extension.local"] ["ocaml.local"; "local"] attr

let has_global attrs =
check_local ["extension.global"] ["ocaml.global"; "global"] attrs

let has_nonlocal attrs =
check_local ["extension.nonlocal"] ["ocaml.nonlocal"; "nonlocal"] attrs

let tailcall attr =
let has_nontail = has_attribute ["ocaml.nontail"; "nontail"] attr in
let tail_attrs = filter_attributes [["ocaml.tail";"tail"], true] attr in
Expand Down
4 changes: 2 additions & 2 deletions parsing/builtin_attributes.mli
Expand Up @@ -134,12 +134,12 @@ val parse_standard_implementation_attributes : Parsetree.attribute -> unit

val has_local_opt: Parsetree.attributes -> bool
val has_curry: Parsetree.attributes -> bool
val has_global: Parsetree.attributes -> bool
val has_nonlocal: Parsetree.attributes -> bool

(* These functions report Error if the builtin extension.* attributes
are present despite the extension being disabled *)
val has_local: Parsetree.attributes -> (bool,unit) result
val has_global: Parsetree.attributes -> (bool,unit) result
val has_nonlocal: Parsetree.attributes -> (bool,unit) result
val tailcall : Parsetree.attributes ->
([`Tail|`Nontail|`Tail_if_possible] option, [`Conflict]) result
val has_include_functor : Parsetree.attributes -> (bool,unit) result
Expand Down
25 changes: 24 additions & 1 deletion parsing/parser.mly
Expand Up @@ -243,6 +243,18 @@ let mkld_global_maybe gbl ld loc =
| Nonlocal -> mkld_nonlocal ld loc
| Nothing -> ld

let mkcty_global cty loc =
{ cty with ptyp_attributes = global_attr loc :: cty.ptyp_attributes }

let mkcty_nonlocal cty loc =
{ cty with ptyp_attributes = nonlocal_attr loc :: cty.ptyp_attributes }

let mkcty_global_maybe gbl cty loc =
match gbl with
| Global -> mkcty_global cty loc
| Nonlocal -> mkcty_nonlocal cty loc
| Nothing -> cty

(* TODO define an abstraction boundary between locations-as-pairs
and locations-as-Location.t; it should be clear when we move from
one world to the other *)
Expand Down Expand Up @@ -3302,8 +3314,14 @@ generalized_constructor_arguments:
{ ($2,Pcstr_tuple [],Some $4) }
;

%inline atomic_type_gbl:
gbl = global_flag cty = atomic_type {
mkcty_global_maybe gbl cty (make_loc $loc(gbl))
}
;

constructor_arguments:
| tys = inline_separated_nonempty_llist(STAR, atomic_type)
| tys = inline_separated_nonempty_llist(STAR, atomic_type_gbl)
%prec below_HASH
{ Pcstr_tuple tys }
| LBRACE label_declarations RBRACE
Expand Down Expand Up @@ -3911,6 +3929,11 @@ mutable_or_global_flag:
| GLOBAL { Immutable, Global }
| NONLOCAL { Immutable, Nonlocal }
;
%inline global_flag:
{ Nothing }
| GLOBAL { Global }
| NONLOCAL { Nonlocal }
;
virtual_flag:
/* empty */ { Concrete }
| VIRTUAL { Virtual }
Expand Down

0 comments on commit 988306d

Please sign in to comment.