mirror of
https://github.com/irmen/prog8.git
synced 2024-12-27 20:33:39 +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.isString -> output("\"${escape(literalValue.strvalue!!)}\"")
|
||||||
literalValue.isArray -> {
|
literalValue.isArray -> {
|
||||||
if(literalValue.arrayvalue!=null) {
|
if(literalValue.arrayvalue!=null) {
|
||||||
|
var counter = 0
|
||||||
output("[")
|
output("[")
|
||||||
|
scopelevel++
|
||||||
for (v in literalValue.arrayvalue) {
|
for (v in literalValue.arrayvalue) {
|
||||||
v.accept(this)
|
v.accept(this)
|
||||||
if (v !== literalValue.arrayvalue.last())
|
if (v !== literalValue.arrayvalue.last())
|
||||||
output(", ")
|
output(", ")
|
||||||
|
counter++
|
||||||
|
if(counter > 16) {
|
||||||
|
outputln("")
|
||||||
|
outputi("")
|
||||||
|
counter=0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
scopelevel--
|
||||||
output("]")
|
output("]")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -427,8 +427,22 @@ open class RuntimeValue(val type: DataType, num: Number?=null, val str: String?=
|
|||||||
|
|
||||||
fun inc(): RuntimeValue {
|
fun inc(): RuntimeValue {
|
||||||
return when(type) {
|
return when(type) {
|
||||||
in ByteDatatypes -> RuntimeValue(type, byteval!! + 1)
|
DataType.UBYTE -> RuntimeValue(type, (byteval!! + 1) and 255)
|
||||||
in WordDatatypes -> RuntimeValue(type, wordval!! + 1)
|
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)
|
DataType.FLOAT -> RuntimeValue(DataType.FLOAT, floatval!! + 1)
|
||||||
else -> throw ArithmeticException("inc can only work on numeric types")
|
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 {
|
fun dec(): RuntimeValue {
|
||||||
return when(type) {
|
return when(type) {
|
||||||
in ByteDatatypes -> RuntimeValue(type, byteval!! - 1)
|
DataType.UBYTE -> RuntimeValue(type, (byteval!! - 1) and 255)
|
||||||
in WordDatatypes -> RuntimeValue(type, wordval!! - 1)
|
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)
|
DataType.FLOAT -> RuntimeValue(DataType.FLOAT, floatval!! - 1)
|
||||||
else -> throw ArithmeticException("dec can only work on numeric types")
|
else -> throw ArithmeticException("dec can only work on numeric types")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user