18 val code_pred_cmd : string -> Proof.context -> Proof.state |
18 val code_pred_cmd : string -> Proof.context -> Proof.state |
19 val print_alternative_rules : theory -> theory |
19 val print_alternative_rules : theory -> theory |
20 val do_proofs: bool ref |
20 val do_proofs: bool ref |
21 val pred_intros : theory -> string -> thm list |
21 val pred_intros : theory -> string -> thm list |
22 val get_nparams : theory -> string -> int |
22 val get_nparams : theory -> string -> int |
|
23 val pred_term_of : theory -> term -> term option |
23 end; |
24 end; |
24 |
25 |
25 structure Predicate_Compile: PREDICATE_COMPILE = |
26 structure Predicate_Compile: PREDICATE_COMPILE = |
26 struct |
27 struct |
27 |
28 |
1393 end; |
1394 end; |
1394 |
1395 |
1395 val code_pred = generic_code_pred (K I); |
1396 val code_pred = generic_code_pred (K I); |
1396 val code_pred_cmd = generic_code_pred Code_Unit.read_const |
1397 val code_pred_cmd = generic_code_pred Code_Unit.read_const |
1397 |
1398 |
|
1399 (* transformation for code generation *) |
|
1400 |
|
1401 fun pred_term_of thy t = let |
|
1402 val (vars, body) = strip_abs t |
|
1403 val (pred, all_args) = strip_comb body |
|
1404 val (name, T) = dest_Const pred |
|
1405 val (params, args) = chop (get_nparams thy name) all_args |
|
1406 val user_mode = flat (map_index |
|
1407 (fn (i, t) => case t of Bound j => if j < length vars then [] else [i+1] | _ => [i+1]) |
|
1408 args) |
|
1409 val (inargs, _) = get_args user_mode args |
|
1410 val all_modes = Symtab.dest (#modes (IndCodegenData.get thy)) |
|
1411 val modes = filter (fn Mode (_, is, _) => is = user_mode) (modes_of all_modes (list_comb (pred, params))) |
|
1412 fun compile m = list_comb (compile_expr thy all_modes (SOME m, list_comb (pred, params)), inargs) |
|
1413 in |
|
1414 case modes of |
|
1415 [] => (let val _ = error "No mode possible for this term" in NONE end) |
|
1416 | [m] => SOME (compile m) |
|
1417 | ms => (let val _ = warning "Multiple modes possible for this term" |
|
1418 in SOME (compile (hd ms)) end) |
|
1419 end; |
|
1420 |
1398 end; |
1421 end; |
1399 |
1422 |
1400 fun pred_compile name thy = Predicate_Compile.create_def_equation |
1423 fun pred_compile name thy = Predicate_Compile.create_def_equation |
1401 (Sign.intern_const thy name) thy; |
1424 (Sign.intern_const thy name) thy; |
|
1425 |