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 *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1999-11-08 09:06:33 -08:00
|
|
|
open Formatmsg
|
1995-05-04 03:15:53 -07:00
|
|
|
open Asttypes
|
1995-07-27 10:40:34 -07:00
|
|
|
open Primitive
|
1996-09-23 04:30:27 -07:00
|
|
|
open Types
|
1995-05-04 03:15:53 -07:00
|
|
|
open Lambda
|
|
|
|
|
|
|
|
|
2000-02-08 12:00:06 -08:00
|
|
|
let rec struct_const ppf = function
|
1995-05-04 03:15:53 -07:00
|
|
|
Const_base(Const_int n) -> print_int n
|
|
|
|
| Const_base(Const_char c) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "'%s'" (Char.escaped c)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Const_base(Const_string s) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "\"%s\"" (String.escaped s)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Const_base(Const_float s) ->
|
|
|
|
print_string s
|
2000-02-08 12:00:06 -08:00
|
|
|
| Const_pointer n -> printf "%ia" n
|
1995-05-04 03:15:53 -07:00
|
|
|
| Const_block(tag, []) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "[%i]" tag
|
1995-05-04 03:15:53 -07:00
|
|
|
| Const_block(tag, sc1::scl) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let sconsts ppf scl =
|
|
|
|
List.iter (fun sc -> printf "@ %a" struct_const sc) scl in
|
|
|
|
printf "@[<1>[%i:@ @[%a%a@]]@]" tag struct_const sc1 sconsts scl
|
1995-07-27 10:40:34 -07:00
|
|
|
| Const_float_array [] ->
|
|
|
|
print_string "[| |]"
|
|
|
|
| Const_float_array (f1 :: fl) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let floats ppf fl =
|
|
|
|
List.iter (fun f -> print_space(); print_string f) fl in
|
|
|
|
printf "@[<1[|@[%s%a@]|]@]" f1 floats fl
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2000-02-08 12:00:06 -08:00
|
|
|
let print_id ppf id = Ident.print id
|
|
|
|
|
|
|
|
let primitive ppf = function
|
1995-05-04 03:15:53 -07:00
|
|
|
Pidentity -> print_string "id"
|
1999-02-24 07:21:50 -08:00
|
|
|
| Pignore -> print_string "ignore"
|
2000-02-08 12:00:06 -08:00
|
|
|
| Pgetglobal id -> printf "global %a" print_id id
|
|
|
|
| Psetglobal id -> printf "setglobal %a" print_id id
|
|
|
|
| Pmakeblock(tag, Immutable) -> printf "makeblock %i" tag
|
|
|
|
| Pmakeblock(tag, Mutable) -> printf "makemutable %i" tag
|
|
|
|
| Pfield n -> printf "field %i" n
|
1998-06-09 06:40:55 -07:00
|
|
|
| Psetfield(n, ptr) ->
|
|
|
|
print_string (if ptr then "setfield_ptr " else "setfield_imm ");
|
|
|
|
print_int n
|
2000-02-08 12:00:06 -08:00
|
|
|
| Pfloatfield n -> printf "floatfield %i" n
|
|
|
|
| Psetfloatfield n -> printf "setfloatfield %i" 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"
|
1999-12-06 08:59:24 -08:00
|
|
|
| Pisint -> print_string "isint"
|
1996-04-04 07:55:29 -08:00
|
|
|
| Pbittest -> print_string "testbit"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2000-02-08 12:00:06 -08:00
|
|
|
let rec lam ppf = function
|
1995-05-04 03:15:53 -07:00
|
|
|
Lvar id ->
|
2000-02-08 12:00:06 -08:00
|
|
|
print_id ppf id
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lconst cst ->
|
2000-02-08 12:00:06 -08:00
|
|
|
struct_const ppf cst
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lapply(lfun, largs) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let lams ppf largs =
|
|
|
|
List.iter (fun l -> printf "@ %a" lam l) largs in
|
|
|
|
printf "@[<2>(apply@ %a%a)@]" lam lfun lams largs
|
1996-10-22 06:36:59 -07:00
|
|
|
| Lfunction(kind, params, body) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let pr_params ppf params =
|
|
|
|
match kind with
|
|
|
|
| Curried ->
|
|
|
|
List.iter (fun param -> printf "@ %a" print_id param) params
|
|
|
|
| Tupled ->
|
|
|
|
print_string " (";
|
|
|
|
let first = ref true in
|
|
|
|
List.iter
|
|
|
|
(fun param ->
|
|
|
|
if !first then first := false else printf ",@ ";
|
|
|
|
print_id ppf param)
|
|
|
|
params;
|
|
|
|
print_string ")" in
|
|
|
|
printf "@[<2>(function%a@ %a)@]" pr_params params lam body
|
1995-12-15 02:18:29 -08:00
|
|
|
| Llet(str, id, arg, body) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let rec letbody = function
|
|
|
|
| Llet(str, id, arg, body) ->
|
|
|
|
printf "@ @[<2>%a@ %a@]" print_id id lam arg;
|
|
|
|
letbody body
|
|
|
|
| expr -> expr in
|
|
|
|
printf "@[<2>(let@ @[<hv 1>(@[<2>%a@ %a@]" print_id id lam arg;
|
|
|
|
let expr = letbody body in
|
|
|
|
printf ")@]@ %a)@]" lam expr
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lletrec(id_arg_list, body) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let bindings ppf id_arg_list =
|
|
|
|
let spc = ref false in
|
|
|
|
List.iter
|
|
|
|
(fun (id, l) ->
|
|
|
|
if !spc then print_space() else spc := true;
|
|
|
|
printf "@[<2>%a@ %a@]" print_id id lam l)
|
|
|
|
id_arg_list in
|
|
|
|
printf "@[<2>(letrec@ (@[<hv 1>%a@])@ %a)@]" bindings id_arg_list lam body
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lprim(prim, largs) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let lams ppf largs =
|
|
|
|
List.iter (fun l -> printf "@ %a" lam l) largs in
|
|
|
|
printf "@[<2>(%a%a)@]" primitive prim lams largs
|
1996-04-04 07:55:29 -08:00
|
|
|
| Lswitch(larg, sw) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let switch ppf sw =
|
|
|
|
let spc = ref false in
|
|
|
|
List.iter
|
|
|
|
(fun (n, l) ->
|
|
|
|
if !spc then print_space() else spc := true;
|
|
|
|
printf "@[<hv 1>case int %i:@ %a@]" n lam l)
|
|
|
|
sw.sw_consts;
|
|
|
|
List.iter
|
|
|
|
(fun (n, l) ->
|
|
|
|
if !spc then print_space() else spc := true;
|
|
|
|
printf "@[<hv 1>case tag %i:@ %a@]" n lam l)
|
|
|
|
sw.sw_blocks in
|
|
|
|
printf
|
|
|
|
"@[<1>(%s%a@ @[<v 0>%a@])@]"
|
|
|
|
(if sw.sw_checked then "switch-checked " else "switch ")
|
|
|
|
lam larg switch sw
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lstaticfail ->
|
|
|
|
print_string "exit"
|
|
|
|
| Lcatch(lbody, lhandler) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(catch@ %a@;<1 -1>with@ %a)@]" lam lbody lam lhandler
|
1995-05-04 03:15:53 -07:00
|
|
|
| Ltrywith(lbody, param, lhandler) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(try@ %a@;<1 -1>with %a@ %a)@]"
|
|
|
|
lam lbody print_id param lam lhandler
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lifthenelse(lcond, lif, lelse) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(if@ %a@ %a@ %a)@]" lam lcond lam lif lam lelse
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lsequence(l1, l2) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(seq@ %a@ %a)@]" lam l1 sequence l2
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lwhile(lcond, lbody) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(while@ %a@ %a)@]" lam lcond lam lbody
|
1995-05-04 03:15:53 -07:00
|
|
|
| Lfor(param, lo, hi, dir, body) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(for %a@ %a@ %s@ %a@ %a)@]"
|
|
|
|
print_id param lam lo
|
|
|
|
(match dir with Upto -> "to" | Downto -> "downto")
|
|
|
|
lam hi lam body
|
1995-11-25 07:38:43 -08:00
|
|
|
| Lassign(id, expr) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(assign@ %a@ %a)@]" print_id id lam expr
|
1996-04-22 04:15:41 -07:00
|
|
|
| Lsend (met, obj, largs) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
let args ppf largs =
|
|
|
|
List.iter (fun l -> printf "@ %a" lam l) largs in
|
|
|
|
printf "@[<2>(send@ %a@ %a%a)@]" lam obj lam met args largs
|
|
|
|
| Levent(expr, ev) ->
|
|
|
|
let kind =
|
|
|
|
match ev.lev_kind with
|
|
|
|
| Lev_before -> "before"
|
|
|
|
| Lev_after _ -> "after"
|
|
|
|
| Lev_function -> "funct-body" in
|
|
|
|
printf "@[<2>(%s %i@ %a)@]" kind ev.lev_loc lam expr
|
1998-06-24 12:22:26 -07:00
|
|
|
| Lifused(id, expr) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>(ifused@ %a@ %a)@]" print_id id lam expr
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2000-02-08 12:00:06 -08:00
|
|
|
and sequence ppf = function
|
1995-05-04 03:15:53 -07:00
|
|
|
Lsequence(l1, l2) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "%a@ %a" sequence l1 sequence l2
|
1997-04-11 06:55:39 -07:00
|
|
|
| Llet(str, id, arg, body) ->
|
2000-02-08 12:00:06 -08:00
|
|
|
printf "@[<2>let@ %a@ %a@]@ %a" print_id id lam arg sequence body
|
1995-05-04 03:15:53 -07:00
|
|
|
| l ->
|
2000-02-08 12:00:06 -08:00
|
|
|
lam ppf l
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2000-02-08 12:00:06 -08:00
|
|
|
let structured_constant cst = printf "%a" struct_const cst
|
|
|
|
|
|
|
|
let lambda l = printf "%a" lam l
|