ir: ignore empty chunks instead of crashing

This commit is contained in:
Irmen de Jong 2023-12-01 22:49:20 +01:00
parent 36bfef567d
commit 172e78e8f2
3 changed files with 11 additions and 25 deletions

View File

@ -283,15 +283,10 @@ class IRCodeGen(
else -> TODO("missing codegen for $node")
}
chunks.forEach { chunk ->
require(chunk.isNotEmpty() || chunk.label != null) {
"chunk should have instructions and/or a label"
}
}
val nonEmptyChunks = chunks.filter { it.isNotEmpty() || it.label != null }
nonEmptyChunks.filterIsInstance<IRCodeChunk>().firstOrNull()?.appendSrcPosition(node.position)
chunks.filterIsInstance<IRCodeChunk>().firstOrNull()?.appendSrcPosition(node.position)
return chunks
return nonEmptyChunks
}
private fun readBinaryData(node: PtIncludeBinary): Collection<UByte> {

View File

@ -2,6 +2,9 @@
TODO
====
- 10 * (uw/10) is correct, (uw/10) * 10 fails with -noopt 10 * (uw/10) needs -noopt to work correctly
- don't print the leading space in print_f()
- uword scanline_buf = memory("scanline", 320, 0) different result when inside a sub or outside a sub??! (imageviewer iff module)
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- once VAL_1 is merged into the kernal properly, remove all the workarounds in cx16 floats.parse_f()

View File

@ -1,25 +1,13 @@
%import textio
%import floats
%import string
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
str buffer = "???????????????????????????"
repeat {
txt.print("enter number: ")
void txt.input_chars(buffer)
txt.print("\nprog8's parse_f: ")
float value = floats.parse_f(buffer)
floats.print_f(value)
; floats.VAL_1 is defined as:
; romsub $fe09 = VAL_1(uword string @XY, ubyte length @A) clobbers(A,X,Y) -> float @FAC1
; txt.print("\nrom val_1: ")
; value = floats.VAL_1(buffer, string.length(buffer))
; floats.print_f(value)
txt.nl()
}
ubyte uw = 97
txt.print_ub( 10 * (uw/10) ) ; 90
txt.nl()
txt.print_ub( (uw/10) * 10 ) ; 90
txt.nl()
}
}