mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-01-23 09:33:30 +00:00
Temporary implementation for arrays of structs
This commit is contained in:
parent
837104f4fd
commit
007985111a
2
src/main/fragment/pssc1_derefidx_vbuxx_mbr_0=vbuaa.asm
Normal file
2
src/main/fragment/pssc1_derefidx_vbuxx_mbr_0=vbuaa.asm
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
sta {c1},x
|
||||||
|
|
2
src/main/fragment/pssc1_derefidx_vbuxx_mbr_1=vbuaa.asm
Normal file
2
src/main/fragment/pssc1_derefidx_vbuxx_mbr_1=vbuaa.asm
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
sta {c1}+1,x
|
||||||
|
|
2
src/main/fragment/pssc1_derefidx_vbuyy_mbr_0=vbuaa.asm
Normal file
2
src/main/fragment/pssc1_derefidx_vbuyy_mbr_0=vbuaa.asm
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
sta {c1},y
|
||||||
|
|
2
src/main/fragment/pssc1_derefidx_vbuyy_mbr_1=vbuaa.asm
Normal file
2
src/main/fragment/pssc1_derefidx_vbuyy_mbr_1=vbuaa.asm
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
sta {c1}+1,y
|
||||||
|
|
1
src/main/fragment/vbuaa=_deref_pssc1_mbr_0.asm
Normal file
1
src/main/fragment/vbuaa=_deref_pssc1_mbr_0.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1}
|
1
src/main/fragment/vbuaa=_deref_pssc1_mbr_1.asm
Normal file
1
src/main/fragment/vbuaa=_deref_pssc1_mbr_1.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1}+1
|
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuxx_mbr_0.asm
Normal file
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuxx_mbr_0.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1},x
|
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuxx_mbr_1.asm
Normal file
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuxx_mbr_1.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1}+1,x
|
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuyy_mbr_0.asm
Normal file
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuyy_mbr_0.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1},y
|
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuyy_mbr_1.asm
Normal file
1
src/main/fragment/vbuaa=pssc1_derefidx_vbuyy_mbr_1.asm
Normal file
@ -0,0 +1 @@
|
|||||||
|
lda {c1}+1,y
|
@ -383,6 +383,8 @@ public class AsmFragmentInstanceSpecFactory {
|
|||||||
return "ppr";
|
return "ppr";
|
||||||
} else if(elementType instanceof SymbolTypePointer) {
|
} else if(elementType instanceof SymbolTypePointer) {
|
||||||
return "ppt";
|
return "ppt";
|
||||||
|
} else if(elementType instanceof SymbolTypeStruct) {
|
||||||
|
return "pss";
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Not implemented " + type);
|
throw new RuntimeException("Not implemented " + type);
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,7 @@ import dk.camelot64.kickc.model.*;
|
|||||||
import dk.camelot64.kickc.model.operators.Operators;
|
import dk.camelot64.kickc.model.operators.Operators;
|
||||||
import dk.camelot64.kickc.model.statements.*;
|
import dk.camelot64.kickc.model.statements.*;
|
||||||
import dk.camelot64.kickc.model.symbols.*;
|
import dk.camelot64.kickc.model.symbols.*;
|
||||||
import dk.camelot64.kickc.model.types.SymbolType;
|
import dk.camelot64.kickc.model.types.*;
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeArray;
|
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypePointer;
|
|
||||||
import dk.camelot64.kickc.model.types.SymbolTypeProcedure;
|
|
||||||
import dk.camelot64.kickc.model.values.*;
|
import dk.camelot64.kickc.model.values.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -438,6 +435,11 @@ public class Pass4CodeGeneration {
|
|||||||
String asmSize = AsmFormat.getAsmConstant(program, new ConstantBinary(new ConstantInteger(2L), Operators.MULTIPLY, arraySize), 99, scopeRef);
|
String asmSize = AsmFormat.getAsmConstant(program, new ConstantBinary(new ConstantInteger(2L), Operators.MULTIPLY, arraySize), 99, scopeRef);
|
||||||
asm.addDataFilled(asmName.replace("#", "_").replace("$", "_"), AsmDataNumeric.Type.WORD, asmSize, size, "0");
|
asm.addDataFilled(asmName.replace("#", "_").replace("$", "_"), AsmDataNumeric.Type.WORD, asmSize, size, "0");
|
||||||
added.add(asmName);
|
added.add(asmName);
|
||||||
|
} else if(constantArrayFilled.getElementType() instanceof SymbolTypeStruct) {
|
||||||
|
SymbolTypeStruct structElementType = (SymbolTypeStruct) constantArrayFilled.getElementType();
|
||||||
|
String asmSize = AsmFormat.getAsmConstant(program, new ConstantBinary(new ConstantInteger((long) structElementType.getSizeBytes()), Operators.MULTIPLY, arraySize), 99, scopeRef);
|
||||||
|
asm.addDataFilled(asmName.replace("#", "_").replace("$", "_"), AsmDataNumeric.Type.WORD, asmSize, size, "0");
|
||||||
|
added.add(asmName);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unhandled constant array element type " + constantArrayFilled.toString(program));
|
throw new RuntimeException("Unhandled constant array element type " + constantArrayFilled.toString(program));
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,11 @@ public class TestPrograms {
|
|||||||
public TestPrograms() {
|
public TestPrograms() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStruct3() throws IOException, URISyntaxException {
|
||||||
|
compileAndCompare("struct-3", log().verboseParse().verboseCreateSsa().verboseStatementSequence().verboseFragmentLog());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStruct2() throws IOException, URISyntaxException {
|
public void testStruct2() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("struct-2");
|
compileAndCompare("struct-2");
|
||||||
|
20
src/test/kc/struct-3.kc
Normal file
20
src/test/kc/struct-3.kc
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Minimal struct - different instances and copying
|
||||||
|
|
||||||
|
struct Point {
|
||||||
|
byte x;
|
||||||
|
byte y;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Point[4] points;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
for( byte i: 0..4) {
|
||||||
|
points[i].x = i;
|
||||||
|
points[i].y = i+1;
|
||||||
|
}
|
||||||
|
const byte* SCREEN = 0x0400;
|
||||||
|
for( byte i: 0..4) {
|
||||||
|
SCREEN[i] = points[i].x;
|
||||||
|
(SCREEN+40)[i] = points[i].y;
|
||||||
|
}
|
||||||
|
}
|
39
src/test/ref/struct-3.asm
Normal file
39
src/test/ref/struct-3.asm
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// Minimal struct - different instances and copying
|
||||||
|
.pc = $801 "Basic"
|
||||||
|
:BasicUpstart(main)
|
||||||
|
.pc = $80d "Program"
|
||||||
|
main: {
|
||||||
|
.label SCREEN = $400
|
||||||
|
.label _5 = 2
|
||||||
|
ldx #0
|
||||||
|
b1:
|
||||||
|
txa
|
||||||
|
asl
|
||||||
|
sta _5
|
||||||
|
tay
|
||||||
|
txa
|
||||||
|
sta points,y
|
||||||
|
txa
|
||||||
|
tay
|
||||||
|
iny
|
||||||
|
tya
|
||||||
|
ldy _5
|
||||||
|
sta points+1,y
|
||||||
|
inx
|
||||||
|
cpx #5
|
||||||
|
bne b1
|
||||||
|
ldy #0
|
||||||
|
b2:
|
||||||
|
tya
|
||||||
|
asl
|
||||||
|
tax
|
||||||
|
lda points,x
|
||||||
|
sta SCREEN,y
|
||||||
|
lda points+1,x
|
||||||
|
sta SCREEN+$28,y
|
||||||
|
iny
|
||||||
|
cpy #5
|
||||||
|
bne b2
|
||||||
|
rts
|
||||||
|
}
|
||||||
|
points: .fill 2*4, 0
|
Loading…
x
Reference in New Issue
Block a user