Skip to content

Commit 91596e8

Browse files
author
Danel Ahman
committed
Changed dummy interrupt name in cancellable calls examples; added an example of handling only first n interrupts of particular kind
1 parent eb67f5e commit 91596e8

File tree

5 files changed

+137
-43
lines changed

5 files changed

+137
-43
lines changed

examples/cancellableCall.aeff

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
operation call : int * int
22
operation result : int * int
33
operation cancel : int
4-
operation dummy : empty
4+
operation impossible : empty
55

66
let callWith callCounter =
77
fun x ->
@@ -19,10 +19,10 @@ let callWith callCounter =
1919
let remote f =
2020
promise (call (x, callNo) r ->
2121
spawn (
22-
promise (cancel callNo' dummyR when callNo = callNo' ->
23-
let dummyPromise = promise (dummy empty -> return <<empty>>) in
24-
await dummyPromise;
25-
dummyR ()
22+
promise (cancel callNo' impossibleR when callNo = callNo' ->
23+
let impossiblePromise = promise (impossible empty -> return <<empty>>) in
24+
await impossiblePromise;
25+
impossibleR ()
2626
);
2727
let y = (unbox f) x in
2828
send result (y, callNo)
@@ -40,4 +40,4 @@ run
4040
result3 ()
4141

4242
run
43-
remote [| fun x -> 4 * (5 * (6 * x)) |]
43+
remote [| fun x -> 4 * (5 * (6 * x)) |]

examples/cancellableCallFunPayload.aeff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
operation call : [| unit -> unit |]
22
operation result : int * int
33
operation cancel : int
4-
operation dummy : empty
4+
operation impossible : empty
55

66
let waitForCancel callNo =
77
promise (cancel callNo' when callNo = callNo' ->
8-
let p = promise (dummy empty -> return <<()>>) in
8+
let p = promise (impossible empty -> return <<()>>) in
99
await p;
1010
return <<()>>
1111
)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
operation request : int
2+
operation response : int
3+
4+
run
5+
promise (request x r s ->
6+
if s > 0 then
7+
send response (x + 42);
8+
r (s - 1)
9+
else
10+
return <<()>>
11+
) at 3
12+
13+
run
14+
send request 1;
15+
send request 2;
16+
send request 3;
17+
send request 4;
18+
send request 5

src/webInterface/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@
5151
(echo "({|Timer|}, {|")
5252
(cat ../../examples/ticktock.aeff)
5353
(echo "|});")
54+
(echo "({|Handle only first n interrupts|}, {|")
55+
(cat ../../examples/handleFirstThreeInterrupts.aeff)
56+
(echo "|});")
5457
(echo "]"))))

tests/run_tests.t

Lines changed: 108 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@
395395
operation call : int × int
396396
operation result : int × int
397397
operation cancel : int
398-
operation dummy : empty
398+
operation impossible : empty
399399
val callWith : int ref → int → (unit → int) × (unit → unit) ×
400400
(int → unit)
401401
val remote : [(int → int)] → ⟨α⟩
@@ -410,7 +410,7 @@
410410
↑ call (240, 2)
411411
↑ result (28800, 2)
412412
The process has terminated in the configuration:
413-
run promise (dummy empty _ _ ↦ return ⟨empty⟩)
413+
run promise (impossible empty _ _ ↦ return ⟨empty⟩)
414414
@ () as p in
415415
↓result((28800, 2),
416416
↓call((240, 2),
@@ -421,7 +421,7 @@
421421
await p until ⟨x⟩ in
422422
return x;
423423
(fun s' ↦ promise (
424-
cancel callNo' dummyR _ ↦
424+
cancel callNo' impossibleR _ ↦
425425
let b =
426426
(=)
427427
(
@@ -430,77 +430,80 @@
430430
match b with (
431431
true ↦
432432
let
433-
dummyPromise =
433+
impossiblePromise =
434434
promise (
435-
dummy empty _ _ ↦
435+
impossible empty _ _ ↦
436436
return
437437
⟨empty⟩)
438438
@ () as p in
439439
return p in
440440
await
441-
dummyPromise until
441+
impossiblePromise until
442442
⟨x⟩ in
443443
return x;
444-
dummyR () |
444+
impossibleR
445+
() |
445446
false ↦
446-
dummyR ()))
447+
impossibleR
448+
()))
447449
@ s' as p' in
448450
return p')
449451
() in
450452
↓cancel(0, return ()))))))
451453
||
452-
run promise (cancel callNo' dummyR _ ↦
454+
run promise (cancel callNo' impossibleR _ ↦
453455
let b = (=) (1, callNo') in
454-
match b with (true ↦ let dummyPromise =
455-
promise (dummy empty _ _ ↦
456+
match b with (true ↦ let impossiblePromise =
457+
promise (impossible empty _ _ ↦
456458
return ⟨empty⟩)
457459
@ () as p in
458460
return p in
459-
await dummyPromise until ⟨x⟩ in
460-
return x; dummyR () | false ↦ dummyR ()))
461+
await impossiblePromise until ⟨x⟩ in
462+
return x; impossibleR () |
463+
false ↦ impossibleR ()))
461464
@ () as p' in
462465
return ()
463466
||
464-
run promise (dummy empty _ _ ↦ return ⟨empty⟩)
467+
run promise (impossible empty _ _ ↦ return ⟨empty⟩)
465468
@ () as p in
466469
↓result((28800, 2),
467470
↓call((240, 2),
468471
let p =
469472
await p until ⟨x⟩ in return x;
470-
(fun s' ↦ promise (cancel callNo' dummyR _ ↦
473+
(fun s' ↦ promise (cancel callNo' impossibleR _ ↦
471474
let b = (=) (2, callNo') in
472475
match b with (true ↦
473476
let
474-
dummyPromise =
477+
impossiblePromise =
475478
promise (
476-
dummy empty _ _ ↦
479+
impossible empty _ _ ↦
477480
return
478481
⟨empty⟩)
479482
@ () as p in
480483
return p in
481-
await dummyPromise until
484+
await impossiblePromise until
482485
⟨x⟩ in
483486
return x;
484-
dummyR () |
487+
impossibleR () |
485488
false ↦
486-
dummyR ()))
489+
impossibleR ()))
487490
@ s' as p' in
488491
return p')
489492
() in ↓cancel(2, return ())))
490493
||
491494
run promise (call (x, callNo) r _ ↦
492-
Spawn (promise (cancel callNo' dummyR _ ↦
495+
Spawn (promise (cancel callNo' impossibleR _ ↦
493496
let b = (=) (callNo, callNo') in
494-
match b with (true ↦ let dummyPromise =
495-
promise (dummy empty _ _ ↦
497+
match b with (true ↦ let impossiblePromise =
498+
promise (impossible empty _ _ ↦
496499
return
497500
⟨empty⟩)
498501
@ () as p in
499502
return p in
500-
await dummyPromise until
503+
await impossiblePromise until
501504
⟨x⟩ in return x;
502-
dummyR () |
503-
false ↦ dummyR ()))
505+
impossibleR () |
506+
false ↦ impossibleR ()))
504507
@ () as p in
505508
return p;
506509
let y =
@@ -514,15 +517,16 @@
514517
@ () as p' in
515518
return p'
516519
||
517-
run promise (cancel callNo' dummyR _ ↦
520+
run promise (cancel callNo' impossibleR _ ↦
518521
let b = (=) (2, callNo') in
519-
match b with (true ↦ let dummyPromise =
520-
promise (dummy empty _ _ ↦
522+
match b with (true ↦ let impossiblePromise =
523+
promise (impossible empty _ _ ↦
521524
return ⟨empty⟩)
522525
@ () as p in
523526
return p in
524-
await dummyPromise until ⟨x⟩ in
525-
return x; dummyR () | false ↦ dummyR ()))
527+
await impossiblePromise until ⟨x⟩ in
528+
return x; impossibleR () |
529+
false ↦ impossibleR ()))
526530
@ () as p in
527531
return ()
528532
||
@@ -587,7 +591,7 @@
587591
operation call : [(unit → unit)]
588592
operation result : int × int
589593
operation cancel : int
590-
operation dummy : empty
594+
operation impossible : empty
591595
val waitForCancel : int → ⟨unit⟩
592596
val remoteCall : int ref → [(unit → int)] → (unit → int) ×
593597
(unit → unit)
@@ -609,7 +613,7 @@
609613
let res = g () in ↑result((res, 2), return ())]
610614
↑ result (504, 2)
611615
The process has terminated in the configuration:
612-
run promise (dummy empty _ _ ↦ return ⟨()⟩)
616+
run promise (impossible empty _ _ ↦ return ⟨()⟩)
613617
@ () as p in
614618
↓result((504, 2),
615619
↓call([fun _ ↦ waitForCancel 2;
@@ -632,7 +636,7 @@
632636
run promise (cancel callNo' r _ ↦
633637
let b = (=) (2, callNo') in
634638
match b with (true ↦ let p =
635-
promise (dummy empty _ _ ↦
639+
promise (impossible empty _ _ ↦
636640
return ⟨()⟩)
637641
@ () as p in
638642
return p in
@@ -644,7 +648,7 @@
644648
run promise (cancel callNo' r _ ↦
645649
let b = (=) (0, callNo') in
646650
match b with (true ↦ let p =
647-
promise (dummy empty _ _ ↦
651+
promise (impossible empty _ _ ↦
648652
return ⟨()⟩)
649653
@ () as p in
650654
return p in
@@ -884,6 +888,75 @@
884888
@ () as p' in
885889
return p'
886890
======================================================================
891+
../examples/handleFirstThreeInterrupts.aeff
892+
======================================================================
893+
val (=) : α × α → bool
894+
val (<) : α × α → bool
895+
val (>) : α × α → bool
896+
val (<=) : α × α → bool
897+
val (>=) : α × α → bool
898+
val (<>) : α × α → bool
899+
val (~-) : intint
900+
val (+) : int × intint
901+
val (*) : int × intint
902+
val (-) : int × intint
903+
val (mod) : int × intint
904+
val (/) : int × int → int
905+
val ref : α → α ref
906+
val (!) : α ref → α
907+
val (:=) : α ref × α → unit
908+
val toString : α → string
909+
val absurd : α → β
910+
val not : bool → bool
911+
type option
912+
val assoc : α → (α × β) list → β option
913+
val range : int → int → int list
914+
val reverse : α list → α list
915+
val map : (α → β) → α list → β list
916+
val hd : α list → α
917+
val tl : α list → α list
918+
val take : (int → α) → int → α list
919+
val foldLeft : (α → β → α) → α → β list → α
920+
val foldRight : (α → β → β) → α list → β → β
921+
val iter : (α → β) → α list → unit
922+
val forall : (α → bool) → α list → bool
923+
val exists : (α → bool) → α list → bool
924+
val mem : α → α list → bool
925+
val filter : (α → bool) → α list → α list
926+
val complement : α list → α list → α list
927+
val intersection : α list → α list → α list
928+
val zip : α list → β list → (α × β) list
929+
val unzip : (α × β) list → α list × β list
930+
val (@) : α list × α list → α list
931+
val length : α list → int
932+
val nth : α list → int → α
933+
val abs : int → int
934+
val min : α → α → α
935+
val max : α → α → α
936+
val gcd : int → int → int
937+
val lcm : int → int → int
938+
val odd : int → bool
939+
val even : int → bool
940+
val id : α → α
941+
val compose : (α → β) → (γ → α) → γ → β
942+
val (|>) : α → (α → β) → β
943+
val ignore : α → unit
944+
val fst : α × β → α
945+
val snd : α × β → β
946+
val return : α → α
947+
operation request : int
948+
operation response : int
949+
↑ request 1
950+
↑ request 2
951+
↑ request 3
952+
↑ request 4
953+
↑ request 5
954+
↑ response 43
955+
↑ response 44
956+
↑ response 45
957+
The process has terminated in the configuration:
958+
run (return ()) || run (return ⟨()⟩)
959+
======================================================================
887960
../examples/heapPure.aeff
888961
======================================================================
889962
val (=) : α × α → bool

0 commit comments

Comments
 (0)