All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
encrywm.lib.ESMath.scala Maven / Gradle / Ivy
package encrywm.lib
import encrywm.ast.Ast
import encrywm.ast.Ast.OPERATOR._
import encrywm.ast.Ast.{EXPR, OPERATOR}
import encrywm.frontend.semantics.error.ZeroDivisionError
object ESMath {
import Types._
val BinaryOperationResults: Seq[(Ast.OPERATOR, (ESType, ESType), ESType)] = Seq(
(Add, (ESInt, ESInt), ESInt),
(Add, (ESInt, ESLong), ESLong),
(Add, (ESLong, ESInt), ESLong),
(Add, (ESLong, ESLong), ESLong),
(Mult, (ESInt, ESInt), ESInt),
(Mult, (ESInt, ESLong), ESLong),
(Mult, (ESLong, ESInt), ESLong),
(Mult, (ESLong, ESLong), ESLong),
(Div, (ESInt, ESInt), ESInt),
(Div, (ESInt, ESLong), ESLong),
(Div, (ESLong, ESInt), ESLong),
(Div, (ESLong, ESLong), ESLong),
)
def ensureZeroDivision(op: Ast.OPERATOR, operand2: Ast.EXPR): Unit = {
operand2 match {
case int: EXPR.IntConst
if (op == OPERATOR.Div || op == OPERATOR.FloorDiv) && int.n == 0 =>
throw ZeroDivisionError
case long: EXPR.LongConst
if (op == OPERATOR.Div || op == OPERATOR.FloorDiv) && long.n == 0L =>
throw ZeroDivisionError
case _ => // Do nothing.
}
}
}