Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into small-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sakehl committed May 9, 2024
2 parents c7992e2 + 32e9dbf commit 4c01568
Show file tree
Hide file tree
Showing 135 changed files with 2,268 additions and 621 deletions.
14 changes: 14 additions & 0 deletions examples/concepts/generics/box.pvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Box<T> {
T t;
context Perm(t, 1\2);
ensures \result == t;
T get() {
return t;
}
}

void m() {
Box<int> b = new Box<int>();
int t = b.get();
int t = b.t;
}
65 changes: 65 additions & 0 deletions examples/concepts/generics/genericChannel.pvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
lock_invariant Perm(transfering, 1) ** Perm(exchangeValue,1);
class Chan<T> {
boolean transfering;
T exchangeValue;

ensures committed(this);
constructor() {
transfering = false;
commit this;
}

context committed(this);
void writeValue(T v) {
lock this;

loop_invariant Perm(transfering, 1) ** Perm(exchangeValue,1);
loop_invariant held(this);
while (!transfering) {
unlock this;
lock this;
}

transfering = false;
exchangeValue = v;
unlock this;
}

context committed(this);
T readValue() {
lock this;

loop_invariant Perm(transfering, 1) ** Perm(exchangeValue,1);
loop_invariant held(this);
while (transfering) {
unlock this;
lock this;
}

T m = exchangeValue;
transfering = false;
unlock this;

return m;
}

context committed(this);
T noop(T t) {
writeValue(t);
return readValue();
}
}

void main() {
Chan<int> intChan = new Chan<int>();
Chan<boolean> boolChan = new Chan<boolean>();
Chan<Chan<int>> intChanChan = new Chan<Chan<int>>();

intChan.writeValue(5);
boolChan.writeValue(true);
intChanChan.writeValue(intChan);

int i = intChan.readValue();
boolean b = boolChan.readValue();
Chan<int> c = intChanChan.readValue();
}
4 changes: 4 additions & 0 deletions examples/concepts/generics/genericProcedure.pvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ensures \result == t;
T myProcedure<T>(T t) {
return t;
}
13 changes: 13 additions & 0 deletions examples/technical/java/generics/MyRetention.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.lang.annotation.Retention;

class C {
Retention r;
}

class D<T> { }

class E {
void m() {
D<?> d = null;
}
}
23 changes: 23 additions & 0 deletions examples/technical/veymont/genericEndpoints.pvl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Role<T> {
T t;
int i;

T fromInt(int i);
int toInt(T t);
}

class A { }

class B { }

seq_program genericTest() {
endpoint a = Role<A>();
endpoint b = Role<B>();

requires a != b;
seq_run {
a.i := a.toInt(a.t);
communicate a.i -> b.i;
b.t := b.fromInt(b.i);
}
}
Loading

0 comments on commit 4c01568

Please sign in to comment.