From b200f9945f114f73ebc9ee943818d7873219427a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 4 Apr 2019 23:51:22 +0200 Subject: [PATCH] asmgen array with pointer values (w.i.p) --- .gitignore | 1 - .../src/prog8/compiler/target/c64/AsmGen.kt | 18 +-- examples/test.p8 | 109 +++++++++++++++++- 3 files changed, 115 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index b68b249c4..c968f5bab 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ .*cache/ *.directory *.prg -*.asm *.bin *.labels.txt *.vm.txt diff --git a/compiler/src/prog8/compiler/target/c64/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/AsmGen.kt index c83bc3de7..2b5c708a9 100644 --- a/compiler/src/prog8/compiler/target/c64/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/AsmGen.kt @@ -359,14 +359,18 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram, private fun makeArrayFillDataUnsigned(value: Value): List { val array = heap.get(value.heapId).array!! - if(value.type==DataType.ARRAY_UB) { - TODO("deal with byte array") - //return array.map { "$"+it.toString(16).padStart(2, '0') } - } else if(value.type==DataType.ARRAY_UW) { - TODO("deal with pointerto") + return when { + value.type==DataType.ARRAY_UB -> + // byte array can never contain pointer-to types, so treat values as all integers + array.map { "$"+it.integer!!.toString(16).padStart(2, '0') } + value.type==DataType.ARRAY_UW -> array.map { + if(it.integer!=null) + "$"+it.integer.toString(16).padStart(2, '0') + else + TODO("deal with pointerto") + } + else -> throw AssemblyError("invalid arrayspec type") } - else - throw AssemblyError("invalid arrayspec type") } private fun makeArrayFillDataSigned(value: Value): List { diff --git a/examples/test.p8 b/examples/test.p8 index 99b4f68f2..ac5d12992 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,11 +1,95 @@ %zeropage basicsafe +%option enable_floats + +%import c64flt + ~ main { sub start() { + ;aggregates() + pointers() + } - ; TODO what about avg() on floating point array variable! + sub aggregates() { + ; @todo test this in StackVM as well!! + + byte[3] ba = [-5, 0, 20] + ubyte[3] uba = [100, 0, 20] + word[3] wa = [-5000, 0, 2000] + uword[3] uwa = [10000, 0, 2000] + float[4] fa = [5.5, 0.0, 20.22,-4.44] + + c64scr.print_ub(any(ba)) + c64.CHROUT(' ') + c64scr.print_ub(any(uba)) + c64.CHROUT(' ') + c64scr.print_ub(any(wa)) + c64.CHROUT(' ') + c64scr.print_ub(any(uwa)) + c64.CHROUT(' ') + c64scr.print_ub(any(fa)) + c64.CHROUT('\n') + + c64scr.print_ub(all(ba)) + c64.CHROUT(' ') + c64scr.print_ub(all(uba)) + c64.CHROUT(' ') + c64scr.print_ub(all(wa)) + c64.CHROUT(' ') + c64scr.print_ub(all(uwa)) + c64.CHROUT(' ') + c64scr.print_ub(all(fa)) + c64.CHROUT('\n') + + c64scr.print_b(min(ba)) + c64.CHROUT(' ') + c64scr.print_ub(min(uba)) + c64.CHROUT(' ') + c64scr.print_w(min(wa)) + c64.CHROUT(' ') + c64scr.print_uw(min(uwa)) + c64.CHROUT(' ') + c64flt.print_f(min(fa)) ; @todo fix min(floatarray) + c64.CHROUT('\n') + + c64scr.print_b(max(ba)) + c64.CHROUT(' ') + c64scr.print_ub(max(uba)) + c64.CHROUT(' ') + c64scr.print_w(max(wa)) + c64.CHROUT(' ') + c64scr.print_uw(max(uwa)) + c64.CHROUT(' ') + c64flt.print_f(max(fa)) ; @todo fix max(floatarray) + c64.CHROUT('\n') + + c64scr.print_uw(sum(ba)) + c64.CHROUT(' ') + c64scr.print_uw(sum(uba)) + c64.CHROUT(' ') + c64scr.print_w(sum(wa)) + c64.CHROUT(' ') + c64scr.print_uw(sum(uwa)) + c64.CHROUT(' ') + c64flt.print_f(sum(fa)) + c64.CHROUT('\n') + + c64flt.print_f(avg(ba)) + c64.CHROUT(' ') + c64flt.print_f(avg(uba)) + c64.CHROUT(' ') + c64flt.print_f(avg(wa)) + c64.CHROUT(' ') + c64flt.print_f(avg(uwa)) + c64.CHROUT(' ') + c64flt.print_f(avg(fa)) + c64.CHROUT('\n') + + } + + sub pointers() { ubyte[3] array1 ubyte[3] array2 @@ -20,29 +104,44 @@ pointer = &array2 pointer = &string1 - uword[4] pointers = [&array1, &array2, &string1, &string2] ; @todo make it possible to initialize array with pointers + ;uword[4] pointers = [&array1, &array2, &string1, &string2] ; @todo make it possible to initialize array with pointers ;ptrsubasm("moet werken") ; @todo rewrite ast into pointer-of expression (and remove special cases from Compiler) ;pointersub("moet werken") ; @todo rewrite ast into pointer-of expression (and remove special cases from Compiler) ;myprintasm("moet werken3") ; @todo rewrite ast into pointer-of expression (and remove special cases from Compiler) ptrsubasm(&array1) + ptrsubasm(&array2) ptrsubasm(&string1) + ptrsubasm(&string2) pointersub(&array1) + pointersub(&array2) pointersub(&string1) + pointersub(&string2) } sub pointersub(uword arg) { - A=lsb(arg) + c64scr.print_uwhex(1, arg) + c64.CHROUT('\n') } asmsub ptrsubasm(uword arg @ AY) -> clobbers() -> () { - A=4 + %asm {{ + sec + jsr c64scr.print_uwhex + lda #13 + jmp c64.CHROUT + }} } asmsub myprintasm(str arg @ AY) -> clobbers() -> () { - A=4 + %asm {{ + sec + jsr c64scr.print_uwhex + lda #13 + jmp c64.CHROUT + }} } }