blob: 6827303549c8245a3b15dfae0d1b711b06640cc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
(***********************************************************************)
(* *)
(* Caml Special Light *)
(* *)
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* Automatique. Distributed only by permission. *)
(* *)
(***********************************************************************)
(* $Id$ *)
open Misc
open Asttypes
open Longident
open Lambda
(* Get oo primitives identifiers *)
let oo_prim name =
try
transl_path
(fst (Env.lookup_value (Ldot (Lident "Oo", name)) Env.empty))
with Not_found ->
fatal_error ("Primitive " ^ name ^ " not found.")
(* Collect labels *)
let used_methods = ref ([] : (string * Ident.t) list);;
let meth lab =
let lab = lab.Label.lab_name in
try
List.assoc lab !used_methods
with Not_found ->
let id = Ident.create lab in
used_methods := (lab, id)::!used_methods;
id
let reset_labels () =
used_methods := []
(* Insert labels *)
let string s = Lconst (Const_base (Const_string s))
let transl_init kind labels expr =
if labels = [] then
expr
else
let init = Ident.create kind in
Llet(Alias, init, oo_prim kind,
List.fold_right
(fun (lab, id) expr ->
Llet(Strict, id, Lapply(Lvar init, [string lab]), expr))
labels
expr)
let transl_label_init expr =
let new_method = Ident.create "new_method" in
let expr' = transl_init "new_method" !used_methods expr in
reset_labels ();
expr'
|