mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
tweaks
This commit is contained in:
parent
8446dd567b
commit
05fc6fa47a
@ -413,18 +413,20 @@ class AstChecker(private val namespace: INameScope,
|
|||||||
when(decl.type) {
|
when(decl.type) {
|
||||||
VarDeclType.VAR, VarDeclType.CONST -> {
|
VarDeclType.VAR, VarDeclType.CONST -> {
|
||||||
if (decl.value == null) {
|
if (decl.value == null) {
|
||||||
if (decl.datatype in NumericDatatypes) {
|
when {
|
||||||
// initialize numeric var with value zero by default.
|
decl.datatype in NumericDatatypes -> {
|
||||||
val litVal = LiteralValue(DataType.UBYTE, 0, position = decl.position)
|
// initialize numeric var with value zero by default.
|
||||||
litVal.parent = decl
|
val litVal = LiteralValue(DataType.UBYTE, 0, position = decl.position)
|
||||||
decl.value = litVal
|
litVal.parent = decl
|
||||||
}
|
decl.value = litVal
|
||||||
else if(decl.type==VarDeclType.VAR) {
|
}
|
||||||
val litVal = LiteralValue(decl.datatype, heapId = heapStringSentinel, position=decl.position) // point to the sentinel heap value instead
|
decl.type==VarDeclType.VAR -> {
|
||||||
litVal.parent=decl
|
val litVal = LiteralValue(decl.datatype, heapId = heapStringSentinel, position=decl.position) // point to the sentinel heap value instead
|
||||||
decl.value = litVal
|
litVal.parent=decl
|
||||||
} else {
|
decl.value = litVal
|
||||||
err("var/const declaration needs a compile-time constant initializer value for type ${decl.datatype}") // const fold should have provided it!
|
}
|
||||||
|
else -> err("var/const declaration needs a compile-time constant initializer value for type ${decl.datatype}")
|
||||||
|
// const fold should have provided it!
|
||||||
}
|
}
|
||||||
return super.process(decl)
|
return super.process(decl)
|
||||||
}
|
}
|
||||||
|
@ -1055,9 +1055,9 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
|||||||
// store A in target
|
// store A in target
|
||||||
val storeByte = when(segment[2].callLabel) {
|
val storeByte = when(segment[2].callLabel) {
|
||||||
"A" -> ""
|
"A" -> ""
|
||||||
"X" -> " tax"
|
"X" -> "tax"
|
||||||
"Y" -> " tya"
|
"Y" -> "tya"
|
||||||
else -> " sta ${segment[2].callLabel}"
|
else -> "sta ${segment[2].callLabel}"
|
||||||
}
|
}
|
||||||
|
|
||||||
" $setupPtr | $loadByte | $storeByte"
|
" $setupPtr | $loadByte | $storeByte"
|
||||||
|
@ -363,7 +363,7 @@ private fun builtinLen(args: List<IExpression>, position: Position, namespace:IN
|
|||||||
private fun numericLiteral(value: Number, position: Position): LiteralValue {
|
private fun numericLiteral(value: Number, position: Position): LiteralValue {
|
||||||
val floatNum=value.toDouble()
|
val floatNum=value.toDouble()
|
||||||
val tweakedValue: Number =
|
val tweakedValue: Number =
|
||||||
if(floatNum==Math.floor(floatNum) && floatNum in -32768..65535)
|
if(floatNum==Math.floor(floatNum) && (floatNum>=-32768 && floatNum<=65535))
|
||||||
floatNum.toInt() // we have an integer disguised as a float.
|
floatNum.toInt() // we have an integer disguised as a float.
|
||||||
else
|
else
|
||||||
floatNum
|
floatNum
|
||||||
|
@ -100,7 +100,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
val fillArray = IntArray(size) { _ -> fillvalue }
|
val fillArray = IntArray(size) { fillvalue }
|
||||||
val heapId = heap.add(decl.datatype, fillArray)
|
val heapId = heap.add(decl.datatype, fillArray)
|
||||||
decl.value = LiteralValue(decl.datatype, heapId = heapId, position = litval?.position ?: decl.position)
|
decl.value = LiteralValue(decl.datatype, heapId = heapId, position = litval?.position ?: decl.position)
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
if(fillvalue< FLOAT_MAX_NEGATIVE || fillvalue> FLOAT_MAX_POSITIVE)
|
if(fillvalue< FLOAT_MAX_NEGATIVE || fillvalue> FLOAT_MAX_POSITIVE)
|
||||||
errors.add(ExpressionError("float value overflow", litval?.position ?: decl.position))
|
errors.add(ExpressionError("float value overflow", litval?.position ?: decl.position))
|
||||||
else {
|
else {
|
||||||
val fillArray = DoubleArray(size) { _ -> fillvalue }
|
val fillArray = DoubleArray(size) { fillvalue }
|
||||||
val heapId = heap.add(decl.datatype, fillArray)
|
val heapId = heap.add(decl.datatype, fillArray)
|
||||||
decl.value = LiteralValue(decl.datatype, heapId = heapId, position = litval?.position ?: decl.position)
|
decl.value = LiteralValue(decl.datatype, heapId = heapId, position = litval?.position ?: decl.position)
|
||||||
}
|
}
|
||||||
@ -575,7 +575,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
assignment.value = LiteralValue(DataType.UWORD, wordvalue = lv.asIntegerValue, position=lv.position)
|
assignment.value = LiteralValue(DataType.UWORD, wordvalue = lv.asIntegerValue, position=lv.position)
|
||||||
else if(lv.type==DataType.FLOAT) {
|
else if(lv.type==DataType.FLOAT) {
|
||||||
val d = lv.floatvalue!!
|
val d = lv.floatvalue!!
|
||||||
if(floor(d)==d && d in 0..65535)
|
if(floor(d)==d && d>=0 && d<=65535)
|
||||||
assignment.value = LiteralValue(DataType.UWORD, wordvalue=floor(d).toInt(), position=lv.position)
|
assignment.value = LiteralValue(DataType.UWORD, wordvalue=floor(d).toInt(), position=lv.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -587,7 +587,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
assignment.value = LiteralValue(DataType.UBYTE, lv.bytevalue.toShort(), position=lv.position)
|
assignment.value = LiteralValue(DataType.UBYTE, lv.bytevalue.toShort(), position=lv.position)
|
||||||
else if(lv.type==DataType.FLOAT) {
|
else if(lv.type==DataType.FLOAT) {
|
||||||
val d = lv.floatvalue!!
|
val d = lv.floatvalue!!
|
||||||
if(floor(d)==d && d in 0..255)
|
if(floor(d)==d && d >=0 && d<=255)
|
||||||
assignment.value = LiteralValue(DataType.UBYTE, floor(d).toShort(), position=lv.position)
|
assignment.value = LiteralValue(DataType.UBYTE, floor(d).toShort(), position=lv.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -599,7 +599,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
assignment.value = LiteralValue(DataType.BYTE, lv.bytevalue, position=lv.position)
|
assignment.value = LiteralValue(DataType.BYTE, lv.bytevalue, position=lv.position)
|
||||||
else if(lv.type==DataType.FLOAT) {
|
else if(lv.type==DataType.FLOAT) {
|
||||||
val d = lv.floatvalue!!
|
val d = lv.floatvalue!!
|
||||||
if(floor(d)==d && d in 0..127)
|
if(floor(d)==d && d>=0 && d<=127)
|
||||||
assignment.value = LiteralValue(DataType.BYTE, floor(d).toShort(), position=lv.position)
|
assignment.value = LiteralValue(DataType.BYTE, floor(d).toShort(), position=lv.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -611,7 +611,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
|
|||||||
assignment.value = LiteralValue(DataType.WORD, wordvalue=lv.wordvalue, position=lv.position)
|
assignment.value = LiteralValue(DataType.WORD, wordvalue=lv.wordvalue, position=lv.position)
|
||||||
else if(lv.type==DataType.FLOAT) {
|
else if(lv.type==DataType.FLOAT) {
|
||||||
val d = lv.floatvalue!!
|
val d = lv.floatvalue!!
|
||||||
if(floor(d)==d && d in -32768..32767)
|
if(floor(d)==d && d>=-32768 && d<=32767)
|
||||||
assignment.value = LiteralValue(DataType.BYTE, floor(d).toShort(), position=lv.position)
|
assignment.value = LiteralValue(DataType.BYTE, floor(d).toShort(), position=lv.position)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ class ScreenDialog : JFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun start() {
|
fun start() {
|
||||||
val repaintTimer = Timer(1000 / 60) { _ -> repaint() }
|
val repaintTimer = Timer(1000 / 60) { repaint() }
|
||||||
repaintTimer.start()
|
repaintTimer.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user