| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Genarg |
| 13 |
open Geninterp |
| 14 |
open Ltac2_plugin |
| 15 |
open Tac2ffi |
| 16 |
open Tac2expr |
| 17 |
open Proofview.Notations |
| 18 |
open Tac2externals |
| 19 |
|
| 20 |
let ltac2_ltac1_plugin = "rocq-runtime.plugins.ltac2_ltac1" |
| 21 |
|
| 22 |
let pname ?(plugin=ltac2_ltac1_plugin) s = { mltac_plugin = plugin; mltac_tactic = s } |
| 23 |
|
| 24 |
let define ?plugin s = define (pname ?plugin s) |
| 25 |
|
| 26 |
let val_tag wit = match val_tag wit with |
| 27 |
| Base t -> t |
| 28 |
| _ -> assert false |
| 29 |
|
| 30 |
let prj : type a. a Val.typ -> Val.t -> a option = fun t v -> |
| 31 |
let Val.Dyn (t', x) = v in |
| 32 |
match Val.eq t t' with |
| 33 |
| None -> None |
| 34 |
| Some Refl -> Some x |
| 35 |
|
| 36 |
let in_gen wit v = Val.Dyn (val_tag wit, v) |
| 37 |
|
| 38 |
let out_gen wit v = prj (val_tag wit) v |
| 39 |
|
| 40 |
let () = |
| 41 |
define "ltac1_of_intro_pattern" (Tac2stdlib.intro_pattern @-> ret Tac2quote_ltac1.ltac1) @@ fun v -> |
| 42 |
let v = Tac2tactics.mk_intro_pattern v in |
| 43 |
in_gen (topwit Ltac_plugin.Tacarg.wit_simple_intropattern) v |
| 44 |
|
| 45 |
let rec to_intro_pattern (v : Tactypes.intro_pattern) : Tac2types.intro_pattern = |
| 46 |
match v.CAst.v with |
| 47 |
| IntroForthcoming b -> IntroForthcoming b |
| 48 |
| IntroNaming pat -> IntroNaming (to_intro_pattern_naming pat) |
| 49 |
| IntroAction act -> IntroAction (to_intro_pattern_action act) |
| 50 |
|
| 51 |
|
| 52 |
and to_intro_pattern_naming : Namegen.intro_pattern_naming_expr -> Tac2types.intro_pattern_naming = function |
| 53 |
| IntroIdentifier id -> IntroIdentifier id |
| 54 |
| IntroFresh id -> IntroFresh id |
| 55 |
| IntroAnonymous -> IntroAnonymous |
| 56 |
|
| 57 |
and to_intro_pattern_action : Tactypes.delayed_open_constr Tactypes.intro_pattern_action_expr -> Tac2types.intro_pattern_action = function |
| 58 |
| IntroWildcard -> IntroWildcard |
| 59 |
| IntroOrAndPattern op -> IntroOrAndPattern (to_or_and_intro_pattern op) |
| 60 |
| IntroInjection inj -> IntroInjection (to_intro_patterns inj) |
| 61 |
| IntroApplyOn ({loc;v=c}, ipat) -> |
| 62 |
let c = |
| 63 |
let open Proofview in |
| 64 |
Goal.enter_one ~__LOC__ @@ fun gl -> |
| 65 |
let sigma, c = c (Goal.env gl) (Goal.sigma gl) in |
| 66 |
Proofview.Unsafe.tclEVARS sigma >>= fun () -> |
| 67 |
tclUNIT c |
| 68 |
in |
| 69 |
let c () = c in |
| 70 |
IntroApplyOn (c, to_intro_pattern ipat) |
| 71 |
| IntroRewrite b -> IntroRewrite b |
| 72 |
|
| 73 |
and to_or_and_intro_pattern : Tactypes.delayed_open_constr Tactypes.or_and_intro_pattern_expr -> Tac2types.or_and_intro_pattern = function |
| 74 |
| IntroOrPattern ill -> IntroOrPattern (List.map to_intro_patterns ill) |
| 75 |
| IntroAndPattern il -> IntroAndPattern (to_intro_patterns il) |
| 76 |
|
| 77 |
and to_intro_patterns v = List.map to_intro_pattern v |
| 78 |
|
| 79 |
let () = |
| 80 |
define "ltac1_to_intro_pattern" (Tac2quote_ltac1.ltac1 @-> ret (option Tac2stdlib.intro_pattern)) @@ fun v -> |
| 81 |
|
| 82 |
|
| 83 |
match out_gen (topwit Ltac_plugin.Tacarg.wit_simple_intropattern) v with |
| 84 |
| None -> None |
| 85 |
| Some v -> |
| 86 |
let v = to_intro_pattern v in |
| 87 |
Some v |