Skip to content

Commit e6ed002

Browse files
authored
Merge pull request #1257 from CakeML/cfHeapsBaseSyntax
Refactor code in cfHeapsBaseSyntax
2 parents e802d90 + 5806d0c commit e6ed002

File tree

1 file changed

+51
-36
lines changed

1 file changed

+51
-36
lines changed

characteristic/cfHeapsBaseSyntax.sml

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ open preamble
77
open set_sepTheory helperLib
88
open cfHeapsBaseTheory
99

10-
val ERR = mk_HOL_ERR"cfHeapsBaseSyntax";
10+
val ERR = mk_HOL_ERR "cfHeapsBaseSyntax";
1111

1212
local
13-
1413
structure Parse = struct
1514
open Parse
1615
val (Type,Term) =
@@ -39,30 +38,41 @@ val heap_part_ty =
3938
val res_ty =
4039
mk_thy_type {Thy = "cfHeapsBase", Tyop = "res", Args = []}
4140

42-
fun dest_sep_imp tm = let
43-
val format = (fst o dest_eq o concl o SPEC_ALL) SEP_IMP_def
44-
in if can (match_term format) tm then (cdr (car tm), cdr tm) else fail() end
41+
local
42+
val sep_imp = prim_mk_const {Name = "SEP_IMP", Thy = "set_sep"}
43+
in
44+
val dest_sep_imp = dest_binop sep_imp (ERR "dest_sep_imp" "")
45+
end
4546

46-
fun dest_cell tm = let
47-
val format = (fst o dest_eq o concl o SPEC_ALL) cell_def
48-
in if can (match_term format) tm then (cdr (car tm), cdr tm) else fail() end
47+
local
48+
val cell = prim_mk_const {Name = "cell", Thy = "cfHeapsBase"}
49+
in
50+
val dest_cell = dest_binop cell (ERR "dest_cell" "")
51+
end
4952

50-
fun dest_REF tm = let
51-
val format = (fst o dest_eq o concl o SPEC_ALL) REF_def
52-
in if can (match_term format) tm then (cdr (car tm), cdr tm) else fail() end
53+
local
54+
val REF = prim_mk_const {Name = "REF", Thy = "cfHeapsBase"}
55+
in
56+
val dest_REF = dest_binop REF (ERR "dest_REF" "")
57+
end
5358

54-
fun dest_ARRAY tm = let
55-
val format = (fst o dest_eq o concl o SPEC_ALL) ARRAY_def
56-
in if can (match_term format) tm then (cdr (car tm), cdr tm) else fail() end
59+
local
60+
val ARRAY = prim_mk_const {Name = "ARRAY", Thy = "cfHeapsBase"}
61+
in
62+
val dest_ARRAY = dest_binop ARRAY (ERR "dest_ARRAY" "")
63+
end
5764

58-
fun dest_W8ARRAY tm = let
59-
val format = (fst o dest_eq o concl o SPEC_ALL) W8ARRAY_def
60-
in if can (match_term format) tm then (cdr (car tm), cdr tm) else fail() end
65+
local
66+
val W8ARRAY = prim_mk_const {Name = "W8ARRAY", Thy = "cfHeapsBase"}
67+
in
68+
val dest_W8ARRAY = dest_binop W8ARRAY (ERR "dest_W8ARRAY" "")
69+
end
6170

62-
fun dest_IO tm = let
63-
val format = (fst o dest_eq o concl o SPEC_ALL) IO_def
64-
in if can (match_term format) tm then (cdr (car (car tm)), cdr (car tm), cdr tm)
65-
else fail() end
71+
local
72+
val IO = prim_mk_const {Name = "IO", Thy = "cfHeapsBase"}
73+
in
74+
val dest_IO = dest_triop IO (ERR "dest_W8ARRAY" "")
75+
end
6676

6777
fun is_cell tm = can dest_cell tm
6878
fun is_REF tm = can dest_REF tm
@@ -72,23 +82,28 @@ fun is_IO tm = can dest_IO tm
7282

7383
fun is_sep_imp tm = can dest_sep_imp tm
7484

75-
fun is_sep_imppost tm = let
76-
val format = (fst o dest_eq o concl o SPEC_ALL) SEP_IMPPOST_def
77-
in can (match_term format) tm end
78-
79-
fun is_cond tm = let
80-
val format = (fst o dest_eq o concl o SPEC_ALL) cond_def
81-
in can (match_term format) tm end
85+
local
86+
val SEP_IMPPOST = prim_mk_const {Name = "SEP_IMPPOST", Thy = "cfHeapsBase"}
87+
val dest_sep_imppost = dest_binop SEP_IMPPOST (ERR "is_sep_imppost" "")
88+
in
89+
val is_sep_imppost = can dest_sep_imppost
90+
end
8291

83-
fun is_sep_exists tm = let
84-
val se = (fst o dest_eq o concl o SPEC_ALL) SEP_EXISTS
85-
in (ignore (match_term se (dest_comb tm |> fst)); true)
86-
handle HOL_ERR _ => false
87-
end
92+
local
93+
val cond_tm = inst [alpha |-> heap_part_ty]
94+
(prim_mk_const {Name = "cond", Thy = "set_sep"})
95+
in
96+
val is_cond = can (dest_monop cond_tm (ERR "is_cond" ""))
97+
fun mk_cond tm = mk_comb (cond_tm,tm)
98+
handle HOL_ERR _ => raise (ERR "mk_cond" "")
99+
end
88100

89-
fun mk_cond t =
90-
SPEC t (INST_TYPE [alpha |-> heap_part_ty] cond_def)
91-
|> concl |> lhs
101+
local
102+
val se = (fst o dest_eq o concl o SPEC_ALL) SEP_EXISTS
103+
in
104+
fun is_sep_exists tm = (same_const se (dest_comb tm |> fst))
105+
handle HOL_ERR _ => false
106+
end
92107

93108
val emp_tm =
94109
inst [alpha |-> heap_part_ty]

0 commit comments

Comments
 (0)