summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2012-08-21 07:12:04 +0000
committerFabrice Le Fessant <Fabrice.Le_fessant@inria.fr>2012-08-21 07:12:04 +0000
commit3fa58bda8923a6fdb7f43849761199891d77149e (patch)
treef2a02676d6f87b8857eac9d7fde934f297cb7964
parent7ec7f16f55b6bc1622affe65eca532cf74b29d50 (diff)
Fix PR#5735: %apply and %revapply not first class citizens
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12870 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Changes2
-rw-r--r--bytecomp/translcore.ml18
-rw-r--r--bytecomp/translcore.mli2
-rw-r--r--bytecomp/translmod.ml7
4 files changed, 16 insertions, 13 deletions
diff --git a/Changes b/Changes
index e5f221647..bb9dc2498 100644
--- a/Changes
+++ b/Changes
@@ -17,7 +17,7 @@ Bug fixes:
- PR#5698: remove harcoded limit of 200000 labels in emitaux.ml
- PR#5708: catch Failure"int_of_string" in ocamldebug
- PR#5731: instruction scheduling forgot to account for destroyed registers
-
+- PR#5735: %apply and %revapply not first class citizens
Internals:
- Moved debugger/envaux.ml to typing/envaux.ml to publish env_of_only_summary
as part of compilerlibs, to be used on bin-annot files.
diff --git a/bytecomp/translcore.ml b/bytecomp/translcore.ml
index 8490f33b4..e3880076c 100644
--- a/bytecomp/translcore.ml
+++ b/bytecomp/translcore.ml
@@ -285,6 +285,12 @@ let prim_obj_dup =
{ prim_name = "caml_obj_dup"; prim_arity = 1; prim_alloc = true;
prim_native_name = ""; prim_native_float = false }
+let find_primitive loc prim_name =
+ match prim_name with
+ "%revapply" -> Prevapply loc
+ | "%apply" -> Pdirapply loc
+ | name -> Hashtbl.find primitives_table name
+
let transl_prim loc prim args =
let prim_name = prim.prim_name in
try
@@ -323,11 +329,7 @@ let transl_prim loc prim args =
end
with Not_found ->
try
- let p =
- match prim_name with
- "%revapply" -> Prevapply loc
- | "%apply" -> Pdirapply loc
- | name -> Hashtbl.find primitives_table name in
+ let p = find_primitive loc prim_name in
(* Try strength reduction based on the type of the argument *)
begin match (p, args) with
(Psetfield(n, _), [arg1; arg2]) -> Psetfield(n, maybe_pointer arg2)
@@ -354,7 +356,7 @@ let transl_prim loc prim args =
(* Eta-expand a primitive without knowing the types of its arguments *)
-let transl_primitive p =
+let transl_primitive loc p =
let prim =
try
let (gencomp, _, _, _, _, _, _, _) =
@@ -362,7 +364,7 @@ let transl_primitive p =
gencomp
with Not_found ->
try
- Hashtbl.find primitives_table p.prim_name
+ find_primitive loc p.prim_name
with Not_found ->
Pccall p in
match prim with
@@ -583,7 +585,7 @@ and transl_exp0 e =
Lfunction(Curried, [obj; meth; cache; pos],
Lsend(Cached, Lvar meth, Lvar obj, [Lvar cache; Lvar pos], e.exp_loc))
else
- transl_primitive p
+ transl_primitive e.exp_loc p
| Texp_ident(path, _, {val_kind = Val_anc _}) ->
raise(Error(e.exp_loc, Free_super_var))
| Texp_ident(path, _, {val_kind = Val_reg | Val_self _}) ->
diff --git a/bytecomp/translcore.mli b/bytecomp/translcore.mli
index 71717d12e..51a7295f4 100644
--- a/bytecomp/translcore.mli
+++ b/bytecomp/translcore.mli
@@ -26,7 +26,7 @@ val transl_apply: lambda -> (label * expression option * optional) list
-> Location.t -> lambda
val transl_let:
rec_flag -> (pattern * expression) list -> lambda -> lambda
-val transl_primitive: Primitive.description -> lambda
+val transl_primitive: Location.t -> Primitive.description -> lambda
val transl_exception:
Ident.t -> Path.t option -> exception_declaration -> lambda
diff --git a/bytecomp/translmod.ml b/bytecomp/translmod.ml
index 980d6dde9..1f58db6e7 100644
--- a/bytecomp/translmod.ml
+++ b/bytecomp/translmod.ml
@@ -49,7 +49,7 @@ let rec apply_coercion restr arg =
(Lapply(Lvar id, [apply_coercion cc_arg (Lvar param)],
Location.none))))
| Tcoerce_primitive p ->
- transl_primitive p
+ transl_primitive Location.none p
and apply_coercion_field id (pos, cc) =
apply_coercion cc (Lprim(Pfield pos, [Lvar id]))
@@ -278,7 +278,7 @@ and transl_structure fields cc rootpath = function
List.map
(fun (pos, cc) ->
match cc with
- Tcoerce_primitive p -> transl_primitive p
+ Tcoerce_primitive p -> transl_primitive Location.none p
| _ -> apply_coercion cc (Lvar v.(pos)))
pos_cc_list)
| _ ->
@@ -479,7 +479,8 @@ let transl_store_structure glob map prims str =
and store_primitive (pos, prim) cont =
Lsequence(Lprim(Psetfield(pos, false),
- [Lprim(Pgetglobal glob, []); transl_primitive prim]),
+ [Lprim(Pgetglobal glob, []);
+ transl_primitive Location.none prim]),
cont)
in List.fold_right store_primitive prims (transl_store !transl_store_subst str)