-
Notifications
You must be signed in to change notification settings - Fork 54
/
Global.scala
47 lines (42 loc) · 959 Bytes
/
Global.scala
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
import stainless.annotation._
import stainless.io._
object Global {
@cCode.global
case class GlobalState(
val data: Array[Int] = Array.fill(100)(0),
var stable: Boolean = true,
var x: Int = 5,
var y: Int = 7,
) {
require(
data.length == 100 && (
!stable || (
0 <= x && x <= 100 &&
0 <= y && y <= 100 &&
x + y == 12
)
)
)
}
def move()(implicit state: GlobalState): Unit = {
require(state.stable && state.y > 0)
state.stable = false
state.x += 1
state.y -= 1
state.data(state.y) = 1
state.stable = true
if (state.y > 0) move()
}.ensuring(_ => state.stable)
@cCode.export
def main() {
@ghost implicit val state = newState
implicit val gs = GlobalState()
StdOut.print(gs.x)
StdOut.print(gs.y)
move()
StdOut.print(gs.data(6))
StdOut.print(gs.data(7))
StdOut.print(gs.x)
StdOut.println(gs.y)
}
}