fix for loop asm creation with word loopvar

This commit is contained in:
Irmen de Jong 2020-08-29 02:05:24 +02:00
parent a18de75da9
commit c50ecf6055
5 changed files with 23 additions and 14 deletions

View File

@ -80,8 +80,6 @@ cx16 {
&uword r15 = $20
; TODO subroutine args + soubroutine returnvalues + clobber registers
; supported C128 additions
romsub $ff4a = close_all()
romsub $ff59 = lkupla()

View File

@ -13,7 +13,6 @@ txt {
asmsub clear_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) {
; ---- clear the character screen with the given fill character and character color.
; (assumes screen and color matrix are at their default addresses)
%asm {{
brk ; TODO

View File

@ -642,7 +642,14 @@ class RangeExpr(var from: Expression,
fromDt istype DataType.STR && toDt istype DataType.STR -> InferredTypes.knownFor(DataType.STR)
fromDt istype DataType.WORD || toDt istype DataType.WORD -> InferredTypes.knownFor(DataType.ARRAY_W)
fromDt istype DataType.BYTE || toDt istype DataType.BYTE -> InferredTypes.knownFor(DataType.ARRAY_B)
else -> InferredTypes.knownFor(DataType.ARRAY_UB)
else -> {
val fdt = fromDt.typeOrElse(DataType.STRUCT)
val tdt = toDt.typeOrElse(DataType.STRUCT)
if(fdt largerThan tdt)
InferredTypes.knownFor(ElementArrayTypes.getValue(fdt))
else
InferredTypes.knownFor(ElementArrayTypes.getValue(tdt))
}
}
}
override fun toString(): String {

View File

@ -46,7 +46,7 @@ internal class ForLoopsAsmGen(private val program: Program, private val asmgen:
DataType.ARRAY_B, DataType.ARRAY_UB -> {
if (stepsize==1 || stepsize==-1) {
// bytes, step 1 or -1
// bytes array, step 1 or -1
val incdec = if(stepsize==1) "inc" else "dec"
// loop over byte range via loopvar
@ -258,13 +258,6 @@ $endLabel inx""")
asmgen.loopEndLabels.pop()
}
private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) {
val target = AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, stmt.loopVarDt(program).typeOrElse(DataType.STRUCT), variable=stmt.loopVar)
val src = AsmAssignSource.fromAstSource(range.from, program).adjustDataTypeToTarget(target)
val assign = AsmAssignment(src, target, false, range.position)
asmgen.translateNormalAssignment(assign)
}
private fun translateForOverIterableVar(stmt: ForLoop, iterableDt: DataType, ident: IdentifierReference) {
val loopLabel = asmgen.makeLabel("for_loop")
val endLabel = asmgen.makeLabel("for_end")
@ -615,4 +608,11 @@ $loopLabel""")
$endLabel""")
asmgen.loopEndLabels.pop()
}
private fun assignLoopvar(stmt: ForLoop, range: RangeExpr) {
val target = AsmAssignTarget(TargetStorageKind.VARIABLE, program, asmgen, stmt.loopVarDt(program).typeOrElse(DataType.STRUCT), variable=stmt.loopVar)
val src = AsmAssignSource.fromAstSource(range.from, program).adjustDataTypeToTarget(target)
val assign = AsmAssignment(src, target, false, range.position)
asmgen.translateNormalAssignment(assign)
}
}

View File

@ -4,10 +4,15 @@
main {
sub start() {
ubyte xx
uword xx
ubyte yy
for xx in 319 downto 0 {
; TODO also fix that the asm is invalid for word iterator variable.
}
for yy in 199 downto 0 {
for xx in 255 downto 0 {
for xx in 319 downto 0 {
; TODO also fix that the asm is invalid for word iterator variable.
}
}