49 | tuplify print _ xs = SOME (enum "," "(" ")" (map (print NOBR) xs)); |
49 | tuplify print _ xs = SOME (enum "," "(" ")" (map (print NOBR) xs)); |
50 |
50 |
51 |
51 |
52 (** SML serializer **) |
52 (** SML serializer **) |
53 |
53 |
54 fun print_sml_stmt tyco_syntax const_syntax reserved is_cons deresolve = |
54 fun print_sml_stmt tyco_syntax const_syntax reserved is_constr deresolve = |
55 let |
55 let |
56 fun print_tyco_expr (tyco, []) = (str o deresolve) tyco |
56 fun print_tyco_expr (tyco, []) = (str o deresolve) tyco |
57 | print_tyco_expr (tyco, [ty]) = |
57 | print_tyco_expr (tyco, [ty]) = |
58 concat [print_typ BR ty, (str o deresolve) tyco] |
58 concat [print_typ BR ty, (str o deresolve) tyco] |
59 | print_tyco_expr (tyco, tys) = |
59 | print_tyco_expr (tyco, tys) = |
108 of SOME (app as ({ name = c, ... }, _)) => if is_none (const_syntax c) |
108 of SOME (app as ({ name = c, ... }, _)) => if is_none (const_syntax c) |
109 then print_case is_pseudo_fun some_thm vars fxy case_expr |
109 then print_case is_pseudo_fun some_thm vars fxy case_expr |
110 else print_app is_pseudo_fun some_thm vars fxy app |
110 else print_app is_pseudo_fun some_thm vars fxy app |
111 | NONE => print_case is_pseudo_fun some_thm vars fxy case_expr) |
111 | NONE => print_case is_pseudo_fun some_thm vars fxy case_expr) |
112 and print_app_expr is_pseudo_fun some_thm vars (app as ({ name = c, dicts = dss, dom = dom, ... }, ts)) = |
112 and print_app_expr is_pseudo_fun some_thm vars (app as ({ name = c, dicts = dss, dom = dom, ... }, ts)) = |
113 if is_cons c then |
113 if is_constr c then |
114 let val k = length dom in |
114 let val k = length dom in |
115 if k < 2 orelse length ts = k |
115 if k < 2 orelse length ts = k |
116 then (str o deresolve) c |
116 then (str o deresolve) c |
117 :: the_list (tuplify (print_term is_pseudo_fun some_thm vars) BR ts) |
117 :: the_list (tuplify (print_term is_pseudo_fun some_thm vars) BR ts) |
118 else [print_term is_pseudo_fun some_thm vars BR (Code_Thingol.eta_expand k app)] |
118 else [print_term is_pseudo_fun some_thm vars BR (Code_Thingol.eta_expand k app)] |
353 }; |
353 }; |
354 |
354 |
355 |
355 |
356 (** OCaml serializer **) |
356 (** OCaml serializer **) |
357 |
357 |
358 fun print_ocaml_stmt tyco_syntax const_syntax reserved is_cons deresolve = |
358 fun print_ocaml_stmt tyco_syntax const_syntax reserved is_constr deresolve = |
359 let |
359 let |
360 fun print_tyco_expr (tyco, []) = (str o deresolve) tyco |
360 fun print_tyco_expr (tyco, []) = (str o deresolve) tyco |
361 | print_tyco_expr (tyco, [ty]) = |
361 | print_tyco_expr (tyco, [ty]) = |
362 concat [print_typ BR ty, (str o deresolve) tyco] |
362 concat [print_typ BR ty, (str o deresolve) tyco] |
363 | print_tyco_expr (tyco, tys) = |
363 | print_tyco_expr (tyco, tys) = |
408 of SOME (app as ({ name = c, ... }, _)) => if is_none (const_syntax c) |
408 of SOME (app as ({ name = c, ... }, _)) => if is_none (const_syntax c) |
409 then print_case is_pseudo_fun some_thm vars fxy case_expr |
409 then print_case is_pseudo_fun some_thm vars fxy case_expr |
410 else print_app is_pseudo_fun some_thm vars fxy app |
410 else print_app is_pseudo_fun some_thm vars fxy app |
411 | NONE => print_case is_pseudo_fun some_thm vars fxy case_expr) |
411 | NONE => print_case is_pseudo_fun some_thm vars fxy case_expr) |
412 and print_app_expr is_pseudo_fun some_thm vars (app as ({ name = c, dicts = dss, dom = dom, ... }, ts)) = |
412 and print_app_expr is_pseudo_fun some_thm vars (app as ({ name = c, dicts = dss, dom = dom, ... }, ts)) = |
413 if is_cons c then |
413 if is_constr c then |
414 let val k = length dom in |
414 let val k = length dom in |
415 if length ts = k |
415 if length ts = k |
416 then (str o deresolve) c |
416 then (str o deresolve) c |
417 :: the_list (tuplify (print_term is_pseudo_fun some_thm vars) BR ts) |
417 :: the_list (tuplify (print_term is_pseudo_fun some_thm vars) BR ts) |
418 else [print_term is_pseudo_fun some_thm vars BR (Code_Thingol.eta_expand k app)] |
418 else [print_term is_pseudo_fun some_thm vars BR (Code_Thingol.eta_expand k app)] |
792 ml_program_of_program labelled_name (Name.make_context reserved_syms) module_alias program; |
792 ml_program_of_program labelled_name (Name.make_context reserved_syms) module_alias program; |
793 |
793 |
794 (* print statements *) |
794 (* print statements *) |
795 fun print_stmt prefix_fragments (_, stmt) = print_ml_stmt |
795 fun print_stmt prefix_fragments (_, stmt) = print_ml_stmt |
796 tyco_syntax const_syntax (make_vars reserved_syms) |
796 tyco_syntax const_syntax (make_vars reserved_syms) |
797 (Code_Thingol.is_cons program) (deresolver prefix_fragments) stmt |
797 (Code_Thingol.is_constr program) (deresolver prefix_fragments) stmt |
798 |> apfst SOME; |
798 |> apfst SOME; |
799 |
799 |
800 (* print modules *) |
800 (* print modules *) |
801 fun print_module _ base _ xs = |
801 fun print_module _ base _ xs = |
802 let |
802 let |