Add local string Buffer, fix speed issues

This commit is contained in:
Jacob
2018-11-20 00:35:39 -05:00
parent aa68debd81
commit af2f0442bf
6 changed files with 54 additions and 11 deletions

View File

@@ -27,7 +27,9 @@ class B93Interpreter : Interpreter {
override val outputChanged: Event<OutputEvent> = Event() override val outputChanged: Event<OutputEvent> = Event()
override val stdInput = LinkedList<Char>() override val stdInput = LinkedList<Char>()
override val stdOutput = LinkedList<Char>() override val stdOutput = LinkedList<String>()
private var outBuf: StringBuffer = StringBuffer()
private var bufLimit = 10
private val fungeMods = HashMap<Vec,Value>() private val fungeMods = HashMap<Vec,Value>()
@@ -174,13 +176,18 @@ class B93Interpreter : Interpreter {
val vv = pop() val vv = pop()
val v = vv.value val v = vv.value
val out = when (type) { val out = when (type) {
'.' -> v.toString().toList() + ' ' '.' -> v.toString() + ' '
',' -> listOf(v.toChar()) ',' -> v.toChar().toString()
else -> listOf() else -> null
} }
stdOutput.addAll(out) return out?.let{
outputChanged.invoke(OutputEvent()) outBuf.append(it)
return true if (outBuf.length > bufLimit) {
stdOutput.add(outBuf.toString())
outBuf.delete(0, outBuf.length)
outputChanged.invoke(OutputEvent())
}
} != null
} }
private fun stepIP(): Boolean { private fun stepIP(): Boolean {
@@ -255,6 +262,9 @@ class B93Interpreter : Interpreter {
} }
private fun terminate(): Boolean { private fun terminate(): Boolean {
stdOutput.add(outBuf.toString())
outBuf.delete(0, outBuf.length)
outputChanged.invoke(OutputEvent())
ip.mode = IpMode.Inactive ip.mode = IpMode.Inactive
return true return true
} }

View File

@@ -23,7 +23,7 @@ interface Interpreter {
val outputChanged: Event<OutputEvent> val outputChanged: Event<OutputEvent>
val stdInput: Queue<Char> val stdInput: Queue<Char>
val stdOutput: Queue<Char> val stdOutput: Queue<String>
/** /**
* @return If [ip] is inactive after this step, indicating execution has halted, then return `false` * @return If [ip] is inactive after this step, indicating execution has halted, then return `false`

View File

@@ -33,7 +33,7 @@ class ActionView(val interp: Interpreter, val ioView: IOView) : View() {
button("run") { button("run") {
setOnAction { setOnAction {
runTimeline.rate = 1000.0 runTimeline.rate = 10000000.0
runTimeline.playFromStart() runTimeline.playFromStart()
} }
} }

View File

@@ -14,5 +14,7 @@ class CodeView(val interp: Interpreter) : View() {
} }
override val root = textarea(srcProperty) { override val root = textarea(srcProperty) {
prefRowCount = 25
prefColumnCount = 80
} }
} }

View File

@@ -27,6 +27,35 @@ class EditorView : View("Befide") {
} }
init { init {
codeView.src = """64+"!dlroW ,olleH">:#,_@""" codeView.src = """>84*>:#v_55+"ude.ub@yelruta">:#,_@>188*+>\02p\12p\:22p#v_${'$'} 55+,1- v
^ 0 v +1\ _^#-+*< >22g02g*"_@"*-!1- #v_v>
>:>::3g: ,\188 ^^ -1\g21\g22<p3\"_":<
________________________________@_________________________________^ p3\"@":<"""
// codeView.src = """--------------------------------------------------------------------------------
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// |-
// """.trimMargin()
} }
} }

View File

@@ -16,9 +16,11 @@ class IOView(val interp: Interpreter) : View() {
init { init {
interp.outputChanged += { interp.outputChanged += {
var str = ""
while (!interp.stdOutput.isEmpty()) { while (!interp.stdOutput.isEmpty()) {
output += interp.stdOutput.remove() str += interp.stdOutput.remove()
} }
output += str
} }
// add listeners to interp, handle streams, idk // add listeners to interp, handle streams, idk
} }