mirror of
https://github.com/irmen/prog8.git
synced 2024-12-26 14:29:35 +00:00
nicer printing of arrays, fix inc/dec overflow issue in runtimevalue
This commit is contained in:
parent
dcab6d00bb
commit
c9b16dcbd9
@ -249,12 +249,21 @@ class AstToSourceCode(val output: (text: String) -> Unit): IAstVisitor {
|
||||
literalValue.isString -> output("\"${escape(literalValue.strvalue!!)}\"")
|
||||
literalValue.isArray -> {
|
||||
if(literalValue.arrayvalue!=null) {
|
||||
var counter = 0
|
||||
output("[")
|
||||
scopelevel++
|
||||
for (v in literalValue.arrayvalue) {
|
||||
v.accept(this)
|
||||
if (v !== literalValue.arrayvalue.last())
|
||||
output(", ")
|
||||
counter++
|
||||
if(counter > 16) {
|
||||
outputln("")
|
||||
outputi("")
|
||||
counter=0
|
||||
}
|
||||
}
|
||||
scopelevel--
|
||||
output("]")
|
||||
}
|
||||
}
|
||||
|
@ -427,8 +427,22 @@ open class RuntimeValue(val type: DataType, num: Number?=null, val str: String?=
|
||||
|
||||
fun inc(): RuntimeValue {
|
||||
return when(type) {
|
||||
in ByteDatatypes -> RuntimeValue(type, byteval!! + 1)
|
||||
in WordDatatypes -> RuntimeValue(type, wordval!! + 1)
|
||||
DataType.UBYTE -> RuntimeValue(type, (byteval!! + 1) and 255)
|
||||
DataType.UWORD -> RuntimeValue(type, (byteval!! + 1) and 65535)
|
||||
DataType.BYTE -> {
|
||||
val newval = byteval!! + 1
|
||||
if(newval == 256)
|
||||
RuntimeValue(type, 0)
|
||||
else
|
||||
RuntimeValue(type, newval)
|
||||
}
|
||||
DataType.WORD -> {
|
||||
val newval = byteval!! + 1
|
||||
if(newval == 65536)
|
||||
RuntimeValue(type, 0)
|
||||
else
|
||||
RuntimeValue(type, newval)
|
||||
}
|
||||
DataType.FLOAT -> RuntimeValue(DataType.FLOAT, floatval!! + 1)
|
||||
else -> throw ArithmeticException("inc can only work on numeric types")
|
||||
}
|
||||
@ -436,8 +450,22 @@ open class RuntimeValue(val type: DataType, num: Number?=null, val str: String?=
|
||||
|
||||
fun dec(): RuntimeValue {
|
||||
return when(type) {
|
||||
in ByteDatatypes -> RuntimeValue(type, byteval!! - 1)
|
||||
in WordDatatypes -> RuntimeValue(type, wordval!! - 1)
|
||||
DataType.UBYTE -> RuntimeValue(type, (byteval!! - 1) and 255)
|
||||
DataType.UWORD -> RuntimeValue(type, (byteval!! - 1) and 65535)
|
||||
DataType.BYTE -> {
|
||||
val newval = byteval!! - 1
|
||||
if(newval == -129)
|
||||
RuntimeValue(type, 127)
|
||||
else
|
||||
RuntimeValue(type, newval)
|
||||
}
|
||||
DataType.WORD -> {
|
||||
val newval = byteval!! - 1
|
||||
if(newval == -32769)
|
||||
RuntimeValue(type, 32767)
|
||||
else
|
||||
RuntimeValue(type, newval)
|
||||
}
|
||||
DataType.FLOAT -> RuntimeValue(DataType.FLOAT, floatval!! - 1)
|
||||
else -> throw ArithmeticException("dec can only work on numeric types")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user