@@ -1399,7 +1399,7 @@ module Op = struct
1399
1399
let cont (env : Sem.senv ) =
1400
1400
(`Det , Sem. translate_e env ret) in
1401
1401
1402
- let _ , aout = Sem. translate_s env cont body.f_body in
1402
+ let mode , aout = Sem. translate_s env cont body.f_body in
1403
1403
let aout = form_of_expr mhr aout in (* FIXME: translate to forms directly? *)
1404
1404
let aout = f_lambda (List. map2 (fun (_ , ty ) x -> (x, GTty ty)) params ids) aout in
1405
1405
@@ -1413,7 +1413,93 @@ module Op = struct
1413
1413
op_unfold = None ;
1414
1414
} in
1415
1415
1416
- bind scope (unloc op.ppo_name, opdecl)
1416
+ let oppath = EcPath. pqname (path scope) (unloc op.ppo_name) in
1417
+
1418
+ let scope = bind scope (unloc op.ppo_name, opdecl) in
1419
+
1420
+ let scope =
1421
+ let prax =
1422
+ let locs = List. map (fun (x , ty ) -> (EcIdent. create x, ty)) params in
1423
+ let res = f_pvar pv_res sig_.fs_ret mhr in
1424
+ let resx = EcIdent. create " v" in
1425
+ let resv = f_local resx sig_.fs_ret in
1426
+ let prmem = EcIdent. create " &m" in
1427
+
1428
+ let mu =
1429
+ let sem =
1430
+ f_app
1431
+ (f_op oppath [] opdecl.op_ty)
1432
+ (List. map (fun (x , ty ) -> f_local x ty) locs)
1433
+ (match mode with `Det -> sig_.fs_ret | `Distr -> tdistr sig_.fs_ret) in
1434
+
1435
+ match mode with
1436
+ | `Det ->
1437
+ f_if (f_eq sem resv) f_r1 f_r0
1438
+
1439
+ | `Distr ->
1440
+ f_mu_x sem resv
1441
+ in
1442
+
1443
+ f_forall
1444
+ [(prmem, GTmem EcMemory. abstract_mt)]
1445
+ (f_forall
1446
+ (List. map (fun (x , ty ) -> (x, GTty ty)) ((resx, sig_.fs_ret) :: locs))
1447
+ (f_eq
1448
+ (f_pr prmem
1449
+ f
1450
+ (f_tuple (List. map (fun (x , ty ) -> f_local x ty) locs))
1451
+ (f_eq res resv))
1452
+ mu))
1453
+ in
1454
+
1455
+ let prax = EcDecl. {
1456
+ ax_tparams = [] ;
1457
+ ax_spec = prax;
1458
+ ax_kind = `Lemma ;
1459
+ ax_loca = op.ppo_locality;
1460
+ ax_visibility = `Visible ;
1461
+ } in
1462
+
1463
+ Ax. bind scope (unloc op.ppo_name ^ " _opsem" , prax) in
1464
+
1465
+ let scope =
1466
+ match mode with
1467
+ | `Det ->
1468
+ let hax =
1469
+ let locs = List. map (fun (x , ty ) -> (EcIdent. create x, ty)) params in
1470
+ let res = f_pvar pv_res sig_.fs_ret mhr in
1471
+ let args = f_pvar pv_arg sig_.fs_arg mhr in
1472
+
1473
+ f_forall
1474
+ (List. map (fun (x , ty ) -> (x, GTty ty)) locs)
1475
+ (f_hoareF
1476
+ (f_eq
1477
+ args
1478
+ (f_tuple (List. map (fun (x , ty ) -> f_local x ty) locs)))
1479
+ f
1480
+ (f_eq
1481
+ res
1482
+ (f_app
1483
+ (f_op oppath [] opdecl.op_ty)
1484
+ (List. map (fun (x , ty ) -> f_local x ty) locs)
1485
+ sig_.fs_ret)))
1486
+ in
1487
+
1488
+ let prax = EcDecl. {
1489
+ ax_tparams = [] ;
1490
+ ax_spec = hax;
1491
+ ax_kind = `Lemma ;
1492
+ ax_loca = op.ppo_locality;
1493
+ ax_visibility = `Visible ;
1494
+ } in
1495
+
1496
+ Ax. bind scope (unloc op.ppo_name ^ " _opsem_det" , prax)
1497
+
1498
+ | `Distr ->
1499
+ scope
1500
+ in
1501
+
1502
+ scope
1417
1503
end
1418
1504
1419
1505
(* -------------------------------------------------------------------- *)
0 commit comments