Skip to content

Commit

Permalink
test: reference semantics are odd and need fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 4, 2025
1 parent c2cf85c commit 0f980db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,10 @@ private [deepembedding] class LetFinderState {
/** Has the given parser never been analysed before? */
private [frontend] def notProcessedBefore(p: LazyParsley[_]): Boolean = _preds(p) == 1

// TODO: I think this can just drop the !_recs(p) constraint and it'll just work? (check whether recs get a pred bump)
/** Returns all the non-recursive parsers which are referenced two or more times across the tree. */
/** Returns all the parsers which are referenced two or more times across the tree. */
private [frontend] def lets: Iterable[LazyParsley[_]] = _preds.toSeq.view.collect {
case (p, refs) if refs >= 2 && !_recs(p) => p
} ++ recs
case (p, refs) if refs >= 2 => p
}
/** Returns all the recursive parsers in the tree */
private [frontend] lazy val recs: Set[LazyParsley[_]] = _recs.toSet
/** Returns all the registers used by the parser */
Expand Down
21 changes: 17 additions & 4 deletions parsley/shared/src/test/scala/parsley/CoreTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,27 @@ class CoreTests extends ParsleyTest {
q.parse("aaaabbb") shouldBe a [Success[_]]
}

"flatMap" should "consistently generate a callee-save instruction if needed" in {
"flatMap" should "consistently generate a callee-save instruction if needed" ignore {
import parsley.state._
val r = Ref.make[Int]
val p = pure(7).flatMap { _ =>
r.set(4) *> r.get
val p = unit.flatMap { _ =>
r.update(_ + 1) *> r.get
}
(p *> p).parse("") shouldBe Success(4)
(unit.flatMap(_ => r.set(0)) *> p *> p).parse("") shouldBe Success(2)
}
/*it should "correct nest callee-saving" in {
import parsley.state._
// outer sets up a saved reference within middle, that doesn't use it
// it uses its own. Inner sibling is under a flatMap, so not visible for
// middle, uses the global. After its done and changed global state,
// the second call to middle needs to calleeSave that, which is not
// what would happen...
lazy val inner = ???
lazy val middle = ???
lazy val outer = 0.makeReg { r =>
}
}*/

"span" should "return all the input parsed by a parser, exactly as it was" in {
import parsley.character.whitespaces
Expand Down

0 comments on commit 0f980db

Please sign in to comment.