begin of for asm

This commit is contained in:
Irmen de Jong 2019-07-31 00:54:04 +02:00
parent 6f7322150f
commit 50aa286d3a
2 changed files with 26 additions and 11 deletions

View File

@ -952,21 +952,36 @@ internal class AsmGen2(val program: Program,
} }
private fun translate(stmt: ForLoop) { private fun translate(stmt: ForLoop) {
val iterableDt = stmt.iterable.inferType(program)
when(stmt.iterable) { when(stmt.iterable) {
is RangeExpr -> { is RangeExpr -> {
println("forloop over range $stmt") when(iterableDt) {
in ByteDatatypes -> {
println("forloop over byte range $stmt") // TODO
}
in WordDatatypes -> {
println("forloop over word range $stmt") // TODO
}
else -> throw AssemblyError("range expression can only be byte or word")
}
} }
is IdentifierReference -> { is IdentifierReference -> {
val iterableDt = stmt.iterable.inferType(program) val decl = (stmt.iterable as IdentifierReference).targetVarDecl(program.namespace)!!
when(iterableDt) { when(iterableDt) {
DataType.STR, DataType.STR_S, DataType.ARRAY_UB, DataType.ARRAY_B -> { DataType.STR, DataType.STR_S -> {
println("forloop over byte array/string $stmt") println("forloop over string $stmt") // TODO (ends at 0 byte)
}
DataType.ARRAY_UB, DataType.ARRAY_B -> {
val size = decl.arraysize!!.size()
println("forloop over byte array of len $size $stmt") // TODO (ends at length of array)
} }
DataType.ARRAY_W, DataType.ARRAY_UW -> { DataType.ARRAY_W, DataType.ARRAY_UW -> {
println("forloop over word array $stmt") val size = decl.arraysize!!.size()
println("forloop over word array len $size $stmt") // TODO
} }
DataType.ARRAY_F -> { DataType.ARRAY_F -> {
println("forloop over float array $stmt") val size = decl.arraysize!!.size()
println("forloop over float array len $size $stmt") // TODO
} }
else -> throw AssemblyError("can't iterate over $iterableDt") else -> throw AssemblyError("can't iterate over $iterableDt")
} }

View File

@ -14,11 +14,11 @@ main {
} }
c64.CHROUT('\n') c64.CHROUT('\n')
; for A in [1,3,5,99] { for A in [1,3,5,99] {
; c64scr.print_ub(A) c64scr.print_ub(A)
; c64.CHROUT(',') c64.CHROUT(',')
; } }
; c64.CHROUT('\n') c64.CHROUT('\n')
; ;
; for A in 10 to 20 { ; for A in 10 to 20 {
; c64scr.print_ub(A) ; c64scr.print_ub(A)