mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-06 00:33:42 +00:00
Added some pointer-based struct tests (simulating the ASM we want for array indexing).
This commit is contained in:
parent
007985111a
commit
ef953a12b4
@ -32,9 +32,19 @@ public class TestPrograms {
|
||||
public TestPrograms() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStruct5() throws IOException, URISyntaxException {
|
||||
compileAndCompare("struct-5", log().verboseParse().verboseCreateSsa().verboseStatementSequence());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStruct4() throws IOException, URISyntaxException {
|
||||
compileAndCompare("struct-4", log().verboseParse().verboseCreateSsa().verboseStatementSequence());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStruct3() throws IOException, URISyntaxException {
|
||||
compileAndCompare("struct-3", log().verboseParse().verboseCreateSsa().verboseStatementSequence().verboseFragmentLog());
|
||||
compileAndCompare("struct-3");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Minimal struct - different instances and copying
|
||||
// Minimal struct - array of struct
|
||||
|
||||
struct Point {
|
||||
byte x;
|
||||
|
24
src/test/kc/struct-4.kc
Normal file
24
src/test/kc/struct-4.kc
Normal file
@ -0,0 +1,24 @@
|
||||
// Minimal struct - array of struct - near pointer math indexing
|
||||
|
||||
struct Point {
|
||||
byte x;
|
||||
byte y;
|
||||
};
|
||||
|
||||
struct Point[4] points;
|
||||
|
||||
const byte SIZEOF_POINT = 2;
|
||||
const byte OFFS_X = 0;
|
||||
const byte OFFS_Y = 1;
|
||||
|
||||
void main() {
|
||||
for( byte i: 0..3) {
|
||||
*((byte*)points+OFFS_X+i*SIZEOF_POINT) = i; // points[i].x = i;
|
||||
*((byte*)points+OFFS_Y+i*SIZEOF_POINT) = i+4; // points[i].y = i+4;
|
||||
}
|
||||
const byte* SCREEN = 0x0400;
|
||||
for( byte i: 0..3) {
|
||||
SCREEN[i] = *((byte*)points+OFFS_X+i*SIZEOF_POINT); // SCREEN[i] = points[i].x;
|
||||
(SCREEN+40)[i] = *((byte*)points+OFFS_Y+i*SIZEOF_POINT); // (SCREEN+40)[i] = points[i].y;
|
||||
}
|
||||
}
|
26
src/test/kc/struct-5.kc
Normal file
26
src/test/kc/struct-5.kc
Normal file
@ -0,0 +1,26 @@
|
||||
// Minimal struct - array of struct - far pointer math indexing
|
||||
|
||||
struct Point {
|
||||
byte x;
|
||||
byte y;
|
||||
};
|
||||
|
||||
struct Point[4] points;
|
||||
|
||||
const byte SIZEOF_POINT = 2;
|
||||
const byte OFFS_X = 0;
|
||||
const byte OFFS_Y = 1;
|
||||
|
||||
void main() {
|
||||
for( byte i: 0..3) {
|
||||
struct Point* point_i = points+i;
|
||||
*((byte*)point_i+OFFS_X) = i; // points[i].x = i;
|
||||
*((byte*)point_i+OFFS_Y) = i+4; // points[i].y = i+4;
|
||||
}
|
||||
const byte* SCREEN = 0x0400;
|
||||
for( byte i: 0..3) {
|
||||
struct Point* point_i = points+i;
|
||||
SCREEN[i] = *((byte*)point_i+OFFS_X); // SCREEN[i] = points[i].x;
|
||||
(SCREEN+40)[i] = *((byte*)point_i+OFFS_Y); // (SCREEN+40)[i] = points[i].y;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Minimal struct - different instances and copying
|
||||
// Minimal struct - array of struct
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
|
39
src/test/ref/struct-4.asm
Normal file
39
src/test/ref/struct-4.asm
Normal file
@ -0,0 +1,39 @@
|
||||
// Minimal struct - array of struct - near pointer math indexing
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.const OFFS_X = 0
|
||||
.const OFFS_Y = 1
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
ldx #0
|
||||
b1:
|
||||
txa
|
||||
asl
|
||||
tay
|
||||
txa
|
||||
sta points+OFFS_X,y
|
||||
txa
|
||||
clc
|
||||
adc #4
|
||||
// points[i].x = i;
|
||||
sta points+OFFS_Y,y
|
||||
inx
|
||||
cpx #4
|
||||
bne b1
|
||||
ldy #0
|
||||
b2:
|
||||
tya
|
||||
asl
|
||||
tax
|
||||
lda points+OFFS_X,x
|
||||
sta SCREEN,y
|
||||
// SCREEN[i] = points[i].x;
|
||||
lda points+OFFS_Y,x
|
||||
sta SCREEN+$28,y
|
||||
iny
|
||||
cpy #4
|
||||
bne b2
|
||||
rts
|
||||
}
|
||||
points: .fill 2*4, 0
|
67
src/test/ref/struct-5.asm
Normal file
67
src/test/ref/struct-5.asm
Normal file
@ -0,0 +1,67 @@
|
||||
// Minimal struct - array of struct - far pointer math indexing
|
||||
.pc = $801 "Basic"
|
||||
:BasicUpstart(main)
|
||||
.pc = $80d "Program"
|
||||
.const OFFS_X = 0
|
||||
.const OFFS_Y = 1
|
||||
main: {
|
||||
.label SCREEN = $400
|
||||
.label _1 = 4
|
||||
.label _3 = 2
|
||||
.label _8 = 4
|
||||
.label _11 = 2
|
||||
.label point_i = 2
|
||||
.label point_i1 = 2
|
||||
ldx #0
|
||||
b1:
|
||||
txa
|
||||
asl
|
||||
clc
|
||||
adc #<points
|
||||
sta point_i
|
||||
lda #>points
|
||||
adc #0
|
||||
sta point_i+1
|
||||
lda point_i
|
||||
sta _1
|
||||
lda point_i+1
|
||||
sta _1+1
|
||||
txa
|
||||
ldy #OFFS_X
|
||||
sta (_1),y
|
||||
txa
|
||||
clc
|
||||
adc #4
|
||||
// points[i].x = i;
|
||||
ldy #OFFS_Y
|
||||
sta (_3),y
|
||||
inx
|
||||
cpx #4
|
||||
bne b1
|
||||
ldx #0
|
||||
b2:
|
||||
txa
|
||||
asl
|
||||
clc
|
||||
adc #<points
|
||||
sta point_i1
|
||||
lda #>points
|
||||
adc #0
|
||||
sta point_i1+1
|
||||
lda point_i1
|
||||
sta _8
|
||||
lda point_i1+1
|
||||
sta _8+1
|
||||
ldy #OFFS_X
|
||||
lda (_8),y
|
||||
sta SCREEN,x
|
||||
// SCREEN[i] = points[i].x;
|
||||
ldy #OFFS_Y
|
||||
lda (_11),y
|
||||
sta SCREEN+$28,x
|
||||
inx
|
||||
cpx #4
|
||||
bne b2
|
||||
rts
|
||||
}
|
||||
points: .fill 2*4, 0
|
Loading…
Reference in New Issue
Block a user