src/Tools/Code/code_ml.ML
changeset 31934 004c9a18e699
parent 31889 fb2c8a687529
child 32123 8bac9ee4b28d
equal deleted inserted replaced
31933:cd6511035315 31934:004c9a18e699
   176       | pr_stmt (MLVal (name, (((vs, ty), t), (thm, _)))) =
   176       | pr_stmt (MLVal (name, (((vs, ty), t), (thm, _)))) =
   177           let
   177           let
   178             val consts = map_filter
   178             val consts = map_filter
   179               (fn c => if (is_some o syntax_const) c
   179               (fn c => if (is_some o syntax_const) c
   180                 then NONE else (SOME o Long_Name.base_name o deresolve) c)
   180                 then NONE else (SOME o Long_Name.base_name o deresolve) c)
   181                 (Code_Thingol.fold_constnames (insert (op =)) t []);
   181                 (Code_Thingol.add_constnames t []);
   182             val vars = reserved_names
   182             val vars = reserved_names
   183               |> Code_Printer.intro_vars consts;
   183               |> Code_Printer.intro_vars consts;
   184           in
   184           in
   185             concat [
   185             concat [
   186               str "val",
   186               str "val",
   201                 fun pr_eq definer ((ts, t), (thm, _)) =
   201                 fun pr_eq definer ((ts, t), (thm, _)) =
   202                   let
   202                   let
   203                     val consts = map_filter
   203                     val consts = map_filter
   204                       (fn c => if (is_some o syntax_const) c
   204                       (fn c => if (is_some o syntax_const) c
   205                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   205                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   206                         ((fold o Code_Thingol.fold_constnames) (insert (op =)) (t :: ts) []);
   206                         (fold Code_Thingol.add_constnames (t :: ts) []);
   207                     val vars = reserved_names
   207                     val vars = reserved_names
   208                       |> Code_Printer.intro_vars consts
   208                       |> Code_Printer.intro_vars consts
   209                       |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_unbound_varnames)
   209                       |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_varnames)
   210                            (insert (op =)) ts []);
   210                            (insert (op =)) ts []);
   211                   in
   211                   in
   212                     concat (
   212                     concat (
   213                       str definer
   213                       str definer
   214                       :: (str o deresolve) name
   214                       :: (str o deresolve) name
   486       | pr_stmt (MLVal (name, (((vs, ty), t), (thm, _)))) =
   486       | pr_stmt (MLVal (name, (((vs, ty), t), (thm, _)))) =
   487           let
   487           let
   488             val consts = map_filter
   488             val consts = map_filter
   489               (fn c => if (is_some o syntax_const) c
   489               (fn c => if (is_some o syntax_const) c
   490                 then NONE else (SOME o Long_Name.base_name o deresolve) c)
   490                 then NONE else (SOME o Long_Name.base_name o deresolve) c)
   491                 (Code_Thingol.fold_constnames (insert (op =)) t []);
   491                 (Code_Thingol.add_constnames t []);
   492             val vars = reserved_names
   492             val vars = reserved_names
   493               |> Code_Printer.intro_vars consts;
   493               |> Code_Printer.intro_vars consts;
   494           in
   494           in
   495             concat [
   495             concat [
   496               str "let",
   496               str "let",
   506             fun pr_eq ((ts, t), (thm, _)) =
   506             fun pr_eq ((ts, t), (thm, _)) =
   507               let
   507               let
   508                 val consts = map_filter
   508                 val consts = map_filter
   509                   (fn c => if (is_some o syntax_const) c
   509                   (fn c => if (is_some o syntax_const) c
   510                     then NONE else (SOME o Long_Name.base_name o deresolve) c)
   510                     then NONE else (SOME o Long_Name.base_name o deresolve) c)
   511                     ((fold o Code_Thingol.fold_constnames) (insert (op =)) (t :: ts) []);
   511                     (fold Code_Thingol.add_constnames (t :: ts) []);
   512                 val vars = reserved_names
   512                 val vars = reserved_names
   513                   |> Code_Printer.intro_vars consts
   513                   |> Code_Printer.intro_vars consts
   514                   |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_unbound_varnames)
   514                   |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_varnames)
   515                       (insert (op =)) ts []);
   515                       (insert (op =)) ts []);
   516               in concat [
   516               in concat [
   517                 (Pretty.block o Pretty.commas)
   517                 (Pretty.block o Pretty.commas)
   518                   (map (pr_term (member (op =) pseudo_funs) thm vars NOBR) ts),
   518                   (map (pr_term (member (op =) pseudo_funs) thm vars NOBR) ts),
   519                 str "->",
   519                 str "->",
   522             fun pr_eqs is_pseudo [((ts, t), (thm, _))] =
   522             fun pr_eqs is_pseudo [((ts, t), (thm, _))] =
   523                   let
   523                   let
   524                     val consts = map_filter
   524                     val consts = map_filter
   525                       (fn c => if (is_some o syntax_const) c
   525                       (fn c => if (is_some o syntax_const) c
   526                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   526                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   527                         ((fold o Code_Thingol.fold_constnames) (insert (op =)) (t :: ts) []);
   527                         (fold Code_Thingol.add_constnames (t :: ts) []);
   528                     val vars = reserved_names
   528                     val vars = reserved_names
   529                       |> Code_Printer.intro_vars consts
   529                       |> Code_Printer.intro_vars consts
   530                       |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_unbound_varnames)
   530                       |> Code_Printer.intro_vars ((fold o Code_Thingol.fold_varnames)
   531                           (insert (op =)) ts []);
   531                           (insert (op =)) ts []);
   532                   in
   532                   in
   533                     concat (
   533                     concat (
   534                       (if is_pseudo then [str "()"]
   534                       (if is_pseudo then [str "()"]
   535                         else map (pr_term (member (op =) pseudo_funs) thm vars BR) ts)
   535                         else map (pr_term (member (op =) pseudo_funs) thm vars BR) ts)
   550               | pr_eqs _ (eqs as eq :: eqs') =
   550               | pr_eqs _ (eqs as eq :: eqs') =
   551                   let
   551                   let
   552                     val consts = map_filter
   552                     val consts = map_filter
   553                       (fn c => if (is_some o syntax_const) c
   553                       (fn c => if (is_some o syntax_const) c
   554                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   554                         then NONE else (SOME o Long_Name.base_name o deresolve) c)
   555                         ((fold o Code_Thingol.fold_constnames)
   555                         (fold Code_Thingol.add_constnames (map (snd o fst) eqs) []);
   556                           (insert (op =)) (map (snd o fst) eqs) []);
       
   557                     val vars = reserved_names
   556                     val vars = reserved_names
   558                       |> Code_Printer.intro_vars consts;
   557                       |> Code_Printer.intro_vars consts;
   559                     val dummy_parms = (map str o fish_params vars o map (fst o fst)) eqs;
   558                     val dummy_parms = (map str o fish_params vars o map (fst o fst)) eqs;
   560                   in
   559                   in
   561                     Pretty.block (
   560                     Pretty.block (
   775       let
   774       let
   776         val eqs = filter (snd o snd) raw_eqs;
   775         val eqs = filter (snd o snd) raw_eqs;
   777         val (eqs', is_value) = if null (filter_out (null o snd) vs) then case eqs
   776         val (eqs', is_value) = if null (filter_out (null o snd) vs) then case eqs
   778          of [(([], t), thm)] => if (not o null o fst o Code_Thingol.unfold_fun) ty
   777          of [(([], t), thm)] => if (not o null o fst o Code_Thingol.unfold_fun) ty
   779             then ([(([IVar (SOME "x")], t `$ IVar (SOME "x")), thm)], false)
   778             then ([(([IVar (SOME "x")], t `$ IVar (SOME "x")), thm)], false)
   780             else (eqs, not (Code_Thingol.fold_constnames
   779             else (eqs, not (member (op =) (Code_Thingol.add_constnames t []) name))
   781               (fn name' => fn b => b orelse name = name') t false))
       
   782           | _ => (eqs, false)
   780           | _ => (eqs, false)
   783           else (eqs, false)
   781           else (eqs, false)
   784       in ((name, (tysm, eqs')), is_value) end;
   782       in ((name, (tysm, eqs')), is_value) end;
   785     fun check_kind [((name, (tysm, [(([], t), thm)])), true)] = MLVal (name, ((tysm, t), thm))
   783     fun check_kind [((name, (tysm, [(([], t), thm)])), true)] = MLVal (name, ((tysm, t), thm))
   786       | check_kind [((name, ((vs, ty), [])), _)] =
   784       | check_kind [((name, ((vs, ty), [])), _)] =