src/Pure/Tools/codegen_thingol.ML
changeset 18812 a4554848b59e
parent 18756 5eb3df798405
child 18850 92ef83e5eaea
equal deleted inserted replaced
18811:15f9fe3064ef 18812:a4554848b59e
   315 
   315 
   316 
   316 
   317 (* simple diagnosis *)
   317 (* simple diagnosis *)
   318 
   318 
   319 fun pretty_itype (IType (tyco, tys)) =
   319 fun pretty_itype (IType (tyco, tys)) =
   320       Pretty.gen_list "" "(" ")" (Pretty.str tyco :: map pretty_itype tys)
   320       Pretty.enum "" "(" ")" (Pretty.str tyco :: map pretty_itype tys)
   321   | pretty_itype (IFun (ty1, ty2)) =
   321   | pretty_itype (IFun (ty1, ty2)) =
   322       Pretty.gen_list "" "(" ")" [pretty_itype ty1, Pretty.str "->", pretty_itype ty2]
   322       Pretty.enum "" "(" ")" [pretty_itype ty1, Pretty.str "->", pretty_itype ty2]
   323   | pretty_itype (IVarT (v, sort)) =
   323   | pretty_itype (IVarT (v, sort)) =
   324       Pretty.str (v ^ enclose "|" "|" (space_implode "|" sort))
   324       Pretty.str (v ^ enclose "|" "|" (space_implode "|" sort))
   325   | pretty_itype (IDictT _) =
   325   | pretty_itype (IDictT _) =
   326       Pretty.str "<DictT>";
   326       Pretty.str "<DictT>";
   327 
   327 
   328 fun pretty_ipat (ICons ((cons, ps), ty)) =
   328 fun pretty_ipat (ICons ((cons, ps), ty)) =
   329       Pretty.gen_list " " "(" ")"
   329       Pretty.enum " " "(" ")"
   330         (Pretty.str cons :: map pretty_ipat ps @ [Pretty.str ":: ", pretty_itype ty])
   330         (Pretty.str cons :: map pretty_ipat ps @ [Pretty.str ":: ", pretty_itype ty])
   331   | pretty_ipat (IVarP (v, ty)) =
   331   | pretty_ipat (IVarP (v, ty)) =
   332       Pretty.block [Pretty.str ("?" ^ v ^ "::"), pretty_itype ty];
   332       Pretty.block [Pretty.str ("?" ^ v ^ "::"), pretty_itype ty];
   333 
   333 
   334 fun pretty_iexpr (IConst (f, ty)) =
   334 fun pretty_iexpr (IConst (f, ty)) =
   477 fun pretty_def Undef =
   477 fun pretty_def Undef =
   478       Pretty.str "<UNDEF>"
   478       Pretty.str "<UNDEF>"
   479   | pretty_def (Prim prims) =
   479   | pretty_def (Prim prims) =
   480       Pretty.str ("<PRIM " ^ (commas o map fst) prims ^ ">")
   480       Pretty.str ("<PRIM " ^ (commas o map fst) prims ^ ">")
   481   | pretty_def (Fun (eqs, (_, ty))) =
   481   | pretty_def (Fun (eqs, (_, ty))) =
   482       Pretty.gen_list " |" "" "" (
   482       Pretty.enum " |" "" "" (
   483         map (fn (ps, body) =>
   483         map (fn (ps, body) =>
   484           Pretty.block [
   484           Pretty.block [
   485             Pretty.gen_list "," "[" "]" (map pretty_ipat ps),
   485             Pretty.enum "," "[" "]" (map pretty_ipat ps),
   486             Pretty.str " |->",
   486             Pretty.str " |->",
   487             Pretty.brk 1,
   487             Pretty.brk 1,
   488             pretty_iexpr body,
   488             pretty_iexpr body,
   489             Pretty.str "::",
   489             Pretty.str "::",
   490             pretty_itype ty
   490             pretty_itype ty
   498       ]
   498       ]
   499   | pretty_def (Datatype ((vs, cs), insts)) =
   499   | pretty_def (Datatype ((vs, cs), insts)) =
   500       Pretty.block [
   500       Pretty.block [
   501         Pretty.list "(" ")" (map (pretty_itype o IVarT) vs),
   501         Pretty.list "(" ")" (map (pretty_itype o IVarT) vs),
   502         Pretty.str " |=> ",
   502         Pretty.str " |=> ",
   503         Pretty.gen_list " |" "" ""
   503         Pretty.enum " |" "" ""
   504           (map (fn (c, tys) => (Pretty.block o Pretty.breaks) (Pretty.str c :: map pretty_itype tys)) cs),
   504           (map (fn (c, tys) => (Pretty.block o Pretty.breaks) (Pretty.str c :: map pretty_itype tys)) cs),
   505         Pretty.str ", instances ",
   505         Pretty.str ", instances ",
   506         Pretty.gen_list "," "[" "]" (map Pretty.str insts)
   506         Pretty.enum "," "[" "]" (map Pretty.str insts)
   507       ]
   507       ]
   508   | pretty_def (Datatypecons dtname) =
   508   | pretty_def (Datatypecons dtname) =
   509       Pretty.str ("cons " ^ dtname)
   509       Pretty.str ("cons " ^ dtname)
   510   | pretty_def (Class ((supcls, (v, mems)), insts)) =
   510   | pretty_def (Class ((supcls, (v, mems)), insts)) =
   511       Pretty.block [
   511       Pretty.block [
   512         Pretty.str ("class var " ^ v ^ "extending "),
   512         Pretty.str ("class var " ^ v ^ "extending "),
   513         Pretty.gen_list "," "[" "]" (map Pretty.str supcls),
   513         Pretty.enum "," "[" "]" (map Pretty.str supcls),
   514         Pretty.str " with ",
   514         Pretty.str " with ",
   515         Pretty.gen_list "," "[" "]"
   515         Pretty.enum "," "[" "]"
   516           (map (fn (m, (_, ty)) => Pretty.block [Pretty.str (m ^ "::"), pretty_itype ty]) mems),
   516           (map (fn (m, (_, ty)) => Pretty.block [Pretty.str (m ^ "::"), pretty_itype ty]) mems),
   517         Pretty.str " instances ",
   517         Pretty.str " instances ",
   518         Pretty.gen_list "," "[" "]" (map Pretty.str insts)
   518         Pretty.enum "," "[" "]" (map Pretty.str insts)
   519       ]
   519       ]
   520   | pretty_def (Classmember clsname) =
   520   | pretty_def (Classmember clsname) =
   521       Pretty.block [
   521       Pretty.block [
   522         Pretty.str "class member belonging to ",
   522         Pretty.str "class member belonging to ",
   523         Pretty.str clsname
   523         Pretty.str clsname
   527         Pretty.str "class instance (",
   527         Pretty.str "class instance (",
   528         Pretty.str clsname,
   528         Pretty.str clsname,
   529         Pretty.str ", (",
   529         Pretty.str ", (",
   530         Pretty.str tyco,
   530         Pretty.str tyco,
   531         Pretty.str ", ",
   531         Pretty.str ", ",
   532         Pretty.gen_list "," "[" "]" (map (Pretty.gen_list "," "{" "}" o map Pretty.str o snd) arity),
   532         Pretty.enum "," "[" "]" (map (Pretty.enum "," "{" "}" o map Pretty.str o snd) arity),
   533         Pretty.str "))"
   533         Pretty.str "))"
   534       ];
   534       ];
   535 
   535 
   536 fun pretty_module modl =
   536 fun pretty_module modl =
   537   let
   537   let