|
22 | 22 | * along with this program; if not, write to the Free Software
|
23 | 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
|
24 | 24 |
|
25 |
| -let caml_id_field_info : Lam_primitive.t = (Pfield (0, Fld_record {name = "CamlId"; mutable_flag = Mutable;})) |
| 25 | + |
| 26 | +let caml_id_field_info : Lambda.field_dbg_info = Fld_record {name = Literals.exception_id; mutable_flag = Mutable;} |
| 27 | +let name_info : Lambda.field_dbg_info = Fld_record {name = Literals.exception_debug; mutable_flag = Immutable;} |
| 28 | +let lam_caml_id : Lam_primitive.t = Pfield(0, caml_id_field_info) |
| 29 | +let lam_name : Lam_primitive.t = Pfield (1, name_info) |
26 | 30 | let prim = Lam.prim
|
27 | 31 |
|
| 32 | + |
| 33 | +let num_of_ident name = |
| 34 | + begin match name with |
| 35 | + | "Out_of_memory" -> 0 |
| 36 | + | "Sys_error" -> -1 |
| 37 | + | "Failure" -> -2 |
| 38 | + | "Invalid_argument" -> -3 |
| 39 | + | "End_of_file" -> -4 |
| 40 | + | "Division_by_zero" -> -5 |
| 41 | + | "Not_found" -> -6 |
| 42 | + | "Match_failure" -> -7 |
| 43 | + | "Stack_overflow" -> -8 |
| 44 | + | "Assert_failure" -> -9 |
| 45 | + | "Sys_blocked_io" -> -10 |
| 46 | + | "Undefined_recursive_module" -> -11 |
| 47 | + | _ -> assert false |
| 48 | + end |
| 49 | + |
| 50 | + |
| 51 | +let lam_extension_id loc (head : Lam.t) = |
| 52 | + match head with |
| 53 | + | Lprim {primitive = Pglobal_exception id} -> |
| 54 | + Lam.const (Const_int {value = num_of_ident id.name; comment = Some id.name} ) |
| 55 | + | _ -> prim ~primitive:lam_caml_id ~args:[head] loc |
| 56 | + |
| 57 | + |
| 58 | +let unbox_extension info (args : Lam.t list) mutable_flag loc = |
| 59 | + begin match args with |
| 60 | + | head :: rest -> |
| 61 | + let args = |
| 62 | + match head with |
| 63 | + | Lprim {primitive = Pglobal_exception id} -> |
| 64 | + let name = Ident.name id in |
| 65 | + let id = num_of_ident name in |
| 66 | + Lam.const (Const_int {value = id; comment = None}) |
| 67 | + :: (Ext_list.append_one rest (Lam.const (Const_string (name)))) |
| 68 | + | _ -> |
| 69 | + prim ~primitive:lam_caml_id ~args:[head] loc :: |
| 70 | + (Ext_list.append_one rest (prim ~primitive:lam_name ~args:[head] loc)) |
| 71 | + in |
| 72 | + prim ~primitive:(Pmakeblock (0,info,mutable_flag)) ~args loc |
| 73 | + | _ -> assert false end |
| 74 | + |
28 | 75 | (** A conservative approach to avoid packing exceptions
|
29 | 76 | for lambda expression like {[
|
30 | 77 | try { ... }catch(id){body}
|
@@ -227,7 +274,19 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
|
227 | 274 | prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
|
228 | 275 | | Blk_extension ->
|
229 | 276 | let info : Lam_tag_info.t = Blk_extension in
|
230 |
| - prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc |
| 277 | + unbox_extension info args mutable_flag loc |
| 278 | + | Blk_record_ext s -> |
| 279 | + let info : Lam_tag_info.t = Blk_record_ext s in |
| 280 | + unbox_extension info args mutable_flag loc |
| 281 | + | Blk_extension_slot -> |
| 282 | + ( |
| 283 | + match args with |
| 284 | + | [ Lconst (Const_string name)] -> |
| 285 | + prim ~primitive:(Pcreate_extension name) ~args:[] loc |
| 286 | + | _ -> |
| 287 | + assert false |
| 288 | + ) |
| 289 | + |
231 | 290 | | Blk_class ->
|
232 | 291 | let info : Lam_tag_info.t = Blk_class in
|
233 | 292 | prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
|
|
0 commit comments