asmgen array with pointer values (w.i.p)

This commit is contained in:
Irmen de Jong 2019-04-04 23:51:22 +02:00
parent eebd4e5f18
commit b200f9945f
3 changed files with 115 additions and 13 deletions

1
.gitignore vendored
View File

@ -5,7 +5,6 @@
.*cache/
*.directory
*.prg
*.asm
*.bin
*.labels.txt
*.vm.txt

View File

@ -359,14 +359,18 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
private fun makeArrayFillDataUnsigned(value: Value): List<String> {
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<String> {

View File

@ -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
}}
}
}