Skip to content

Commit

Permalink
updated to newer Scala 3 vararg pattern syntax
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Läufer <[email protected]>
  • Loading branch information
klaeufer committed Dec 17, 2023
1 parent 3e12b89 commit 81d5aba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/imperative/StatementParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ object StatementParser extends JavaTokenParsers:
def statement: Parser[Statement] =
ident ~ "=" ~ expr ^^ { case s ~ _ ~ r => Assignment(Variable(s), r) }
| "while" ~ "(" ~> expr ~ ")" ~ statement ^^ { case g ~ _ ~ b => While(g, b) }
| "{" ~> repsep(statement, ",") <~ "}" ^^ { case ss => Sequence(ss: _*) }
| "{" ~> repsep(statement, ",") <~ "}" ^^ { case ss => Sequence(ss*) }

end StatementParser
2 changes: 1 addition & 1 deletion src/main/scala/imperative/execute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Execute:
val rvalue = apply(store)(right)
val lvalue = apply(store)(left)
lvalue.set(rvalue.get)
case Sequence(statements @ _*) =>
case Sequence(statements*) =>
statements.foldLeft(Cell.NULL.asInstanceOf[Cell])((c, s) => apply(store)(s))
case While(guard, body) =>
var gvalue = apply(store)(guard)
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/objects/execute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Execute:
val rvalue = apply(store)(right)
val lvalue = apply(store)(left)
lvalue.set(rvalue.get)
case Sequence(statements @ _*) =>
case Sequence(statements*) =>
statements.foldLeft(Cell.NULL)((c, s) => apply(store)(s))
case While(guard, body) =>
var gvalue = apply(store)(guard)
Expand All @@ -61,14 +61,14 @@ object Execute:
Cell.NULL
case New(Clazz(fields, methods)) =>
// create an object based on the list of field names and methods
val fs = Map(fields.map(field => (field, Cell(0))): _*)
val ms = Map(methods: _*)
val fs = Map(fields.map(field => (field, Cell(0)))*)
val ms = Map(methods*)
Cell(Right((fs, ms)))
case Selection(receiver, field) =>
// assume the expression evaluates to a record (.right)
// and choose the desired field
apply(store)(receiver).get.toOption.get._1(field)
case Message(receiver, method, arguments @ _*) =>
case Message(receiver, method, arguments*) =>
// evaluate receiver expression to a Cell containing an Instance
val rec = apply(store)(receiver)
// look up method in the Instance's second component (method table)
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/records/execute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ object Execute:
val rvalue = apply(store)(right)
val lvalue = apply(store)(left)
lvalue.set(rvalue.get)
case Sequence(statements @ _*) =>
case Sequence(statements*) =>
statements.foldLeft(Cell.NULL)((c, s) => apply(store)(s))
case While(guard, body) =>
var gvalue = apply(store)(guard)
while gvalue.get.isRight || gvalue.get.left.toOption.get != 0 do
apply(store)(body)
gvalue = apply(store)(guard)
Cell.NULL
case New(Clazz(fields @ _*)) =>
case New(Clazz(fields*)) =>
// create an object based on the list of field names in the clazz
Cell(Right(Map(fields.map(field => (field, Cell(0))): _*)))
Cell(Right(Map(fields.map(field => (field, Cell(0)))*)))
case Selection(record, field) =>
// assume the expression evaluates to a record (.right)
// and choose the desired field
Expand Down

0 comments on commit 81d5aba

Please sign in to comment.