@@ -43,6 +43,18 @@ let open_constr_no_classes_flags =
43
43
polymorphic = false;
44
44
}
45
45
46
+ let preterm_flags =
47
+ let open Pretyping in
48
+ {
49
+ use_coercions = true;
50
+ use_typeclasses = Pretyping.NoUseTC;
51
+ solve_unification_constraints = true;
52
+ fail_evar = false;
53
+ expand_evars = false;
54
+ program_mode = false;
55
+ polymorphic = false;
56
+ }
57
+
46
58
(** Standard values *)
47
59
48
60
module Value = Tac2ffi
@@ -1641,8 +1653,12 @@ let intern_constr self ist c =
1641
1653
let (_, (c, _)) = Genintern.intern Stdarg.wit_constr ist c in
1642
1654
let v = match DAst.get c with
1643
1655
| GGenarg (GenArg (Glbwit tag, v)) ->
1644
- begin match genarg_type_eq tag wit_ltac2_quotation with
1645
- | Some Refl -> GlbTacexpr (GTacVar v)
1656
+ begin match genarg_type_eq tag wit_ltac2_var_quotation with
1657
+ | Some Refl ->
1658
+ begin match (fst v) with
1659
+ | ConstrVar -> GlbTacexpr (GTacVar (snd v))
1660
+ | _ -> GlbVal c
1661
+ end
1646
1662
| None -> GlbVal c
1647
1663
end
1648
1664
| _ -> GlbVal c
@@ -1904,32 +1920,72 @@ let () =
1904
1920
in
1905
1921
GlobEnv.register_constr_interp0 wit_ltac2_constr interp
1906
1922
1923
+ let interp_constr_var_as_constr ?loc env sigma tycon id =
1924
+ let ist = Tac2interp.get_env @@ GlobEnv.lfun env in
1925
+ let env = GlobEnv.renamed_env env in
1926
+ let c = Id.Map.find id ist.env_ist in
1927
+ let c = Value.to_constr c in
1928
+ let t = Retyping.get_type_of env sigma c in
1929
+ let j = { Environ.uj_val = c; uj_type = t } in
1930
+ match tycon with
1931
+ | None ->
1932
+ j, sigma
1933
+ | Some ty ->
1934
+ let sigma =
1935
+ try Evarconv.unify_leq_delay env sigma t ty
1936
+ with Evarconv.UnableToUnify (sigma,e) ->
1937
+ Pretype_errors.error_actual_type ?loc env sigma j ty e
1938
+ in
1939
+ {j with Environ.uj_type = ty}, sigma
1940
+
1941
+ let interp_preterm_var_as_constr ?loc env sigma tycon id =
1942
+ let open Ltac_pretype in
1943
+ let ist = Tac2interp.get_env @@ GlobEnv.lfun env in
1944
+ let env = GlobEnv.renamed_env env in
1945
+ let c = Id.Map.find id ist.env_ist in
1946
+ let {closure; term} = Value.to_ext Value.val_preterm c in
1947
+ let vars = {
1948
+ ltac_constrs = closure.typed;
1949
+ ltac_uconstrs = closure.untyped;
1950
+ ltac_idents = closure.idents;
1951
+ ltac_genargs = closure.genargs;
1952
+ }
1953
+ in
1954
+ let flags = preterm_flags in
1955
+ let tycon = let open Pretyping in match tycon with
1956
+ | Some ty -> OfType ty
1957
+ | None -> WithoutTypeConstraint
1958
+ in
1959
+ let sigma, t, ty = Pretyping.understand_ltac_ty flags env sigma vars tycon term in
1960
+ Environ.make_judge t ty, sigma
1961
+
1907
1962
let () =
1908
- let interp ?loc ~poly env sigma tycon id =
1909
- let ist = Tac2interp.get_env @@ GlobEnv.lfun env in
1910
- let env = GlobEnv.renamed_env env in
1911
- let c = Id.Map.find id ist.env_ist in
1912
- let c = Value.to_constr c in
1913
- let t = Retyping.get_type_of env sigma c in
1914
- let j = { Environ.uj_val = c; uj_type = t } in
1915
- match tycon with
1916
- | None ->
1917
- j, sigma
1918
- | Some ty ->
1919
- let sigma =
1920
- try Evarconv.unify_leq_delay env sigma t ty
1921
- with Evarconv.UnableToUnify (sigma,e) ->
1922
- Pretype_errors.error_actual_type ?loc env sigma j ty e
1923
- in
1924
- {j with Environ.uj_type = ty}, sigma
1963
+ let interp ?loc ~poly env sigma tycon (kind,id) =
1964
+ let f = match kind with
1965
+ | ConstrVar -> interp_constr_var_as_constr
1966
+ | PretermVar -> interp_preterm_var_as_constr
1967
+ in
1968
+ f ?loc env sigma tycon id
1925
1969
in
1926
- GlobEnv.register_constr_interp0 wit_ltac2_quotation interp
1970
+ GlobEnv.register_constr_interp0 wit_ltac2_var_quotation interp
1927
1971
1928
1972
let () =
1929
- let pr_raw id = Genprint.PrinterBasic (fun _env _sigma -> assert false) in
1930
- let pr_glb id = Genprint.PrinterBasic (fun _env _sigma -> str "$" ++ Id.print id) in
1973
+ let pr_raw (kind,id) = Genprint.PrinterBasic (fun _env _sigma ->
1974
+ let ppkind =
1975
+ match kind with
1976
+ | None -> mt()
1977
+ | Some kind -> Id.print kind.CAst.v ++ str ":"
1978
+ in
1979
+ str "$" ++ ppkind ++ Id.print id.CAst.v)
1980
+ in
1981
+ let pr_glb (kind,id) = Genprint.PrinterBasic (fun _env _sigma ->
1982
+ let ppkind = match kind with
1983
+ | ConstrVar -> mt()
1984
+ | PretermVar -> str "preterm:"
1985
+ in
1986
+ str "$" ++ ppkind ++ Id.print id) in
1931
1987
let pr_top x = Util.Empty.abort x in
1932
- Genprint.register_print0 wit_ltac2_quotation pr_raw pr_glb pr_top
1988
+ Genprint.register_print0 wit_ltac2_var_quotation pr_raw pr_glb pr_top
1933
1989
1934
1990
let () =
1935
1991
let subs avoid globs (ids, tac) =
0 commit comments