-let mk_meta ?(attrs=[]) metasenv context ty =
- let tyof = List.map (function `Name s -> `Name ("typeof_"^s) | x -> x) in
- let rec mk_meta attrs n metasenv context = function
- | `WithType ty ->
- let len = List.length context in
- let menv_entry = (n, (attrs, context, ty)) in
- menv_entry :: metasenv, n, NCic.Meta (n, (0,NCic.Irl len)), ty
- | `Sort ->
- let ty = NCic.Implicit (`Typeof n) in
- mk_meta (tyof attrs) n metasenv [] (`WithType ty)
- | `Type ->
- let metasenv, _, ty, _ =
- mk_meta (tyof attrs) (newmeta ()) metasenv context `Sort in
- mk_meta attrs n metasenv context (`WithType ty)
- | `Term ->
- let metasenv, _, ty, _ =
- mk_meta (tyof attrs) (newmeta ()) metasenv context `Type in
- mk_meta attrs n metasenv context (`WithType ty)
- in
- mk_meta attrs (newmeta ()) metasenv context ty
+let mk_meta ?(attrs=[]) metasenv context ?with_type kind =
+ assert(kind <> `IsSort || context = []);
+ let n = newmeta () in
+ let ty= match with_type with None-> NCic.Implicit (`Typeof n)| Some x ->x in
+ let len = List.length context in
+ let attrs = NCicUntrusted.set_kind kind attrs in
+ let menv_entry = (n, (attrs, context, ty)) in
+ menv_entry :: metasenv, n, NCic.Meta (n, (0,NCic.Irl len)), ty
+;;
+
+let extend_meta metasenv n =
+ try
+ let attrs,cc,ty = NCicUtils.lookup_meta n metasenv in
+ (match ty with
+ | NCic.Implicit (`Typeof _) ->
+ let mk_meta context kind =
+ let metasenv, _, ty, _ = mk_meta metasenv context kind in
+ (n, (attrs, cc, ty)) :: List.filter (fun x,_ -> x <> n) metasenv, ty
+ in
+ (match NCicUntrusted.kind_of_meta attrs with
+ | `IsSort
+ | `IsType -> mk_meta [] `IsSort
+ | `IsTerm -> mk_meta cc `IsType)
+ | ty -> metasenv, ty)
+ with NCicUtils.Meta_not_found _ -> assert false