From 5a192dab2bc979904c76cf89b9a5935dc98836de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Brachtha=CC=88user?= Date: Thu, 17 Aug 2023 10:44:01 +0200 Subject: [PATCH] Support 64bit integer literals --- effekt/shared/src/main/scala/effekt/Parser.scala | 4 ++-- .../shared/src/main/scala/effekt/generator/llvm/Tree.scala | 2 +- .../shared/src/main/scala/effekt/machine/Transformer.scala | 2 +- effekt/shared/src/main/scala/effekt/machine/Tree.scala | 2 +- effekt/shared/src/main/scala/effekt/source/Tree.scala | 2 +- examples/neg/parsing/numbers.check | 6 +++--- examples/neg/parsing/numbers.effekt | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/effekt/shared/src/main/scala/effekt/Parser.scala b/effekt/shared/src/main/scala/effekt/Parser.scala index d0d4aa7d7..8d64c5d3d 100644 --- a/effekt/shared/src/main/scala/effekt/Parser.scala +++ b/effekt/shared/src/main/scala/effekt/Parser.scala @@ -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() diff --git a/effekt/shared/src/main/scala/effekt/generator/llvm/Tree.scala b/effekt/shared/src/main/scala/effekt/generator/llvm/Tree.scala index 7a143d086..caab6b4b5 100644 --- a/effekt/shared/src/main/scala/effekt/generator/llvm/Tree.scala +++ b/effekt/shared/src/main/scala/effekt/generator/llvm/Tree.scala @@ -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 diff --git a/effekt/shared/src/main/scala/effekt/machine/Transformer.scala b/effekt/shared/src/main/scala/effekt/machine/Transformer.scala index 606a2a85a..a90011fc9 100644 --- a/effekt/shared/src/main/scala/effekt/machine/Transformer.scala +++ b/effekt/shared/src/main/scala/effekt/machine/Transformer.scala @@ -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)) diff --git a/effekt/shared/src/main/scala/effekt/machine/Tree.scala b/effekt/shared/src/main/scala/effekt/machine/Tree.scala index 49a6a4d23..a51081fd6 100644 --- a/effekt/shared/src/main/scala/effekt/machine/Tree.scala +++ b/effekt/shared/src/main/scala/effekt/machine/Tree.scala @@ -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) diff --git a/effekt/shared/src/main/scala/effekt/source/Tree.scala b/effekt/shared/src/main/scala/effekt/source/Tree.scala index 006bf536c..e06b7abfb 100644 --- a/effekt/shared/src/main/scala/effekt/source/Tree.scala +++ b/effekt/shared/src/main/scala/effekt/source/Tree.scala @@ -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) diff --git a/examples/neg/parsing/numbers.check b/examples/neg/parsing/numbers.check index e4668a6c8..b79c38732 100644 --- a/examples/neg/parsing/numbers.check +++ b/examples/neg/parsing/numbers.check @@ -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) + ^ diff --git a/examples/neg/parsing/numbers.effekt b/examples/neg/parsing/numbers.effekt index c69813c42..02ebe5f50 100644 --- a/examples/neg/parsing/numbers.effekt +++ b/examples/neg/parsing/numbers.effekt @@ -1,3 +1,3 @@ def main() = - println(2147483648) + println(9223372036854775808)