Add total reset to repl history and state interfaces
This commit is contained in:
+9
-1
@@ -52,11 +52,19 @@ open class AggregatedReplStateHistory<T1, T2>(val history1: IReplStageHistory<T1
|
||||
ReplHistoryRecord(r1.id, r1.item to r2.item)
|
||||
}
|
||||
|
||||
override fun reset(): Iterable<ILineId> = lock.write {
|
||||
assertSameSize()
|
||||
val i1 = history1.reset().toList()
|
||||
val i2 = history2.reset().toList()
|
||||
if (i1 != i2) throw IllegalStateException("Aggregated history reset lines mismatch: $i1 != $i2")
|
||||
i1
|
||||
}
|
||||
|
||||
override fun resetTo(id: ILineId): Iterable<ILineId> = lock.write {
|
||||
assertSameSize()
|
||||
val i1 = history1.resetTo(id).toList()
|
||||
val i2 = history2.resetTo(id).toList()
|
||||
if (i1 != i2) throw IllegalStateException("Aggregated history resetted lines mismatch: $i1 != $i2")
|
||||
if (i1 != i2) throw IllegalStateException("Aggregated history reset lines mismatch: $i1 != $i2")
|
||||
i1
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,14 @@ open class BasicReplStageHistory<T>(override val lock: ReentrantReadWriteLock =
|
||||
|
||||
override fun pop(): ReplHistoryRecord<T>? = lock.write { if (isEmpty()) null else removeAt(lastIndex) }
|
||||
|
||||
override fun reset(): Iterable<ILineId> {
|
||||
lock.write {
|
||||
val removed = map { it.id }
|
||||
clear()
|
||||
return removed
|
||||
}
|
||||
}
|
||||
|
||||
override fun resetTo(id: ILineId): Iterable<ILineId> {
|
||||
lock.write {
|
||||
val idx = indexOfFirst { it.id == id }
|
||||
|
||||
+7
-2
@@ -46,8 +46,13 @@ class GenericReplCompilingEvaluator(val compiler: ReplCompiler,
|
||||
aggregatedState.apply {
|
||||
lock.write {
|
||||
if (state1.history.size > state2.history.size) {
|
||||
state2.history.peek()?.let {
|
||||
state1.history.resetTo(it.id)
|
||||
if (state2.history.size == 0) {
|
||||
state1.history.reset()
|
||||
}
|
||||
else {
|
||||
state2.history.peek()?.let {
|
||||
state1.history.resetTo(it.id)
|
||||
}
|
||||
}
|
||||
assert(state1.history.size == state2.history.size)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,13 @@ class ReplHistory<T>(startingHistory: CompiledHistoryList<T> = emptyList()) : Se
|
||||
}
|
||||
}
|
||||
|
||||
/* resets back complete history and returns the lines removed */
|
||||
fun reset(): SourceHistoryList<T> {
|
||||
val removed = history.map { Pair(it.first.source, it.second) }
|
||||
history.clear()
|
||||
return removed
|
||||
}
|
||||
|
||||
/* resets back to a previous line number and returns the lines removed */
|
||||
fun resetToLine(lineNumber: Int): SourceHistoryList<T> {
|
||||
val removed = arrayListOf<SourceHistoryItem<T>>()
|
||||
|
||||
@@ -41,6 +41,8 @@ interface IReplStageHistory<T> : List<ReplHistoryRecord<T>> {
|
||||
else null
|
||||
}
|
||||
|
||||
fun reset(): Iterable<ILineId>
|
||||
|
||||
fun resetTo(id: ILineId): Iterable<ILineId>
|
||||
|
||||
val lock: ReentrantReadWriteLock
|
||||
|
||||
Reference in New Issue
Block a user