1692 | names => error ("No defining equations for " |
1692 | names => error ("No defining equations for " |
1693 ^ commas (map (CodeName.labelled_name thy) names)); |
1693 ^ commas (map (CodeName.labelled_name thy) names)); |
1694 in |
1694 in |
1695 project |
1695 project |
1696 #> check_empty_funs |
1696 #> check_empty_funs |
1697 #> seri module file args (CodeName.labelled_name thy) reserved includes (Symtab.lookup alias) |
1697 #> seri module file args (CodeName.labelled_name thy) reserved includes |
1698 (Symtab.lookup class) (Symtab.lookup tyco) (Symtab.lookup const) |
1698 (Symtab.lookup alias) (Symtab.lookup class) (Symtab.lookup tyco) (Symtab.lookup const) |
1699 end; |
1699 end; |
1700 |
1700 |
1701 fun eval_invoke thy (ref_name, reff) code (t, ty) args = |
1701 fun eval_invoke thy (ref_name, reff) code (t, ty) args = |
1702 let |
1702 let |
1703 val _ = if CodeThingol.contains_dictvar t then |
1703 val _ = if CodeThingol.contains_dictvar t then |
1704 error "Term to be evaluated constains free dictionaries" else (); |
1704 error "Term to be evaluated constains free dictionaries" else (); |
1705 val val_args = space_implode " " |
1705 val val_args = space_implode " " |
1706 (NameSpace.qualifier CodeName.value_name :: map (enclose "(" ")") args); |
1706 (NameSpace.qualifier CodeName.value_name :: map (enclose "(" ")") args); |
1707 val seri = get_serializer thy "SML" false (SOME "Isabelle_Eval") NONE []; |
1707 val seri = get_serializer thy "SML" false (SOME "Isabelle_Eval") NONE []; |
1708 fun eval code = ( |
1708 val code' = CodeThingol.add_value_stmt (t, ty) code; |
|
1709 fun eval () = ( |
1709 reff := NONE; |
1710 reff := NONE; |
1710 seri (SOME [CodeName.value_name]) code; |
1711 seri (SOME [CodeName.value_name]) code'; |
1711 use_text "generated code for evaluation" Output.ml_output (!eval_verbose) |
1712 use_text "generated code for evaluation" Output.ml_output (!eval_verbose) |
1712 ("val _ = (" ^ ref_name ^ " := SOME (fn () => " ^ val_args ^ "))"); |
1713 ("val _ = (" ^ ref_name ^ " := SOME (fn () => " ^ val_args ^ "))"); |
1713 case !reff |
1714 case !reff |
1714 of NONE => error ("Could not retrieve value of ML reference " ^ quote ref_name |
1715 of NONE => error ("Could not retrieve value of ML reference " ^ quote ref_name |
1715 ^ " (reference probably has been shadowed)") |
1716 ^ " (reference probably has been shadowed)") |
1716 | SOME f => f () |
1717 | SOME f => f |
1717 ); |
1718 ); |
1718 in |
1719 in CRITICAL eval () end; |
1719 code |
|
1720 |> CodeThingol.add_value_stmt (t, ty) |
|
1721 |> eval |
|
1722 end; |
|
1723 |
1720 |
1724 |
1721 |
1725 |
1722 |
1726 (** optional pretty serialization **) |
1723 (** optional pretty serialization **) |
1727 |
1724 |