From 837104f4fd3efdffb1ac680fea496241beefb972 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Tue, 28 May 2019 22:56:52 +0200 Subject: [PATCH] Working on structs --- .../fragment/_deref_pbuc1=vssz1_mbr_0.asm | 2 -- .../fragment/_deref_pbuc1=vssz1_mbr_1.asm | 2 -- src/main/fragment/vssz1=vssz2.asm | 4 +++ src/main/fragment/vssz1_mbr_0=vbuc1.asm | 2 -- src/main/fragment/vssz1_mbr_1=vbuc1.asm | 2 -- .../Pass0GenerateStatementSequence.java | 3 ++ .../dk/camelot64/kickc/test/TestPrograms.java | 5 +++ src/test/kc/struct-2.kc | 20 +++++++++++ src/test/ref/struct-2.asm | 36 +++++++++++++++++++ 9 files changed, 68 insertions(+), 8 deletions(-) delete mode 100644 src/main/fragment/_deref_pbuc1=vssz1_mbr_0.asm delete mode 100644 src/main/fragment/_deref_pbuc1=vssz1_mbr_1.asm create mode 100644 src/main/fragment/vssz1=vssz2.asm delete mode 100644 src/main/fragment/vssz1_mbr_0=vbuc1.asm delete mode 100644 src/main/fragment/vssz1_mbr_1=vbuc1.asm create mode 100644 src/test/kc/struct-2.kc create mode 100644 src/test/ref/struct-2.asm diff --git a/src/main/fragment/_deref_pbuc1=vssz1_mbr_0.asm b/src/main/fragment/_deref_pbuc1=vssz1_mbr_0.asm deleted file mode 100644 index f235c1aee..000000000 --- a/src/main/fragment/_deref_pbuc1=vssz1_mbr_0.asm +++ /dev/null @@ -1,2 +0,0 @@ -lda {z1}+0 -sta {c1} \ No newline at end of file diff --git a/src/main/fragment/_deref_pbuc1=vssz1_mbr_1.asm b/src/main/fragment/_deref_pbuc1=vssz1_mbr_1.asm deleted file mode 100644 index 59a255b43..000000000 --- a/src/main/fragment/_deref_pbuc1=vssz1_mbr_1.asm +++ /dev/null @@ -1,2 +0,0 @@ -lda {z1}+1 -sta {c1} \ No newline at end of file diff --git a/src/main/fragment/vssz1=vssz2.asm b/src/main/fragment/vssz1=vssz2.asm new file mode 100644 index 000000000..113613e13 --- /dev/null +++ b/src/main/fragment/vssz1=vssz2.asm @@ -0,0 +1,4 @@ +lda {z2} +sta {z1} +lda {z2}+1 +sta {z1}+1 \ No newline at end of file diff --git a/src/main/fragment/vssz1_mbr_0=vbuc1.asm b/src/main/fragment/vssz1_mbr_0=vbuc1.asm deleted file mode 100644 index cdbf628d1..000000000 --- a/src/main/fragment/vssz1_mbr_0=vbuc1.asm +++ /dev/null @@ -1,2 +0,0 @@ -lda #{c1} -sta {z1}+0 \ No newline at end of file diff --git a/src/main/fragment/vssz1_mbr_1=vbuc1.asm b/src/main/fragment/vssz1_mbr_1=vbuc1.asm deleted file mode 100644 index 540828c77..000000000 --- a/src/main/fragment/vssz1_mbr_1=vbuc1.asm +++ /dev/null @@ -1,2 +0,0 @@ -lda #{c1} -sta {z1}+1 \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java index ee926831a..f25f31473 100644 --- a/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java +++ b/src/main/java/dk/camelot64/kickc/passes/Pass0GenerateStatementSequence.java @@ -497,6 +497,9 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor { // Add comments to constant lValue.setComments(ensureUnusedComments(comments)); } + if(type instanceof SymbolTypeStruct) { + lValue.setDeclaredVolatile(true); + } KickCParser.ExprContext initializer = ctx.expr(); if(declVarStructMember) { if(initializer != null) { diff --git a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java index 011fd3e50..4df4055da 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestPrograms.java +++ b/src/test/java/dk/camelot64/kickc/test/TestPrograms.java @@ -32,6 +32,11 @@ public class TestPrograms { public TestPrograms() { } + @Test + public void testStruct2() throws IOException, URISyntaxException { + compileAndCompare("struct-2"); + } + @Test public void testStruct1() throws IOException, URISyntaxException { compileAndCompare("struct-1"); diff --git a/src/test/kc/struct-2.kc b/src/test/kc/struct-2.kc new file mode 100644 index 000000000..a52a169db --- /dev/null +++ b/src/test/kc/struct-2.kc @@ -0,0 +1,20 @@ +// Minimal struct - different instances and copying + +struct Point { + byte x; + byte y; +}; + +struct Point point1, point2; + +void main() { + point1.x = 2; + point1.y = 3; + point2 = point1; + point2.x = 4; + const byte* SCREEN = 0x0400; + SCREEN[0] = point1.x; + SCREEN[1] = point1.y; + SCREEN[2] = point2.x; + SCREEN[3] = point2.y; +} \ No newline at end of file diff --git a/src/test/ref/struct-2.asm b/src/test/ref/struct-2.asm new file mode 100644 index 000000000..29ff684c8 --- /dev/null +++ b/src/test/ref/struct-2.asm @@ -0,0 +1,36 @@ +// Minimal struct - different instances and copying +.pc = $801 "Basic" +:BasicUpstart(bbegin) +.pc = $80d "Program" + .label point1 = 2 + .label point2 = 4 +bbegin: + lda #0 + sta point1 + sta point1+1 + sta point2 + sta point2+1 + jsr main + rts +main: { + .label SCREEN = $400 + lda #2 + sta point1+0 + lda #3 + sta point1+1 + lda point1 + sta point2 + lda point1+1 + sta point2+1 + lda #4 + sta point2+0 + lda point1+0 + sta SCREEN + lda point1+1 + sta SCREEN+1 + lda point2+0 + sta SCREEN+2 + lda point2+1 + sta SCREEN+3 + rts +}