Skip to content

Commit

Permalink
added example
Browse files Browse the repository at this point in the history
  • Loading branch information
Edkamb committed Mar 26, 2021
1 parent 946d8d0 commit 8d73751
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
12 changes: 11 additions & 1 deletion .idea/Chisel.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions examples/Demo/Billard.abs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Demo;

data HybridSpec = ObjInv(String) | Ensures(String) | Requires(String) | Tactic(String);

type Real = Rat;

interface IBillard {
Unit accelerate(Real r);
Unit push(Real a, Real b);
Unit leap();
[HybridSpec: Requires("extra >= 0")]
Unit incSize(Real extra);
}
[HybridSpec: Requires("top > 0 & bottom < 0 & right > 0 & left < 0")]
class Billard(Real top, Real bottom,
Real left, Real right,
Real vx,
Real vy) implements IBillard{

[HybridSpec: ObjInv("top >= y & bottom <= y & right >= x & left <= x")]
physical{
Real x = 0: x' = vx;
Real y = 0: y' = vy;
}
{
this!ctrlTop(); this!ctrlRight();
this!ctrlBottom(); this!ctrlLeft();
}
Unit ctrlTop(){
await diff y >= top && vy >= 0; vy = -vy; this!ctrlTop();
}
Unit ctrlBottom(){
await diff y >= bottom && vy <= 0; vy = -vy; this!ctrlBottom();
}
Unit ctrlRight(){
await diff x >= right && vx >= 0; vx = -vx; this!ctrlRight();
}
Unit ctrlLeft(){
await diff x >= left && vx <= 0; vx = -vx; this!ctrlLeft();
}
Unit accelerate(Real r){ vx = vx*r; vy = vy*r; }
Unit push(Real a, Real b){ vx = vx + a; vy = vy + b; }
Unit leap(){
if( vx > 0 && right - x > 1) x = x + 1;
if( vx < 0 && x -left > 1) x = x - 1;
}
Unit incSize(Real extra){ top = top + extra; }
}
{}

0 comments on commit 8d73751

Please sign in to comment.