Skip to content

Commit d59b095

Browse files
committed
Move TrampolineContinuation to Dsl
1 parent f815a8d commit d59b095

File tree

2 files changed

+30
-30
lines changed
  • Dsl/src/main/scala/com/thoughtworks/dsl
  • keywords-Shift/src/main/scala/com/thoughtworks/dsl/keywords

2 files changed

+30
-30
lines changed

Dsl/src/main/scala/com/thoughtworks/dsl/Dsl.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ object Dsl extends LowPriorityDsl0 {
126126
) =:= Dsl[Keyword, Domain, Value] =
127127
summon
128128

129+
private[dsl] abstract class TrampolineContinuation[LeftDomain]
130+
extends (LeftDomain !! Throwable) {
131+
protected def step(): LeftDomain !! Throwable
132+
133+
@tailrec
134+
private final def last(): LeftDomain !! Throwable = {
135+
step() match {
136+
case trampoline: TrampolineContinuation[LeftDomain] =>
137+
trampoline.last()
138+
case notTrampoline =>
139+
notTrampoline
140+
}
141+
}
142+
143+
final def apply(handler: Throwable => LeftDomain): LeftDomain = {
144+
val protectedContinuation: LeftDomain !! Throwable =
145+
try {
146+
last()
147+
} catch {
148+
case NonFatal(e) =>
149+
return handler(e)
150+
}
151+
protectedContinuation(handler)
152+
}
153+
}
154+
129155
trait IsStackSafe[Domain]
130156
object IsStackSafe extends IsStackSafe.LowPriority0:
131157
private[IsStackSafe] trait LowPriority0:

keywords-Shift/src/main/scala/com/thoughtworks/dsl/keywords/Shift.scala

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -142,37 +142,11 @@ object Shift extends LowPriorityShift0 {
142142

143143
}
144144

145-
private abstract class TrampolineContinuation[LeftDomain]
146-
extends (LeftDomain !! Throwable) {
147-
protected def step(): LeftDomain !! Throwable
148-
149-
@tailrec
150-
private final def last(): LeftDomain !! Throwable = {
151-
step() match {
152-
case trampoline: TrampolineContinuation[LeftDomain] =>
153-
trampoline.last()
154-
case notTrampoline =>
155-
notTrampoline
156-
}
157-
}
158-
159-
final def apply(handler: Throwable => LeftDomain): LeftDomain = {
160-
val protectedContinuation: LeftDomain !! Throwable =
161-
try {
162-
last()
163-
} catch {
164-
case NonFatal(e) =>
165-
return handler(e)
166-
}
167-
protectedContinuation(handler)
168-
}
169-
}
170-
171145
private def suspend[LeftDomain, Value](
172146
continuation: LeftDomain !! Throwable !! Value,
173147
handler: Value => LeftDomain !! Throwable
174-
): TrampolineContinuation[LeftDomain] =
175-
new TrampolineContinuation[LeftDomain] {
148+
): Dsl.TrampolineContinuation[LeftDomain] =
149+
new Dsl.TrampolineContinuation[LeftDomain] {
176150
protected def step() = continuation(handler)
177151
}
178152

@@ -192,8 +166,8 @@ object Shift extends LowPriorityShift0 {
192166
handler: Value => LeftDomain !! Throwable !! RightDomain,
193167
value: Value,
194168
continue: RightDomain => LeftDomain !! Throwable
195-
): TrampolineContinuation[LeftDomain] =
196-
new TrampolineContinuation[LeftDomain] {
169+
): Dsl.TrampolineContinuation[LeftDomain] =
170+
new Dsl.TrampolineContinuation[LeftDomain] {
197171
protected def step() = {
198172
handler(value)(continue)
199173
}

0 commit comments

Comments
 (0)