-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from VirtusLab/lambda-unraveler
Lambda unraveler
- Loading branch information
Showing
3 changed files
with
88 additions
and
25 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
22 changes: 22 additions & 0 deletions
22
src/main/scala/com/virtuslab/stacktraces/core/LambdaUnraveler.scala
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,22 @@ | ||
package org.virtuslab.stacktraces.core | ||
|
||
import scala.quoted.* | ||
import scala.tasty.inspector.* | ||
|
||
class LambdaUnraveler private (val q: Quotes)( | ||
private val previousLambdas: List[q.reflect.DefDef], | ||
private val previousFrames: Set[String], | ||
private val counter: Int = 0 | ||
): | ||
def getNextLambdaAndState(using qd: Quotes)(defdefs: List[qd.reflect.DefDef], frameName: String): (Option[qd.reflect.DefDef], LambdaUnraveler) = | ||
if defdefs.nonEmpty && !previousFrames.contains(frameName) && previousLambdas == defdefs then | ||
(Some(defdefs.reverse(counter)), new LambdaUnraveler(q)(previousLambdas, previousFrames + frameName, counter + 1)) | ||
else if defdefs.nonEmpty then | ||
(Some(defdefs.last), new LambdaUnraveler(qd)(defdefs, Set(frameName), 1)) | ||
else | ||
(None, new LambdaUnraveler(qd)(defdefs, Set(frameName), 0)) | ||
|
||
|
||
object LambdaUnraveler: | ||
def apply(q: Quotes)(defdefs: List[q.reflect.DefDef]): LambdaUnraveler = | ||
new LambdaUnraveler(q)(defdefs, Set.empty, 0) |
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