50 let |
50 let |
51 val {intros, graph, eqns} = CodegenData.get thy; |
51 val {intros, graph, eqns} = CodegenData.get thy; |
52 fun thyname_of s = (case optmod of |
52 fun thyname_of s = (case optmod of |
53 NONE => Codegen.thyname_of_const thy s | SOME s => s); |
53 NONE => Codegen.thyname_of_const thy s | SOME s => s); |
54 in (case Option.map strip_comb (try HOLogic.dest_Trueprop (concl_of thm)) of |
54 in (case Option.map strip_comb (try HOLogic.dest_Trueprop (concl_of thm)) of |
55 SOME (Const (@{const_name "op ="}, _), [t, _]) => |
55 SOME (Const (@{const_name HOL.eq}, _), [t, _]) => |
56 (case head_of t of |
56 (case head_of t of |
57 Const (s, _) => |
57 Const (s, _) => |
58 CodegenData.put {intros = intros, graph = graph, |
58 CodegenData.put {intros = intros, graph = graph, |
59 eqns = eqns |> Symtab.map_default (s, []) |
59 eqns = eqns |> Symtab.map_default (s, []) |
60 (AList.update Thm.eq_thm_prop (thm, thyname_of s))} thy |
60 (AList.update Thm.eq_thm_prop (thm, thyname_of s))} thy |
186 (iss ~~ args1))) |
186 (iss ~~ args1))) |
187 end |
187 end |
188 end)) (AList.lookup op = modes name) |
188 end)) (AList.lookup op = modes name) |
189 |
189 |
190 in (case strip_comb t of |
190 in (case strip_comb t of |
191 (Const (@{const_name "op ="}, Type (_, [T, _])), _) => |
191 (Const (@{const_name HOL.eq}, Type (_, [T, _])), _) => |
192 [Mode ((([], [1]), false), [1], []), Mode ((([], [2]), false), [2], [])] @ |
192 [Mode ((([], [1]), false), [1], []), Mode ((([], [2]), false), [2], [])] @ |
193 (if is_eqT T then [Mode ((([], [1, 2]), false), [1, 2], [])] else []) |
193 (if is_eqT T then [Mode ((([], [1, 2]), false), [1, 2], [])] else []) |
194 | (Const (name, _), args) => the_default default (mk_modes name args) |
194 | (Const (name, _), args) => the_default default (mk_modes name args) |
195 | (Var ((name, _), _), args) => the (mk_modes name args) |
195 | (Var ((name, _), _), args) => the (mk_modes name args) |
196 | (Free (name, _), args) => the (mk_modes name args) |
196 | (Free (name, _), args) => the (mk_modes name args) |
342 [Pretty.brk 1, str "| _ => DSeq.empty)"] |
342 [Pretty.brk 1, str "| _ => DSeq.empty)"] |
343 else [str ")"]))) |
343 else [str ")"]))) |
344 end; |
344 end; |
345 |
345 |
346 fun modename module s (iss, is) gr = |
346 fun modename module s (iss, is) gr = |
347 let val (id, gr') = if s = @{const_name "op ="} then (("", "equal"), gr) |
347 let val (id, gr') = if s = @{const_name HOL.eq} then (("", "equal"), gr) |
348 else mk_const_id module s gr |
348 else mk_const_id module s gr |
349 in (space_implode "__" |
349 in (space_implode "__" |
350 (mk_qual_id module id :: |
350 (mk_qual_id module id :: |
351 map (space_implode "_" o map string_of_int) (map_filter I iss @ [is])), gr') |
351 map (space_implode "_" o map string_of_int) (map_filter I iss @ [is])), gr') |
352 end; |
352 end; |
361 | compile_expr _ _ _ _ _ _ (SOME _, Var ((name, _), _)) gr = |
361 | compile_expr _ _ _ _ _ _ (SOME _, Var ((name, _), _)) gr = |
362 ([str name], gr) |
362 ([str name], gr) |
363 | compile_expr thy defs dep module brack modes (SOME (Mode ((mode, _), _, ms)), t) gr = |
363 | compile_expr thy defs dep module brack modes (SOME (Mode ((mode, _), _, ms)), t) gr = |
364 (case strip_comb t of |
364 (case strip_comb t of |
365 (Const (name, _), args) => |
365 (Const (name, _), args) => |
366 if name = @{const_name "op ="} orelse AList.defined op = modes name then |
366 if name = @{const_name HOL.eq} orelse AList.defined op = modes name then |
367 let |
367 let |
368 val (args1, args2) = chop (length ms) args; |
368 val (args1, args2) = chop (length ms) args; |
369 val ((ps, mode_id), gr') = gr |> fold_map |
369 val ((ps, mode_id), gr') = gr |> fold_map |
370 (compile_expr thy defs dep module true modes) (ms ~~ args1) |
370 (compile_expr thy defs dep module true modes) (ms ~~ args1) |
371 ||>> modename module name mode; |
371 ||>> modename module name mode; |
579 fun get_nparms s = if member (op =) names s then SOME nparms else |
579 fun get_nparms s = if member (op =) names s then SOME nparms else |
580 Option.map #3 (get_clauses thy s); |
580 Option.map #3 (get_clauses thy s); |
581 |
581 |
582 fun dest_prem (_ $ (Const (@{const_name Set.member}, _) $ t $ u)) = |
582 fun dest_prem (_ $ (Const (@{const_name Set.member}, _) $ t $ u)) = |
583 Prem ([t], Envir.beta_eta_contract u, true) |
583 Prem ([t], Envir.beta_eta_contract u, true) |
584 | dest_prem (_ $ ((eq as Const (@{const_name "op ="}, _)) $ t $ u)) = |
584 | dest_prem (_ $ ((eq as Const (@{const_name HOL.eq}, _)) $ t $ u)) = |
585 Prem ([t, u], eq, false) |
585 Prem ([t, u], eq, false) |
586 | dest_prem (_ $ t) = |
586 | dest_prem (_ $ t) = |
587 (case strip_comb t of |
587 (case strip_comb t of |
588 (v as Var _, ts) => if member (op =) args v then Prem (ts, v, false) else Sidecond t |
588 (v as Var _, ts) => if member (op =) args v then Prem (ts, v, false) else Sidecond t |
589 | (c as Const (s, _), ts) => |
589 | (c as Const (s, _), ts) => |