summaryrefslogtreecommitdiff
path: root/bytecomp
diff options
context:
space:
mode:
authorGabriel Scherer <gabriel.scherer@gmail.com>2014-12-13 22:13:32 +0000
committerGabriel Scherer <gabriel.scherer@gmail.com>2014-12-13 22:13:32 +0000
commit16bc43219cbd49bb3450e362c6c3e0b3a129f374 (patch)
treec95c0e6e177a572b8a747de3301c8763c6ef9bb8 /bytecomp
parent14ab17aab93f5588d0f37b6dd445c3cd74396ca2 (diff)
downloadocaml-16bc43219cbd49bb3450e362c6c3e0b3a129f374.tar.gz
Add a special syntax for index operators
This commit introduces a new syntax for index operators. Six core parenthesis operator are added: .(), .[], .{}, .{,}, .{,,}, .{,..,}. The .{,}/.{,,}/.{,,,} operators are defined for compatibility with the Bigarray syntax extension. Each core index operator is available in a access/assignement versions. For instance, .() is declined in * .() : index operator * .()<- : indexed assignment operator The general syntax for these index operators as implemented in the parser is index_operator::= index_operator_core [<-] From: octachron <octa@polychoron.fr> git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15660 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'bytecomp')
-rw-r--r--bytecomp/translcore.ml19
1 files changed, 18 insertions, 1 deletions
diff --git a/bytecomp/translcore.ml b/bytecomp/translcore.ml
index 32d7d40894..002741178c 100644
--- a/bytecomp/translcore.ml
+++ b/bytecomp/translcore.ml
@@ -316,6 +316,21 @@ let primitives_table = create_hashtable 57 [
"%int_as_pointer", Pint_as_pointer;
]
+let index_primitives_table =
+ let make_ba_ref n="%caml_ba_opt_ref_"^(string_of_int n),
+ fun () -> Pbigarrayref(!Clflags.fast, n, Pbigarray_unknown, Pbigarray_unknown_layout)
+ and make_ba_set n="%caml_ba_opt_set_"^(string_of_int n),
+ fun () -> Pbigarrayset(!Clflags.fast, n, Pbigarray_unknown, Pbigarray_unknown_layout) in
+ create_hashtable 10 [
+ "%array_opt_get", ( fun () -> if !Clflags.fast then Parrayrefu Pgenarray else Parrayrefs Pgenarray );
+ "%array_opt_set", ( fun () -> if !Clflags.fast then Parraysetu Pgenarray else Parraysets Pgenarray );
+ "%string_opt_get", ( fun () -> if !Clflags.fast then Pstringrefu else Pstringrefs );
+ "%string_opt_set", ( fun () -> if !Clflags.fast then Pstringsetu else Pstringsets );
+ make_ba_ref 1; make_ba_set 1;
+ make_ba_ref 2; make_ba_set 2;
+ make_ba_ref 3; make_ba_set 3;
+]
+
let prim_makearray =
{ prim_name = "caml_make_vect"; prim_arity = 2; prim_alloc = true;
prim_native_name = ""; prim_native_float = false }
@@ -333,7 +348,9 @@ let find_primitive loc prim_name =
| "%loc_LINE" -> Ploc Loc_LINE
| "%loc_POS" -> Ploc Loc_POS
| "%loc_MODULE" -> Ploc Loc_MODULE
- | name -> Hashtbl.find primitives_table name
+ | name ->
+ try Hashtbl.find index_primitives_table name @@ () with
+ | Not_found -> Hashtbl.find primitives_table name
let specialize_comparison table env ty =
let (gencomp, intcomp, floatcomp, stringcomp,