-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
216 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.Environment | ||
import org.kframework.kale.{DomainValue, Environment, Label, builtin} | ||
import org.kframework.kale.standard.ReferenceLabel | ||
|
||
trait HasBOOLEAN { | ||
self: Environment => | ||
|
||
val BOOLEAN = new ReferenceLabel[Boolean]("Boolean")(this) { | ||
case class BOOLEAN()(implicit penv: Environment) extends Module("BOOLEAN") { | ||
val Boolean = new ReferenceLabel[Boolean]("Boolean") { | ||
override protected[this] def internalInterpret(s: String): Boolean = s.toBoolean | ||
} | ||
|
||
override val all: Set[Label] = Set(Boolean) | ||
} | ||
|
||
trait importBOOLEAN { | ||
protected val env: Environment | ||
|
||
val BOOLEAN = builtin.BOOLEAN()(env) | ||
|
||
implicit def toBoolean(b: Boolean): DomainValue[Boolean] = BOOLEAN.Boolean(b) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.standard.ReferenceLabel | ||
import org.kframework.kale.{Environment, FunctionLabel2, Term} | ||
import org.kframework.kale.util.Named | ||
import org.kframework.kale.{FunctionLabel2, _} | ||
|
||
trait HasDOUBLE { | ||
self: Environment => | ||
|
||
val DOUBLE = new ReferenceLabel[Double]("Double")(this) { | ||
case class DOUBLE()(implicit protected val penv: Environment) extends Module("DOUBLE") { | ||
val Double = new ReferenceLabel[Double]("Double")(penv) { | ||
override protected[this] def internalInterpret(s: String): Double = s.toDouble | ||
} | ||
} | ||
|
||
trait HasDOUBLEdiv { | ||
self: Environment with HasDOUBLE => | ||
|
||
val DOUBLEdiv = new HasEnvironment with FunctionLabel2 { | ||
val div = new Named("_/Double_") with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (_, DOUBLE(0)) => None | ||
case (DOUBLE(0), b) if b.isGround => Some(DOUBLE(0)) | ||
case (DOUBLE(a), DOUBLE(b)) => Some(DOUBLE(a / b)) | ||
case (_, Double(0)) => None | ||
case (Double(0), b) if b.isGround => Some(Double(0)) | ||
case (Double(a), Double(b)) => Some(Double(a / b)) | ||
case _ => None | ||
} | ||
|
||
override val name: String = "_/Double_" | ||
} | ||
|
||
override lazy val all: Set[Label] = Set(Double) | ||
} | ||
|
||
trait importDOUBLE { | ||
protected val env: Environment | ||
|
||
val DOUBLE = builtin.DOUBLE()(env) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.{DomainValue, Environment} | ||
import org.kframework.kale.{DomainValue, Environment, Label} | ||
import org.kframework.kale.standard.ReferenceLabel | ||
import org.kframework.kale.builtin | ||
|
||
trait HasID { | ||
self: Environment => | ||
|
||
val ID = new ReferenceLabel[Symbol]("ID")(this) { | ||
case class ID()(implicit protected val penv: Environment) extends Module("ID") { | ||
val Id = new ReferenceLabel[Symbol]("Id")(penv) { | ||
override protected[this] def internalInterpret(s: String): Symbol = Symbol(s) | ||
} | ||
override val all: Set[Label] = Set(Id) | ||
} | ||
|
||
trait importID { | ||
protected val env: Environment | ||
|
||
val ID = builtin.ID()(env) | ||
|
||
implicit def toID(s: Symbol): DomainValue[Symbol] = ID.Id(s) | ||
|
||
implicit def toID(s: Symbol): DomainValue[Symbol] = ID(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,34 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.standard.ReferenceLabel | ||
import org.kframework.kale.util.Named | ||
import org.kframework.kale._ | ||
import org.kframework.kale.standard.ReferenceLabel | ||
|
||
trait HasINT { | ||
self: Environment => | ||
|
||
val INT = new ReferenceLabel[Int]("Int")(this) { | ||
override protected[this] def internalInterpret(s: String): Int = s.toInt | ||
} | ||
|
||
implicit def toINT(i: Int): DomainValue[Int] = INT(i) | ||
} | ||
|
||
trait HasINTbop extends HasINTplus with HasINTminus with HasINTmult with HasINTdiv with HasINTmod { self: Environment => } | ||
|
||
trait HasINTplus extends HasINT { self: Environment => | ||
val intPlus = new Named("_+Int_")(self) with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(INT(a + b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "+" | ||
} | ||
} | ||
|
||
trait HasINTminus extends HasINT { self: Environment => | ||
val intMinus = new Named("_-Int_")(self) with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(INT(a + b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "-" | ||
} | ||
} | ||
|
||
trait HasINTmult extends HasINT { self: Environment => | ||
val intMult = new Named("_*Int_")(self) with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(INT(a * b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "*" | ||
} | ||
} | ||
case class INT(implicit protected val penv: Environment with importBOOLEAN) extends Module("INT") { | ||
|
||
trait HasINTdiv extends HasINT { self: Environment => | ||
val intDiv = new Named("_/Int_")(self) with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
//case (_, INT(0)) => None | ||
//case (INT(0), b) if b.isGround => Some(INT(0)) | ||
case (INT(a), INT(b)) => Some(INT(a / b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "div" // integer division, while "/" is real division. | ||
} | ||
} | ||
import penv._ | ||
|
||
trait HasINTmod extends HasINT { self: Environment => | ||
val intMod = new Named("_%Int_")(self) with FunctionLabel2 { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(INT(a % b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "mod" // z3 also has "rem", remainder. | ||
val Int = new ReferenceLabel[Int]("Int") { | ||
override protected[this] def internalInterpret(s: String): Int = s.toInt | ||
} | ||
} | ||
|
||
trait HasINTcmp extends HasINTlt with HasINTle with HasINTgt with HasINTge { self: Environment => } | ||
val plus = PrimitiveFunction2[Int]("_+Int_", Int, _ + _) | ||
val minus = PrimitiveFunction2[Int]("_-Int_", Int, _ - _) | ||
val mult = PrimitiveFunction2[Int]("_*Int_", Int, _ * _) | ||
val div = PrimitiveFunction2[Int]("_/Int_", Int, _ / _) | ||
val mod = PrimitiveFunction2[Int]("_%Int_", Int, _ / _) | ||
val lt = PrimitiveFunction2[Int, Boolean]("_<Int_", Int, BOOLEAN.Boolean, _ < _) | ||
val le = PrimitiveFunction2[Int, Boolean]("_<=Int_", Int, BOOLEAN.Boolean, _ <= _) | ||
val gt = PrimitiveFunction2[Int, Boolean]("_>Int_", Int, BOOLEAN.Boolean, _ > _) | ||
val ge = PrimitiveFunction2[Int, Boolean]("_>=Int_", Int, BOOLEAN.Boolean, _ >= _) | ||
|
||
trait HasINTlt extends HasINT with HasBOOLEAN { self: Environment => | ||
val intLt = new Named("_<Int_")(self) with FunctionLabel2 with Z3Builtin { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(BOOLEAN(a < b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "<" | ||
} | ||
lazy val all = Set(Int, plus, minus, mult, div, mod, lt, le, gt, ge) | ||
} | ||
|
||
trait HasINTle extends HasINT with HasBOOLEAN { self: Environment => | ||
val intLe = new Named("_<=Int_")(self) with FunctionLabel2 with Z3Builtin { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(BOOLEAN(a <= b)) | ||
case _ => None | ||
} | ||
override def smtName: String = "<=" | ||
} | ||
} | ||
trait importINT { | ||
protected val env: Environment with importBOOLEAN | ||
val BOOLEAN: builtin.BOOLEAN | ||
|
||
trait HasINTgt extends HasINT with HasBOOLEAN { self: Environment => | ||
val intGt = new Named("_>Int_")(self) with FunctionLabel2 with Z3Builtin { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(BOOLEAN(a > b)) | ||
case _ => None | ||
} | ||
override def smtName: String = ">" | ||
} | ||
} | ||
val INT = builtin.INT()(env) | ||
|
||
trait HasINTge extends HasINT with HasBOOLEAN { self: Environment => | ||
val intGe = new Named("_>=Int_")(self) with FunctionLabel2 with Z3Builtin { | ||
def f(_1: Term, _2: Term): Option[Term] = (_1, _2) match { | ||
case (INT(a), INT(b)) => Some(BOOLEAN(a >= b)) | ||
case _ => None | ||
} | ||
override def smtName: String = ">=" | ||
} | ||
implicit def toINT(i: Int): DomainValue[Int] = INT.Int(i) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.{Environment, Label, util} | ||
|
||
abstract class Module(val moduleName: String)(implicit val env: Environment) { | ||
|
||
private def fullname(localName: String): String = localName + "@" + moduleName | ||
|
||
protected abstract class LocalName[E <: Environment](val localName: String) extends util.Named(fullname(localName)) | ||
|
||
val all: Set[Label] | ||
|
||
private lazy val labelName2Label = all.map(l => (l.name, l)).toMap | ||
|
||
def apply(localName: String): Label = labelName2Label(fullname(localName)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
package org.kframework.kale.builtin | ||
|
||
import org.kframework.kale.{DomainValue, Environment} | ||
import org.kframework.kale.{DomainValue, Environment, Label} | ||
import org.kframework.kale.standard.ReferenceLabel | ||
import org.kframework.kale.builtin | ||
|
||
trait HasSTRING { | ||
self: Environment => | ||
|
||
val STRING = new ReferenceLabel[String]("String")(this) { | ||
case class STRING()(implicit protected val penv: Environment) extends Module("STRING") { | ||
val String = new ReferenceLabel[String]("String")(penv) { | ||
override protected[this] def internalInterpret(s: String): String = s | ||
} | ||
override val all: Set[Label] = Set(String) | ||
} | ||
|
||
trait importSTRING { | ||
protected val env: Environment | ||
|
||
val STRING = builtin.STRING()(env) | ||
|
||
implicit def toSTRING(s: String): DomainValue[String] = STRING.String(s) | ||
|
||
implicit def toSTRING(s: String): DomainValue[String] = STRING(s) | ||
} |
Oops, something went wrong.