Merge remote-tracking branch 'origin/master'

This commit is contained in:
Irmen de Jong 2018-10-30 11:12:25 +01:00
commit 5361379187
5 changed files with 25 additions and 23 deletions

View File

@ -413,18 +413,20 @@ class AstChecker(private val namespace: INameScope,
when(decl.type) {
VarDeclType.VAR, VarDeclType.CONST -> {
if (decl.value == null) {
if (decl.datatype in NumericDatatypes) {
// initialize numeric var with value zero by default.
val litVal = LiteralValue(DataType.UBYTE, 0, position = decl.position)
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
litVal.parent=decl
decl.value = litVal
} else {
err("var/const declaration needs a compile-time constant initializer value for type ${decl.datatype}") // const fold should have provided it!
when {
decl.datatype in NumericDatatypes -> {
// initialize numeric var with value zero by default.
val litVal = LiteralValue(DataType.UBYTE, 0, position = decl.position)
litVal.parent = decl
decl.value = litVal
}
decl.type==VarDeclType.VAR -> {
val litVal = LiteralValue(decl.datatype, heapId = heapStringSentinel, position=decl.position) // point to the sentinel heap value instead
litVal.parent=decl
decl.value = litVal
}
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)
}

View File

@ -1055,9 +1055,9 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
// store A in target
val storeByte = when(segment[2].callLabel) {
"A" -> ""
"X" -> " tax"
"Y" -> " tya"
else -> " sta ${segment[2].callLabel}"
"X" -> "tax"
"Y" -> "tya"
else -> "sta ${segment[2].callLabel}"
}
" $setupPtr | $loadByte | $storeByte"

View File

@ -363,7 +363,7 @@ private fun builtinLen(args: List<IExpression>, position: Position, namespace:IN
private fun numericLiteral(value: Number, position: Position): LiteralValue {
val floatNum=value.toDouble()
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.
else
floatNum

View File

@ -100,7 +100,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
}
else -> {}
}
val fillArray = IntArray(size) { _ -> fillvalue }
val fillArray = IntArray(size) { fillvalue }
val heapId = heap.add(decl.datatype, fillArray)
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)
errors.add(ExpressionError("float value overflow", litval?.position ?: decl.position))
else {
val fillArray = DoubleArray(size) { _ -> fillvalue }
val fillArray = DoubleArray(size) { fillvalue }
val heapId = heap.add(decl.datatype, fillArray)
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)
else if(lv.type==DataType.FLOAT) {
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)
}
}
@ -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)
else if(lv.type==DataType.FLOAT) {
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)
}
}
@ -599,7 +599,7 @@ class ConstantFolding(private val namespace: INameScope, private val heap: HeapV
assignment.value = LiteralValue(DataType.BYTE, lv.bytevalue, position=lv.position)
else if(lv.type==DataType.FLOAT) {
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)
}
}
@ -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)
else if(lv.type==DataType.FLOAT) {
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)
}
}

View File

@ -150,7 +150,7 @@ class ScreenDialog : JFrame() {
}
fun start() {
val repaintTimer = Timer(1000 / 60) { _ -> repaint() }
val repaintTimer = Timer(1000 / 60) { repaint() }
repaintTimer.start()
}
}