1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
open Format
|
|
|
|
open Asttypes
|
1995-07-27 10:40:34 -07:00
|
|
|
open Primitive
|
1995-07-25 04:38:42 -07:00
|
|
|
open Typedtree
|
1995-05-04 03:15:53 -07:00
|
|
|
open Lambda
|
|
|
|
|
|
|
|
|
|
|
|
let rec structured_constant = function
|
|
|
|
Const_base(Const_int n) -> print_int n
|
|
|
|
| Const_base(Const_char c) ->
|
|
|
|
print_string "'"; print_string(Char.escaped c); print_string "'"
|
|
|
|
| Const_base(Const_string s) ->
|
|
|
|
print_string "\""; print_string(String.escaped s); print_string "\""
|
|
|
|
| Const_base(Const_float s) ->
|
|
|
|
print_string s
|
1995-07-02 09:45:21 -07:00
|
|
|
| Const_pointer n -> print_int n; print_string "a"
|
1995-05-04 03:15:53 -07:00
|
|
|
| Const_block(tag, []) ->
|
|
|
|
print_string "["; print_int tag; print_string "]"
|
|
|
|
| Const_block(tag, sc1::scl) ->
|
|
|
|
open_hovbox 1;
|
|
|
|
print_string "["; print_int tag; print_string ":";
|
|
|
|
print_space();
|
|
|
|
open_hovbox 0;
|
|
|
|
structured_constant sc1;
|
|
|
|
List.iter (fun sc -> print_space(); structured_constant sc) scl;
|
|
|
|
close_box();
|
|
|
|
print_string "]";
|
|
|
|
close_box()
|
1995-07-27 10:40:34 -07:00
|
|
|
| Const_float_array [] ->
|
|
|
|
print_string "[| |]"
|
|
|
|
| Const_float_array (f1 :: fl) ->
|
|
|
|
open_hovbox 1;
|
|
|
|
print_string "[|";
|
|
|
|
open_hovbox 0;
|
|
|
|
print_string f1;
|
|
|
|
List.iter (fun f -> print_space(); print_string f) fl;
|
|
|
|
close_box();
|
|
|
|
print_string "|]";
|
|
|
|
close_box()
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let primitive = function
|
|
|
|
Pidentity -> print_string "id"
|
|
|
|
| Pgetglobal id -> print_string "global "; Ident.print id
|
|
|
|
| Psetglobal id -> print_string "setglobal "; Ident.print id
|
1995-11-09 05:22:16 -08:00
|
|
|
| Pmakeblock(tag, Immutable) -> print_string "makeblock "; print_int tag
|
|
|
|
| Pmakeblock(tag, Mutable) -> print_string "makemutable "; print_int tag
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pfield n -> print_string "field "; print_int n
|
1995-07-10 02:48:27 -07:00
|
|
|
| Psetfield(n, _) -> print_string "setfield "; print_int n
|
1995-07-27 10:40:34 -07:00
|
|
|
| Pfloatfield n -> print_string "floatfield "; print_int n
|
|
|
|
| Psetfloatfield n -> print_string "setfloatfield "; print_int n
|
1995-07-25 04:38:42 -07:00
|
|
|
| Pccall p -> print_string p.prim_name
|
1995-05-04 03:15:53 -07:00
|
|
|
| Praise -> print_string "raise"
|
|
|
|
| Psequand -> print_string "&&"
|
|
|
|
| Psequor -> print_string "||"
|
|
|
|
| Pnot -> print_string "not"
|
|
|
|
| Pnegint -> print_string "~"
|
|
|
|
| Paddint -> print_string "+"
|
|
|
|
| Psubint -> print_string "-"
|
|
|
|
| Pmulint -> print_string "*"
|
|
|
|
| Pdivint -> print_string "/"
|
|
|
|
| Pmodint -> print_string "mod"
|
|
|
|
| Pandint -> print_string "and"
|
|
|
|
| Porint -> print_string "or"
|
|
|
|
| Pxorint -> print_string "xor"
|
|
|
|
| Plslint -> print_string "lsl"
|
|
|
|
| Plsrint -> print_string "lsr"
|
|
|
|
| Pasrint -> print_string "asr"
|
1995-06-18 07:44:56 -07:00
|
|
|
| Pintcomp(Ceq) -> print_string "=="
|
|
|
|
| Pintcomp(Cneq) -> print_string "!="
|
|
|
|
| Pintcomp(Clt) -> print_string "<"
|
|
|
|
| Pintcomp(Cle) -> print_string "<="
|
|
|
|
| Pintcomp(Cgt) -> print_string ">"
|
|
|
|
| Pintcomp(Cge) -> print_string ">="
|
1995-05-04 03:15:53 -07:00
|
|
|
| Poffsetint n -> print_int n; print_string "+"
|
|
|
|
| Poffsetref n -> print_int n; print_string "+:="
|
1995-07-11 01:53:14 -07:00
|
|
|
| Pintoffloat -> print_string "int_of_float"
|
|
|
|
| Pfloatofint -> print_string "float_of_int"
|
1995-06-18 07:44:56 -07:00
|
|
|
| Pnegfloat -> print_string "~."
|
1996-03-07 05:45:57 -08:00
|
|
|
| Pabsfloat -> print_string "abs."
|
1995-06-18 07:44:56 -07:00
|
|
|
| Paddfloat -> print_string "+."
|
|
|
|
| Psubfloat -> print_string "-."
|
|
|
|
| Pmulfloat -> print_string "*."
|
|
|
|
| Pdivfloat -> print_string "/."
|
|
|
|
| Pfloatcomp(Ceq) -> print_string "==."
|
|
|
|
| Pfloatcomp(Cneq) -> print_string "!=."
|
|
|
|
| Pfloatcomp(Clt) -> print_string "<."
|
|
|
|
| Pfloatcomp(Cle) -> print_string "<=."
|
|
|
|
| Pfloatcomp(Cgt) -> print_string ">."
|
|
|
|
| Pfloatcomp(Cge) -> print_string ">=."
|
1995-07-10 02:48:27 -07:00
|
|
|
| Pstringlength -> print_string "string.length"
|
1995-07-27 10:40:34 -07:00
|
|
|
| Pstringrefu -> print_string "string.unsafe_get"
|
|
|
|
| Pstringsetu -> print_string "string.unsafe_set"
|
|
|
|
| Pstringrefs -> print_string "string.get"
|
|
|
|
| Pstringsets -> print_string "string.set"
|
|
|
|
| Parraylength _ -> print_string "array.length"
|
|
|
|
| Pmakearray _ -> print_string "makearray "
|
|
|
|
| Parrayrefu _ -> print_string "array.unsafe_get"
|
|
|
|
| Parraysetu _ -> print_string "array.unsafe_set"
|
|
|
|
| Parrayrefs _ -> print_string "array.get"
|
|
|
|
| Parraysets _ -> print_string "array.set"
|
1996-04-04 07:55:29 -08:00
|
|
|
| Pbittest -> print_string "testbit"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let rec lambda = function
|
|
|
|
Lvar id ->
|
|
|
|
Ident.print id
|
|
|
|
| Lconst cst ->
|
|
|
|
structured_constant cst
|
|
|
|
| Lapply(lfun, largs) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(apply"; print_space();
|
|
|
|
lambda lfun;
|
|
|
|
List.iter (fun l -> print_space(); lambda l) largs;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
1995-12-19 02:19:12 -08:00
|
|
|
| Lfunction(params, body) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
open_hovbox 2;
|
1995-12-19 02:19:12 -08:00
|
|
|
print_string "(function";
|
|
|
|
List.iter (fun param -> print_space(); Ident.print param) params;
|
1995-05-04 03:15:53 -07:00
|
|
|
print_space(); lambda body; print_string ")"; close_box()
|
1995-12-15 02:18:29 -08:00
|
|
|
| Llet(str, id, arg, body) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(let"; print_space();
|
|
|
|
open_hvbox 1;
|
|
|
|
print_string "(";
|
|
|
|
open_hovbox 2; Ident.print id; print_space(); lambda arg; close_box();
|
|
|
|
letbody body;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Lletrec(id_arg_list, body) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(letrec"; print_space();
|
|
|
|
print_string "(";
|
1995-12-15 02:18:29 -08:00
|
|
|
open_hvbox 1;
|
1995-05-04 03:15:53 -07:00
|
|
|
let spc = ref false in
|
|
|
|
List.iter
|
1995-07-02 09:45:21 -07:00
|
|
|
(fun (id, l) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
if !spc then print_space() else spc := true;
|
1995-12-15 02:18:29 -08:00
|
|
|
open_hovbox 2;
|
|
|
|
Ident.print id; print_space(); lambda l;
|
|
|
|
close_box())
|
1995-05-04 03:15:53 -07:00
|
|
|
id_arg_list;
|
|
|
|
close_box();
|
|
|
|
print_string ")";
|
|
|
|
print_space(); lambda body;
|
|
|
|
print_string ")"; close_box()
|
|
|
|
| Lprim(prim, largs) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "("; primitive prim;
|
|
|
|
List.iter (fun l -> print_space(); lambda l) largs;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
1996-04-04 07:55:29 -08:00
|
|
|
| Lswitch(larg, sw) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
open_hovbox 1;
|
1996-04-04 07:55:29 -08:00
|
|
|
print_string (if sw.sw_checked then "(switch-checked " else "(switch ");
|
|
|
|
lambda larg; print_space();
|
1995-05-04 03:15:53 -07:00
|
|
|
open_vbox 0;
|
|
|
|
let spc = ref false in
|
|
|
|
List.iter
|
|
|
|
(fun (n, l) ->
|
1995-06-18 07:44:56 -07:00
|
|
|
if !spc then print_space() else spc := true;
|
|
|
|
open_hvbox 1;
|
|
|
|
print_string "case int "; print_int n;
|
|
|
|
print_string ":"; print_space();
|
|
|
|
lambda l;
|
|
|
|
close_box())
|
1996-04-04 07:55:29 -08:00
|
|
|
sw.sw_consts;
|
1995-06-18 07:44:56 -07:00
|
|
|
List.iter
|
|
|
|
(fun (n, l) ->
|
|
|
|
if !spc then print_space() else spc := true;
|
1995-05-04 03:15:53 -07:00
|
|
|
open_hvbox 1;
|
1995-06-18 07:44:56 -07:00
|
|
|
print_string "case tag "; print_int n;
|
|
|
|
print_string ":"; print_space();
|
1995-05-04 03:15:53 -07:00
|
|
|
lambda l;
|
1995-06-18 07:44:56 -07:00
|
|
|
close_box())
|
1996-04-04 07:55:29 -08:00
|
|
|
sw.sw_blocks;
|
1995-05-04 03:15:53 -07:00
|
|
|
print_string ")"; close_box(); close_box()
|
|
|
|
| Lstaticfail ->
|
|
|
|
print_string "exit"
|
|
|
|
| Lcatch(lbody, lhandler) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(catch"; print_space();
|
1995-07-07 05:09:01 -07:00
|
|
|
lambda lbody; print_break 1 (-1);
|
1995-05-04 03:15:53 -07:00
|
|
|
print_string "with"; print_space(); lambda lhandler;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Ltrywith(lbody, param, lhandler) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(try"; print_space();
|
1995-07-07 05:09:01 -07:00
|
|
|
lambda lbody; print_break 1 (-1);
|
1995-05-04 03:15:53 -07:00
|
|
|
print_string "with "; Ident.print param; print_space();
|
|
|
|
lambda lhandler;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Lifthenelse(lcond, lif, lelse) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(if"; print_space();
|
|
|
|
lambda lcond; print_space();
|
|
|
|
lambda lif; print_space();
|
|
|
|
lambda lelse; print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Lsequence(l1, l2) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(seq"; print_space();
|
|
|
|
lambda l1; print_space(); sequence l2; print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Lwhile(lcond, lbody) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(while"; print_space();
|
|
|
|
lambda lcond; print_space();
|
|
|
|
lambda lbody; print_string ")";
|
|
|
|
close_box()
|
|
|
|
| Lfor(param, lo, hi, dir, body) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(for "; Ident.print param; print_space();
|
|
|
|
lambda lo; print_space();
|
|
|
|
print_string(match dir with Upto -> "to" | Downto -> "downto");
|
|
|
|
print_space();
|
|
|
|
lambda hi; print_space();
|
|
|
|
lambda body; print_string ")";
|
|
|
|
close_box()
|
1995-11-25 07:38:43 -08:00
|
|
|
| Lassign(id, expr) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(assign"; print_space();
|
|
|
|
Ident.print id; print_space();
|
|
|
|
lambda expr; print_string ")";
|
|
|
|
close_box()
|
1996-04-22 04:15:41 -07:00
|
|
|
| Lsend (met, obj, largs) ->
|
|
|
|
open_hovbox 2;
|
|
|
|
print_string "(send"; print_space();
|
|
|
|
lambda obj; print_space();
|
|
|
|
lambda met;
|
|
|
|
List.iter (fun l -> print_space(); lambda l) largs;
|
|
|
|
print_string ")";
|
|
|
|
close_box()
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and sequence = function
|
|
|
|
Lsequence(l1, l2) ->
|
|
|
|
sequence l1; print_space(); sequence l2
|
|
|
|
| l ->
|
|
|
|
lambda l
|
|
|
|
|
|
|
|
and letbody = function
|
1995-12-15 02:18:29 -08:00
|
|
|
Llet(str, id, arg, body) ->
|
1995-05-04 03:15:53 -07:00
|
|
|
print_space();
|
|
|
|
open_hovbox 2; Ident.print id; print_space(); lambda arg;
|
|
|
|
close_box();
|
|
|
|
letbody body
|
|
|
|
| l ->
|
|
|
|
print_string ")";
|
|
|
|
close_box();
|
|
|
|
print_space();
|
|
|
|
lambda l
|