Source file core.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
module Id = Dolmen.Std.Id
module Ast = Dolmen.Std.Term
module Ae = struct
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Ae_Base with type 'a t = 'a Type.Tag.t
and type term := Type.T.t)
(Ty : Dolmen.Intf.Ty.Ae_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Ae_Base with type t = Type.T.t
and type term_var := Type.T.Var.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let free_qm_ids ast =
let test id =
match (id : Id.t) with
| { ns = Term; name = Simple s; } when
String.length s >= 2
&& s.[0] = '?' -> true
| _ -> false
in
Ast.S.elements (Ast.free_ids ~test Ast.S.empty ast)
let parse_trigger env ast =
let l = List.map Ast.const (free_qm_ids ast) in
let t =
match l with
| [] -> ast
| _ -> Ast.exists l ast
in
let var_infer = Type.var_infer env in
let env =
Type.with_var_infer env (
{ var_infer with
infer_term_vars_in_binding_pos =
Wildcard (Any_base {
allowed = [ Ty.int; Ty.real ];
preferred = Ty.real;
})
}
)
in
Type.parse_term env t
let parse_maps_to env ast (var, t) =
let t = Type.parse_term env t in
match var with
| { Ast.term = Ast.Symbol sym; _ }
| { Ast.term =
Ast.App ({ Ast.term = Ast.Symbol sym; _ }, []); _
} ->
begin
match Type.find_bound env sym with
| `Term_var v -> T.semantic_trigger (T.maps_to v t)
| _ -> Type._error env (Ast ast) (Type.Cannot_find (sym, ""))
end
| _ -> Type._error env (Ast ast) (Type.Expected ("Variable name", None))
let parse env s =
match s with
| Type.Builtin Ast.Bool ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.bool)
| Type.Builtin Ast.Prop ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.bool)
| Type.Builtin Ast.Unit ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.unit)
| Type.Builtin Ast.Void ->
Type.builtin_term (Base.app0 (module Type) env s T.void)
| Type.Builtin Ast.True ->
Type.builtin_term (Base.app0 (module Type) env s T._true)
| Type.Builtin Ast.False ->
Type.builtin_term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Not ->
Type.builtin_term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.And ->
Type.builtin_term (Base.term_app_left (module Type) env s mk_and)
| Type.Builtin Ast.Or ->
Type.builtin_term (Base.term_app_left (module Type) env s mk_or)
| Type.Builtin Ast.Xor ->
Type.builtin_term (Base.term_app_left (module Type) env s T.xor)
| Type.Builtin Ast.Imply ->
Type.builtin_term (Base.term_app_right (module Type) env s T.imply)
| Type.Builtin Ast.Equiv ->
Type.builtin_term (Base.term_app_right (module Type) env s T.equiv)
| Type.Builtin Ast.Ite ->
Type.builtin_term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Builtin Ast.Eq ->
Type.builtin_term (
fun ast args ->
match args with
| [Ast.{
term = App ( { term = Builtin Eq; _ }, [_; lr_st] ); _
} as l_st; r_st] ->
Base.term_app_list (module Type) env s
T._and ast [l_st; Ast.eq lr_st r_st]
| _ ->
Base.term_app2 (module Type) env s T.eq ast args
)
| Type.Builtin Ast.Distinct ->
Type.builtin_term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "ac"; ns = Attr; }->
Type.builtin_tags (fun _ _ -> [Type.Set (Tag.ac, ())])
| Type.Id { name = Simple "predicate"; ns = Attr; }->
Type.builtin_tags (fun _ _ -> [Type.Set (Tag.predicate, ())])
| Type.Id { name = Simple n; ns = Track; }->
Type.builtin_tags (fun _ _ -> [Type.Set (Tag.named, n)])
| Type.Id { name = Simple "triggers"; ns = Attr; } ->
Type.builtin_tags
(fun _ast l ->
let l = List.map (parse_trigger env) l in
[Type.Set (Tag.triggers, l)]
)
| Type.Id { name = Simple "filters"; ns = Attr; } ->
Type.builtin_tags (fun _ l ->
let l = List.map (Type.parse_prop env) l in
[Type.Set (Tag.filters, l)]
)
| Type.Builtin Ast.Multi_trigger ->
Type.builtin_term (fun _ast l ->
let l = List.map (Type.parse_term env) l in
T.multi_trigger l
)
| Type.Builtin Ast.Maps_to ->
Type.builtin_term (Base.make_op2 (module Type) env s (parse_maps_to env))
| _ -> `Not_found
end
end
module Dimacs = struct
module Tff
(Type : Tff_intf.S)
(T : Dolmen.Intf.Term.Dimacs with type t = Type.T.t) = struct
let parse env s =
match s with
| Type.Builtin Ast.Not ->
Type.builtin_term (Base.term_app1 (module Type) env s T.neg)
| _ -> `Not_found
end
end
module Tptp = struct
module Tff
(Type : Tff_intf.S)
(Ty : Dolmen.Intf.Ty.Tptp_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Tptp_Tff_Core with type t = Type.T.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse _version env s =
match s with
| Type.Id { name = Simple "$tType"; ns = Term } ->
Type.builtin_ttype (Base.app0 (module Type) env s ())
| Type.Id { name = Simple "$o"; ns = Term } ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "$i"; ns = Term } ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.base)
| Type.Id { name = Simple "$true"; ns = Term } ->
Type.builtin_term (Base.app0 (module Type) env s T._true)
| Type.Id { name = Simple "$false"; ns = Term } ->
Type.builtin_term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Eq ->
Type.builtin_term (Base.term_app2 (module Type) env s T.eq)
| Type.Builtin Ast.Distinct ->
Type.builtin_term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "$distinct"; ns = Term; } ->
Type.builtin_term (Base.term_app_list (module Type) env s T.distinct)
| Type.Builtin Ast.Not ->
Type.builtin_term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.Or ->
Type.builtin_term (Base.term_app2 (module Type) env s mk_or)
| Type.Builtin Ast.And ->
Type.builtin_term (Base.term_app2 (module Type) env s mk_and)
| Type.Builtin Ast.Xor ->
Type.builtin_term (Base.term_app2 (module Type) env s T.xor)
| Type.Builtin Ast.Nor ->
Type.builtin_term (Base.term_app2 (module Type) env s T.nor)
| Type.Builtin Ast.Nand ->
Type.builtin_term (Base.term_app2 (module Type) env s T.nand)
| Type.Builtin Ast.Equiv ->
Type.builtin_term (Base.term_app2 (module Type) env s T.equiv)
| Type.Builtin Ast.Imply ->
Type.builtin_term (Base.term_app2 (module Type) env s T.imply)
| Type.Builtin Ast.Implied ->
Type.builtin_term (Base.term_app2 (module Type) env s T.implied)
| Type.Builtin Ast.Ite ->
Type.builtin_term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id id when Id.equal id Id.tptp_role ->
Type.builtin_tags (fun _ast _args -> [])
| Type.Id id when Id.equal id Id.tptp_kind ->
Type.builtin_tags (fun _ast _args -> [])
| _ -> `Not_found
end
module Thf
(Type : Thf_intf.S)
(Ty : Dolmen.Intf.Ty.Tptp_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Tptp_Thf_Core with type t = Type.T.t
and type Const.t = Type.T.Const.t) = struct
let parse _version env s =
match s with
| Type.Id { name = Simple "$tType"; ns = Term } ->
Type.builtin_ttype (Base.app0 (module Type) env s ())
| Type.Id { name = Simple "$o"; ns = Term } ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "$i"; ns = Term } ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.base)
| Type.Id { name = Simple "$true"; ns = Term } ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const._true)
| Type.Id { name = Simple "$false"; ns = Term } ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const._false)
| Type.Builtin Ast.Eq ->
Type.builtin_term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.eq)))
| Type.Builtin Ast.Distinct ->
Type.builtin_term (Base.term_app_list (module Type) env s T.distinct)
| Type.Id { name = Simple "$distinct"; ns = Term; } ->
Type.builtin_term (Base.term_app_list (module Type) env s T.distinct)
| Type.Builtin Ast.Not ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.neg)
| Type.Builtin Ast.Or ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.or_)
| Type.Builtin Ast.And ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.and_)
| Type.Builtin Ast.Xor ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.xor)
| Type.Builtin Ast.Nor ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.nor)
| Type.Builtin Ast.Nand ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.nand)
| Type.Builtin Ast.Equiv ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.equiv)
| Type.Builtin Ast.Imply ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.imply)
| Type.Builtin Ast.Implied ->
Type.builtin_term (Base.term_app_cst (module Type) env T.Const.implied)
| Type.Builtin Ast.Ite ->
Type.builtin_term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.ite)))
| Type.Builtin Ast.Pi ->
Type.builtin_term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.pi)))
| Type.Builtin Ast.Sigma ->
Type.builtin_term (Base.term_app_ho_ast (module Type) env
(fun ast -> Type.monomorphize env ast (T.of_cst T.Const.sigma)))
| Type.Id id when Id.equal id Id.tptp_role ->
Type.builtin_tags (fun _ast _args -> [])
| Type.Id id when Id.equal id Id.tptp_kind ->
Type.builtin_tags (fun _ast _args -> [])
| _ -> `Not_found
end
end
module Smtlib2 = struct
exception Empty_sexpr of Ast.t
exception Bad_index_in_sexpr of Ast.t
exception Unexpected_structure_in_sexpr of Ast.t
exception Uninterpreted_reserved_word_in_sexpr of Id.t * Ast.t
let uninterpreted_reserved_word = function
| "!"
| "let"
| "exists"
| "forall"
| "match"
| "par"
| "assert"
| "check-sat"
| "check-sat-assuming"
| "declare-const"
| "declare-datatype"
| "declare-datatypes"
| "declare-fun"
| "declare-sort"
| "define-fun"
| "define-fun-rec"
| "define-funs-rec"
| "define-sort"
| "echo"
| "exit"
| "get-assertions"
| "get-assignment"
| "get-info"
| "get-model"
| "get-option"
| "get-proof"
| "get-unsat-assumptions"
| "get-unsat-core"
| "get-value"
| "pop"
| "push"
| "reset"
| "reset-assertions"
| "set-info"
| "set-logic"
| "set-option" -> true
| _ -> false
let index_of_sexpr ast =
match (ast : Ast.t) with
| { term = Symbol {
name = Simple index;
ns = (Value (Integer|Hexadecimal|Binary));
}; _ } ->
index
| _ -> raise (Bad_index_in_sexpr ast)
let rec sexpr_as_term sexpr =
match (sexpr : Ast.t) with
| { term = App ({ term = Builtin Sexpr; _ }, {
term = App ({ term = Builtin Sexpr; _ }, [
{ term = Symbol { name = Simple "as"; _ }; _}; f; ty]);
loc = loc_as; attr = attr_as
} :: args); loc = loc_out; attr = attr_out} ->
let ty = sexpr_as_sort ty in
let f = sexpr_as_term f in
let args = List.map sexpr_as_term args in
let function_app =
Ast.apply ~loc:loc_out f args
|> Ast.add_attrs attr_out
in
Ast.colon ~loc:loc_as function_app ty
|> Ast.add_attrs attr_as
| { term = App ({ term = Builtin Sexpr; _ }, [
{ term = Symbol { name = Simple "as"; _ }; _}; f; ty])
; loc=loc_as; attr=attr_as } ->
let f = sexpr_as_term f in
let ty = sexpr_as_sort ty in
Ast.colon ~loc:loc_as f ty
|> Ast.add_attrs attr_as
| { term = App ({ term = Builtin Sexpr; _ }, {
term = Symbol { ns; name = Simple "_"} ; _} ::
{ term = Symbol {name = Simple s; _}; _ } :: args); loc; attr } ->
Ast.const ~loc (Id.indexed ns s (List.map index_of_sexpr args))
|> Ast.add_attrs attr
| { term = App ({ term = Builtin Sexpr; _ }, []); _ } ->
raise (Empty_sexpr sexpr)
| { term = App ({ term = Builtin Sexpr; _ }, f :: args); loc; attr } ->
let f = sexpr_as_term f in
let args = List.map sexpr_as_term args in
Ast.apply ~loc f args
|> Ast.add_attrs attr
| { term = App({ term = Builtin Sexpr; _ }, _); _ } -> .
| { term = Symbol ({ name = Simple s; _ } as id); _ } ->
if uninterpreted_reserved_word s
then raise (Uninterpreted_reserved_word_in_sexpr (id, sexpr))
else sexpr
| _ -> raise (Unexpected_structure_in_sexpr sexpr)
and sexpr_as_sort sexpr =
match (sexpr : Ast.t) with
| { term = Symbol ({ ns = Term; name = (Simple s as name); } as id) ; loc; attr} ->
if uninterpreted_reserved_word s
then raise (Uninterpreted_reserved_word_in_sexpr (id, sexpr))
else
Ast.const ~loc (Id.create Sort name)
|> Ast.add_attrs attr
| { term = App ({ term = Builtin Sexpr; _ }, {
term = Symbol { ns = Term; name = Simple "_"} ; _} ::
{ term = Symbol {name = Simple s; _}; _ } :: args); loc; attr } ->
Ast.const ~loc (Id.indexed Sort s (List.map index_of_sexpr args))
|> Ast.add_attrs attr
| { term = App ({ term = Builtin Sexpr; _ }, []); _ } ->
raise (Empty_sexpr sexpr)
| { term = App ({ term = Builtin Sexpr; _ }, f :: args); loc; attr } ->
let f = sexpr_as_sort f in
let args = List.map sexpr_as_sort args in
Ast.apply ~loc f args
|> Ast.add_attrs attr
| { term = App({ term = Builtin Sexpr; _ }, _); _ } -> .
| _ -> raise (Unexpected_structure_in_sexpr sexpr)
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Smtlib_Base with type 'a t = 'a Type.Tag.t
and type term := Type.T.t)
(Ty : Dolmen.Intf.Ty.Smtlib_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Smtlib_Base with type t = Type.T.t
and type cstr := Type.T.Cstr.t) = struct
type _ Type.err +=
| Incorrect_sexpression : Dolmen.Intf.Msg.t -> Dolmen.Std.Term.t Type.err
let inferred_model_constants = Dolmen.Std.Tag.create ()
let add_model_constant state c =
let l =
match Type.get_global_custom_state state
inferred_model_constants with
| None -> []
| Some l -> l
in
Type.set_global_custom_state state inferred_model_constants (c :: l)
let parse_name env = function
| ({ Ast.term = Ast.Symbol s; _ } as ast)
| ({ Ast.term = Ast.App ({ Ast.term = Ast.Symbol s; _ }, []); _ } as ast) ->
begin match Dolmen.Std.Id.name s with
| Simple s -> s
| _ -> Type._error env (Ast ast) (Type.Expected ("simple name", None))
end
| ast ->
Type._error env (Ast ast) (Type.Expected ("symbol", None))
let env = function
| { Ast.term = Ast.App ({ Ast.term = Ast.Builtin Sexpr; _ }, l); _} -> l
| ast ->
Type._error env (Ast ast)
(Type.Expected ("a list of terms in a sexpr", None))
let parse_sexpr env sexpr =
match sexpr_as_term sexpr with
| term -> Type.parse_term env term
| exception Empty_sexpr ast ->
let msg = Format.dprintf "empty s-expression" in
Type._error env (Ast ast) (Incorrect_sexpression msg)
| exception Bad_index_in_sexpr ast ->
let msg = Format.dprintf "indexes of indexed identifiers must be integers" in
Type._error env (Ast ast) (Incorrect_sexpression msg)
| exception Uninterpreted_reserved_word_in_sexpr (id, ast) ->
let msg =
Format.dprintf
"the reserved word '%a' is currently not interpreted in s-expressions,@ \
please report upstream if you think it should be interpreted" Id.print id
in
Type._error env (Ast ast) (Incorrect_sexpression msg)
| exception Unexpected_structure_in_sexpr ast ->
let msg = Format.dprintf
"unexpected structure in a s-expression,@ \
please report upstream"
in
Type._error env (Ast ast) (Incorrect_sexpression msg)
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse (version : Dolmen.Smtlib2.version) env s =
match s with
| Type.Id { name = Simple "Bool"; ns = Sort } ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.prop)
| Type.Id { name = Simple "true"; ns = Term } ->
Type.builtin_term (Base.app0 (module Type) env s T._true)
| Type.Id { name = Simple "false"; ns = Term } ->
Type.builtin_term (Base.app0 (module Type) env s T._false)
| Type.Id { name = Simple "not"; ns = Term } ->
Type.builtin_term (Base.term_app1 (module Type) env s T.neg)
| Type.Id { name = Simple "and"; ns = Term } ->
Type.builtin_term (Base.term_app_left (module Type) env s mk_and)
| Type.Id { name = Simple "or"; ns = Term } ->
Type.builtin_term (Base.term_app_left (module Type) env s mk_or)
| Type.Id { name = Simple "xor"; ns = Term } ->
Type.builtin_term (Base.term_app_left (module Type) env s T.xor)
| Type.Id { name = Simple "=>"; ns = Term } ->
Type.builtin_term (Base.term_app_right (module Type) env s T.imply)
| Type.Id { name = Simple "ite"; ns = Term } ->
Type.builtin_term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id { name = Simple "distinct"; ns = Term } ->
Type.builtin_term (fun _ast args ->
let args = List.map (Type.parse_term env) args in
T.distinct args)
| Type.Id { name = Simple "="; ns = Term } ->
Type.builtin_term (Base.term_app_chain (module Type) env s T.eq)
| Type.Id { name = Simple ":named"; ns = Attr } ->
Type.builtin_tags (Base.make_op1 (module Type) env s (fun _ t ->
let name = parse_name env t in
[Type.Set (Tag.named, name)]
))
| Type.Id { name = Simple ":pattern"; ns = Attr } ->
Type.builtin_tags (Base.make_op1 (module Type) env s (fun _ t ->
let l = extract_sexpr_list_from_sexpr env t in
let l = List.map (parse_sexpr env) l in
let t = T.multi_trigger l in
[Type.Add (Tag.triggers, t)]
))
| Type.Id id when Id.equal id Id.rwrt_rule ->
Type.builtin_tags (fun _ast _args -> [Type.Set (Tag.rwrt, ())])
| Type.Id { Id.ns = Term; name = Indexed { basename; indexes; } } as symbol ->
Base.parse_indexed basename indexes
~k:(fun _ -> `Not_found)
~err:(fun _ _ _ -> `Not_found) (function
| "is" -> `Unary (function s ->
let id = Id.mk Term s in
begin match Type.find_bound env id with
| `Cstr c ->
Type.builtin_term (Base.term_app1 (module Type) env symbol (Type.T.cstr_tester c))
| _ -> `Not_found
end)
| _ -> `Not_indexed
)
| Type.Id { Id.ns = Term; name = Simple name; } ->
if String.length name <= 1 then `Not_found
else begin
match name.[0] with
| '.' ->
begin match version with
| `Script _ ->
`Reserved (
"solver-generated function symbols other than abstract values",
`Solver)
| `Response _ -> `Not_found
end
| '@' ->
begin match version with
| `Script _ -> `Reserved ("abstract values in models", `Solver)
| `Response _ ->
let var_infer = Type.var_infer env in
let sym_infer = Type.sym_infer env in
let state = Type.state env in
let sym_hook cst =
sym_infer.sym_hook cst;
match cst with
| `Ty_cst _ -> ()
| `Term_cst c -> add_model_constant state c
in
let sym_infer : Type.sym_infer = {
sym_hook;
infer_type_csts = false;
infer_term_csts = Wildcard Any_in_scope;
} in
`Infer ("abstract values (i.e. constants)", var_infer, sym_infer)
end
| _ -> `Not_found
end
| _ -> `Not_found
end
end
module Zf = struct
module Tff
(Type : Tff_intf.S)
(Tag : Dolmen.Intf.Tag.Zf_Base with type 'a t = 'a Type.Tag.t)
(Ty : Dolmen.Intf.Ty.Zf_Base with type t = Type.Ty.t)
(T : Dolmen.Intf.Term.Zf_Base with type t = Type.T.t) = struct
let mk_or a b = T._or [a; b]
let mk_and a b = T._and [a; b]
let parse env s =
match s with
| Type.Builtin Ast.Prop ->
Type.builtin_ty (Base.app0 (module Type) env s Ty.prop)
| Type.Builtin Ast.True ->
Type.builtin_term (Base.app0 (module Type) env s T._true)
| Type.Builtin Ast.False ->
Type.builtin_term (Base.app0 (module Type) env s T._false)
| Type.Builtin Ast.Not ->
Type.builtin_term (Base.term_app1 (module Type) env s T.neg)
| Type.Builtin Ast.Or ->
Type.builtin_term (Base.term_app2 (module Type) env s mk_or)
| Type.Builtin Ast.And ->
Type.builtin_term (Base.term_app2 (module Type) env s mk_and)
| Type.Builtin Ast.Imply ->
Type.builtin_term (Base.term_app2 (module Type) env s T.imply)
| Type.Builtin Ast.Equiv ->
Type.builtin_term (Base.term_app2 (module Type) env s T.equiv)
| Type.Builtin Ast.Eq ->
Type.builtin_term (Base.term_app2 (module Type) env s T.eq)
| Type.Builtin Ast.Distinct ->
Type.builtin_term (Base.term_app2 (module Type) env s T.neq)
| Type.Builtin Ast.Ite ->
Type.builtin_term (
Base.make_op3 (module Type) env s (fun _ (a, b, c) ->
let cond = Type.parse_prop env a in
let then_ = Type.parse_term env b in
let else_ = Type.parse_term env c in
T.ite cond then_ else_
)
)
| Type.Id id when Id.equal id Id.rwrt_rule ->
Type.builtin_tags (fun _ast _args -> [Type.Set (Tag.rwrt, ())])
| Type.Id { name = Simple "infix"; ns = Term } ->
Type.builtin_tags (fun ast args -> match args with
| [ { Ast.term = Ast.Symbol { name = Simple name; _ }; _ } ] -> [
Type.Set (Tag.name, Tag.exact name);
Type.Set (Tag.pos, Tag.infix);
]
| _ ->
Type._error env (Ast ast)
(Type.Expected ("a symbol", None))
)
| Type.Id { name = Simple "prefix"; ns = Term } ->
Type.builtin_tags (fun ast args -> match args with
| [ { Ast.term = Ast.Symbol { name = Simple name; _ }; _ } ] -> [
Type.Set (Tag.name, Tag.exact name);
Type.Set (Tag.pos, Tag.prefix);
]
| _ ->
Type._error env (Ast ast)
(Type.Expected ("a symbol", None))
)
| _ -> `Not_found
end
end