Skip to content
Snippets Groups Projects
Commit 643d6fb5 authored by Régis Blanc's avatar Régis Blanc
Browse files

io library using implicit state

parent 99e43b6b
No related branches found
No related tags found
No related merge requests found
/* Copyright 2009-2016 EPFL, Lausanne */
package leon.io
import leon.annotation._
object StdIn {
@library
case class State(var seed: BigInt)
@library
def newState: State = State(0)
@library
@isabelle.noBody()
def readInt(implicit state: State): Int = {
state.seed += 1
nativeReadInt
}
@library
@extern
@isabelle.noBody()
private def nativeReadInt(implicit state: State): Int = {
scala.io.StdIn.readInt
} ensuring((x: Int) => true)
@library
@isabelle.noBody()
def readBigInt(implicit state: State): BigInt = {
state.seed += 1
nativeReadBigInt
}
@library
@extern
@isabelle.noBody()
private def nativeReadBigInt(implicit state: State): BigInt = {
BigInt(scala.io.StdIn.readInt)
} ensuring((x: BigInt) => true)
@library
@isabelle.noBody()
def readBoolean(implicit state: State): Boolean = {
state.seed += 1
nativeReadBoolean
}
@library
@extern
@isabelle.noBody()
private def nativeReadBoolean(implicit state: State): Boolean = {
scala.io.StdIn.readBoolean
} ensuring((x: Boolean) => true)
}
import leon.io._
object StdIn1 {
def alwaysPos: Int = {
implicit val state = StdIn.newState
StdIn.readInt
} ensuring(_ >= 0)
}
import leon.io._
object StdIn2 {
def anyTwoNumbers: Boolean = {
implicit val state = StdIn.newState
val n1 = StdIn.readInt
val n2 = StdIn.readInt
n1 == n2
} ensuring(res => res)
}
import leon.io._
object StdIn3 {
//should be invalid because of MinInt
def abs: Int = {
implicit val state = StdIn.newState
val n = StdIn.readInt
if(n < 0) -n else n
} ensuring(_ >= 0)
}
import leon.io._
object StdIn4 {
def readBoolCanBeFalse: Boolean = {
implicit val state = StdIn.newState
StdIn.readBoolean
} ensuring(res => res)
}
import leon.io._
object StdIn1 {
def abs: BigInt = {
implicit val state = StdIn.newState
val n = StdIn.readBigInt
if(n < 0) -n else n
} ensuring(_ >= 0)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment