made stackvm source a bit more readable

This commit is contained in:
Irmen de Jong 2018-09-26 01:14:10 +02:00
parent 00baec12ab
commit 0f53f87895

View File

@ -602,6 +602,10 @@ open class Instruction(val opcode: Opcode,
override fun toString(): String {
val argStr = arg?.toString() ?: ""
val opcodesWithVarArgument = setOf(
Opcode.INC_VAR, Opcode.DEC_VAR,
Opcode.SHR_VAR, Opcode.SHL_VAR, Opcode.ROL_VAR, Opcode.ROR_VAR,
Opcode.ROL2_VAR, Opcode.ROR2_VAR, Opcode.POP_VAR, Opcode.PUSH_VAR)
val result =
when {
opcode==Opcode.LINE -> "_line ${arg!!.stringvalue}"
@ -609,6 +613,10 @@ open class Instruction(val opcode: Opcode,
val syscall = Syscall.values().find { it.callNr==arg!!.numericValue() }
"syscall $syscall"
}
opcodesWithVarArgument.contains(opcode) -> {
// opcodes that manipulate a variable
"${opcode.toString().toLowerCase()} ${argStr.substring(1, argStr.length-1)}"
}
callLabel==null -> "${opcode.toString().toLowerCase()} $argStr"
else -> "${opcode.toString().toLowerCase()} $callLabel $argStr"
}