Skip to content

Commit

Permalink
Support 64bit integer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
b-studios committed Aug 17, 2023
1 parent cd01517 commit 5a192da
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions effekt/shared/src/main/scala/effekt/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ class EffektParsers(positions: Positions) extends EffektLexers(positions) {
double | int | bool | unit | string

lazy val int = integerLiteral.flatMap { n =>
try { val number = n.toInt;
try { val number = n.toLong;
success(IntLit(number).withPositionOf(n))
} catch { case e => failure("Not a 32bit integer literal.") }
} catch { case e => failure("Not a 64bit integer literal.") }
}
lazy val bool = `true` ^^^ BooleanLit(true) | `false` ^^^ BooleanLit(false)
lazy val unit = literal("()") ^^^ UnitLit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case class Parameter(typ: Type, name: String)
sealed trait Operand
object Operand {
case class LocalReference(tpe: Type, name: String) extends Operand
case class ConstantInt(n: Int) extends Operand
case class ConstantInt(n: Long) extends Operand
case class ConstantDouble(x: Double) extends Operand
case class ConstantAggregateZero(typ: Type) extends Operand
case class ConstantGlobal(tpe: Type, name: String) extends Operand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ object Transformer {
Construct(variable, builtins.Unit, List(), k(variable))
}

case lifted.Literal(value: Int, _) =>
case lifted.Literal(value: Long, _) =>
val variable = Variable(freshName("x"), Type.Int());
Binding { k =>
LiteralInt(variable, value, k(variable))
Expand Down
2 changes: 1 addition & 1 deletion effekt/shared/src/main/scala/effekt/machine/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ enum Statement {
/**
* let x = 42; s
*/
case LiteralInt(name: Variable, value: Int, rest: Statement)
case LiteralInt(name: Variable, value: Long, rest: Statement)

case LiteralDouble(name: Variable, value: Double, rest: Statement)
case LiteralUTF8String(name: Variable, utf8: Array[Byte], rest: Statement)
Expand Down
2 changes: 1 addition & 1 deletion effekt/shared/src/main/scala/effekt/source/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export Term.*
// Smart Constructors for literals
// -------------------------------
def UnitLit(): Literal = Literal((), symbols.builtins.TUnit)
def IntLit(value: Int): Literal = Literal(value, symbols.builtins.TInt)
def IntLit(value: Long): Literal = Literal(value, symbols.builtins.TInt)
def BooleanLit(value: Boolean): Literal = Literal(value, symbols.builtins.TBoolean)
def DoubleLit(value: Double): Literal = Literal(value, symbols.builtins.TDouble)
def StringLit(value: String): Literal = Literal(value, symbols.builtins.TString)
Expand Down
6 changes: 3 additions & 3 deletions examples/neg/parsing/numbers.check
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[error] examples/neg/parsing/numbers.effekt:2:21: Not a 32bit integer literal.
println(2147483648)
^
[error] examples/neg/parsing/numbers.effekt:2:30: Not a 64bit integer literal.
println(9223372036854775808)
^
2 changes: 1 addition & 1 deletion examples/neg/parsing/numbers.effekt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
def main() =
println(2147483648)
println(9223372036854775808)

0 comments on commit 5a192da

Please sign in to comment.