Skip to content

Commit 29c0bba

Browse files
authored
Merge pull request #182 from PLTools/reify_in_state
reify_in_state, is_ground, is_ground_bool (needed for JGS)
2 parents 3c8d403 + 3e9f0e7 commit 29c0bba

4 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/core/Core.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,3 +800,20 @@ let trace_diseq : goal = fun st ->
800800
Format.printf "%a\n%!" Disequality.pp (State.constraints st) ;
801801
success st
802802

803+
IFDEF NON_ABSTRACT_GOAL THEN
804+
let reify_in_state st reifier x =
805+
let env = State.env st in
806+
let subst = State.subst st in
807+
reifier (State.env st) (Subst.reify env subst x |> Obj.magic)
808+
809+
let is_ground v st cb =
810+
let ans = Subst.reify (State.env st) (State.subst st) v in
811+
cb (not(Term.is_var ans))
812+
813+
let is_ground_bool
814+
: bool ilogic -> State.t -> onvar:(unit->unit) -> on_ground:(bool -> unit) -> unit =
815+
fun v st ~onvar ~on_ground ->
816+
let ans = Subst.reify (State.env st) (State.subst st) (Obj.magic v) in
817+
if (Term.is_var ans) then onvar()
818+
else on_ground (Obj.magic ans : bool)
819+
END

src/core/Core.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,12 @@ end
330330
val reify_in_empty: ('a, 'b) Reifier.t -> 'a -> 'b
331331

332332
val trace_diseq: goal
333+
334+
IFDEF NON_ABSTRACT_GOAL THEN
335+
val reify_in_state: State.t -> ('a, 'b) Reifier.t -> 'a -> 'b
336+
337+
val is_ground : 'a ilogic -> State.t -> (bool -> unit) -> unit
338+
339+
val is_ground_bool : bool ilogic -> State.t -> onvar:(unit->unit) -> on_ground:(bool -> unit) -> unit
340+
341+
END

src/core/Term.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ let is_box t =
123123
t <= Obj.last_non_constant_constructor_tag &&
124124
t >= Obj.first_non_constant_constructor_tag
125125

126+
let is_var x =
127+
let x = Obj.repr x in
128+
let tx = Obj.tag x in
129+
is_box tx && Var.has_var_structure tx (Obj.size x) x
130+
;;
131+
126132
let is_int = (=) Obj.int_tag
127133
let is_str = (=) Obj.string_tag
128134
let is_dbl = (=) Obj.double_tag

src/core/Term.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ val pp : Format.formatter -> t -> unit
8181
(* [var x] if [x] is logic variable returns it, otherwise returns [None] *)
8282
val var : 'a -> Var.t option
8383

84+
val is_var: 'a -> bool
85+
8486
(* [map ~fvar ~fval x] map over OCaml's value extended with logic variables;
8587
* handles primitive types with the help of [fval] and logic variables with the help of [fvar]
8688
*)

0 commit comments

Comments
 (0)