mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-08-11 17:25:41 +00:00
Fixed tests
This commit is contained in:
@@ -323,7 +323,6 @@ public class Compiler {
|
|||||||
constantOptimizations.add(new PassNSimplifyConstantZero(program));
|
constantOptimizations.add(new PassNSimplifyConstantZero(program));
|
||||||
constantOptimizations.add(new PassNSimplifyExpressionWithZero(program));
|
constantOptimizations.add(new PassNSimplifyExpressionWithZero(program));
|
||||||
|
|
||||||
|
|
||||||
pass2Execute(constantOptimizations);
|
pass2Execute(constantOptimizations);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,137 +0,0 @@
|
|||||||
package dk.camelot64.kickc.model.types;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Symbol Type of an inline expression. Inline expressions can match multiple types depending on the actual value,
|
|
||||||
* eg. the value 27 matches both byte and signed byte (which can in turn be promoted to word/signed word, dword/signed dword), while the value -252 only matches signed word or signed dword.
|
|
||||||
*/
|
|
||||||
public class SymbolTypeMulti implements SymbolType {
|
|
||||||
|
|
||||||
/** All numeric types. */
|
|
||||||
public static final SymbolTypeMulti NUMERIC = new SymbolTypeMulti(Arrays.asList(BYTE, SBYTE, WORD, SWORD, DWORD, SDWORD));
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All potential types for the inline constant.
|
|
||||||
*/
|
|
||||||
private Collection<SymbolType> types;
|
|
||||||
|
|
||||||
public SymbolTypeMulti(Collection<SymbolType> types) {
|
|
||||||
this.types = types;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Collection<SymbolType> getTypes() {
|
|
||||||
return types;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSizeBytes() {
|
|
||||||
// Find the minimal sizeof - and return that
|
|
||||||
Integer size = null;
|
|
||||||
for(SymbolType type : types) {
|
|
||||||
if(size==null) {
|
|
||||||
size = type.getSizeBytes();
|
|
||||||
} else if(size>type.getSizeBytes()) {
|
|
||||||
size = type.getSizeBytes();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(size==null) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getTypeName() {
|
|
||||||
StringBuilder name = new StringBuilder();
|
|
||||||
boolean first = true;
|
|
||||||
for(SymbolType type : types) {
|
|
||||||
if(first) {
|
|
||||||
first = false;
|
|
||||||
} else {
|
|
||||||
name.append("/");
|
|
||||||
}
|
|
||||||
name.append(type);
|
|
||||||
}
|
|
||||||
return name.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if(this == o) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if(o == null || getClass() != o.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
SymbolTypeMulti that = (SymbolTypeMulti) o;
|
|
||||||
return types != null ? types.equals(that.types) : that.types == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return types != null ? types.hashCode() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getTypeName();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is unsigned byte one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if unsigned byte is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isByte() {
|
|
||||||
return types.contains(BYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is signed byte one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if signed byte is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isSByte() {
|
|
||||||
return types.contains(SBYTE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is unsigned word one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if unsigned word is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isWord() {
|
|
||||||
return types.contains(WORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is signed word one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if signed word is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isSWord() {
|
|
||||||
return types.contains(SWORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is unsigned dword one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if unsigned dword is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isDWord() {
|
|
||||||
return types.contains(DWORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is signed dword one of the potential types
|
|
||||||
*
|
|
||||||
* @return true if signed dword is a potential type
|
|
||||||
*/
|
|
||||||
public boolean isSDWord() {
|
|
||||||
return types.contains(SDWORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -63,6 +63,12 @@ public class TestPrograms {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTernaryInference() throws IOException, URISyntaxException {
|
||||||
|
compileAndCompare("ternary-inference");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMul8uMin() throws IOException, URISyntaxException {
|
public void testMul8uMin() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("mul8u-min");
|
compileAndCompare("mul8u-min");
|
||||||
@@ -98,11 +104,6 @@ public class TestPrograms {
|
|||||||
compileAndCompare("derefidx-word-0");
|
compileAndCompare("derefidx-word-0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTernaryInference() throws IOException, URISyntaxException {
|
|
||||||
compileAndCompare("ternary-inference", log());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFragmentVariations() throws IOException, URISyntaxException {
|
public void testFragmentVariations() throws IOException, URISyntaxException {
|
||||||
compileAndCompare("fragment-variations");
|
compileAndCompare("fragment-variations");
|
||||||
@@ -188,7 +189,6 @@ public class TestPrograms {
|
|||||||
compileAndCompare("sandbox");
|
compileAndCompare("sandbox");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//@Test
|
//@Test
|
||||||
//public void testPointerCast3() throws IOException, URISyntaxException {
|
//public void testPointerCast3() throws IOException, URISyntaxException {
|
||||||
// compileAndCompare("pointer-cast-3");
|
// compileAndCompare("pointer-cast-3");
|
||||||
|
@@ -48,8 +48,10 @@ byte myprintf(byte *dst, byte *str, word w1, word w2, word w3) {
|
|||||||
if (bTrailing != 0 && bDigits > b) for (; bDigits > b; --bDigits) dst[bLen++] = ' ';
|
if (bTrailing != 0 && bDigits > b) for (; bDigits > b; --bDigits) dst[bLen++] = ' ';
|
||||||
} else if (b == 'x' || b == 'X'){ // hex
|
} else if (b == 'x' || b == 'X'){ // hex
|
||||||
b = ((byte)w >> 4) & 0xF;
|
b = ((byte)w >> 4) & 0xF;
|
||||||
dst[bLen++] = (b < 10 ? '0' : 0x57) + b; // "('a' - 10)" is the normal way -- not supported -- https://gitlab.com/camelot/kickc/issues/184 [FIXED]
|
dst[bLen++] = (b < 10 ? '0' : 0x57ub) + b;
|
||||||
b = (byte)w & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57) + b;
|
// "('a' - 10)" is the normal way -- not supported -- https://gitlab.com/camelot/kickc/issues/184 [FIXED]
|
||||||
|
// (b < 10 ? '0' : 0x57) not supported
|
||||||
|
b = (byte)w & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57ub) + b;
|
||||||
}
|
}
|
||||||
bFormat = 0;
|
bFormat = 0;
|
||||||
continue;
|
continue;
|
||||||
|
@@ -1,10 +1,8 @@
|
|||||||
// Type inference into the ternary operator
|
// Type inference into the ternary operator
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
const byte* screen = 0x400;
|
const byte* screen = 0x400;
|
||||||
for(byte i: 0..10) {
|
for(byte i: 0..10) {
|
||||||
screen[i] = (i<5?0x57:'0')+i;
|
screen[i] = (i<5?0x57ub:'0')+i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -152,11 +152,10 @@ Print: {
|
|||||||
}
|
}
|
||||||
// myprintf(byte* zeropage(8) str, word zeropage(2) w1, word zeropage(4) w2, word zeropage(6) w3)
|
// myprintf(byte* zeropage(8) str, word zeropage(2) w1, word zeropage(4) w2, word zeropage(6) w3)
|
||||||
myprintf: {
|
myprintf: {
|
||||||
.label _17 = $12
|
|
||||||
.label str = 8
|
.label str = 8
|
||||||
.label bDigits = $11
|
.label bDigits = $11
|
||||||
.label bLen = $10
|
.label bLen = $10
|
||||||
.label digit = $a
|
.label b = $a
|
||||||
.label bArg = $b
|
.label bArg = $b
|
||||||
.label return = $10
|
.label return = $10
|
||||||
.label w1 = 2
|
.label w1 = 2
|
||||||
@@ -228,19 +227,13 @@ myprintf: {
|
|||||||
sta bFormat
|
sta bFormat
|
||||||
jmp b27
|
jmp b27
|
||||||
b26:
|
b26:
|
||||||
lda w+1
|
|
||||||
sta _17+1
|
|
||||||
lda w
|
lda w
|
||||||
sta _17
|
lsr
|
||||||
ldy #4
|
lsr
|
||||||
!:
|
lsr
|
||||||
lsr _17+1
|
lsr
|
||||||
ror _17
|
ldx #$f
|
||||||
dey
|
axs #0
|
||||||
bne !-
|
|
||||||
lda _17
|
|
||||||
and #$f
|
|
||||||
tax
|
|
||||||
cpx #$a
|
cpx #$a
|
||||||
bcc b8
|
bcc b8
|
||||||
lda #$57
|
lda #$57
|
||||||
@@ -255,8 +248,8 @@ myprintf: {
|
|||||||
sta strTemp,y
|
sta strTemp,y
|
||||||
iny
|
iny
|
||||||
lda w
|
lda w
|
||||||
and #$f
|
ldx #$f
|
||||||
tax
|
axs #0
|
||||||
cpx #$a
|
cpx #$a
|
||||||
bcc b10
|
bcc b10
|
||||||
lda #$57
|
lda #$57
|
||||||
@@ -277,35 +270,33 @@ myprintf: {
|
|||||||
lda w+1
|
lda w+1
|
||||||
sta utoa.value+1
|
sta utoa.value+1
|
||||||
jsr utoa
|
jsr utoa
|
||||||
ldx #1
|
lda #1
|
||||||
|
sta b
|
||||||
b12:
|
b12:
|
||||||
lda buf6,x
|
ldy b
|
||||||
|
lda buf6,y
|
||||||
cmp #0
|
cmp #0
|
||||||
bne b13
|
bne b13
|
||||||
lda bTrailing
|
lda bTrailing
|
||||||
cmp #0
|
cmp #0
|
||||||
beq b39
|
beq b39
|
||||||
b15:
|
b15:
|
||||||
lda #0
|
ldx #0
|
||||||
sta digit
|
|
||||||
b19:
|
b19:
|
||||||
ldy digit
|
lda buf6,x
|
||||||
lda buf6,y
|
|
||||||
ldy bLen
|
ldy bLen
|
||||||
sta strTemp,y
|
sta strTemp,y
|
||||||
inc bLen
|
inc bLen
|
||||||
inc digit
|
inx
|
||||||
txa
|
cpx b
|
||||||
cmp digit
|
bcc b19
|
||||||
beq !+
|
|
||||||
bcs b19
|
|
||||||
!:
|
|
||||||
lda bTrailing
|
lda bTrailing
|
||||||
cmp #0
|
cmp #0
|
||||||
bne b40
|
bne b40
|
||||||
jmp b22
|
jmp b22
|
||||||
b40:
|
b40:
|
||||||
cpx bDigits
|
lda b
|
||||||
|
cmp bDigits
|
||||||
bcc b21
|
bcc b21
|
||||||
jmp b22
|
jmp b22
|
||||||
b21:
|
b21:
|
||||||
@@ -314,11 +305,13 @@ myprintf: {
|
|||||||
sta strTemp,y
|
sta strTemp,y
|
||||||
inc bLen
|
inc bLen
|
||||||
dec bDigits
|
dec bDigits
|
||||||
cpx bDigits
|
lda b
|
||||||
|
cmp bDigits
|
||||||
bcc b21
|
bcc b21
|
||||||
jmp b22
|
jmp b22
|
||||||
b39:
|
b39:
|
||||||
cpx bDigits
|
lda b
|
||||||
|
cmp bDigits
|
||||||
bcc b16
|
bcc b16
|
||||||
jmp b15
|
jmp b15
|
||||||
b16:
|
b16:
|
||||||
@@ -334,11 +327,12 @@ myprintf: {
|
|||||||
sta strTemp,y
|
sta strTemp,y
|
||||||
inc bLen
|
inc bLen
|
||||||
dec bDigits
|
dec bDigits
|
||||||
cpx bDigits
|
lda b
|
||||||
|
cmp bDigits
|
||||||
bcc b16
|
bcc b16
|
||||||
jmp b15
|
jmp b15
|
||||||
b13:
|
b13:
|
||||||
inx
|
inc b
|
||||||
jmp b12
|
jmp b12
|
||||||
b6:
|
b6:
|
||||||
lda w
|
lda w
|
||||||
|
24
src/test/ref/ternary-inference.asm
Normal file
24
src/test/ref/ternary-inference.asm
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// Type inference into the ternary operator
|
||||||
|
.pc = $801 "Basic"
|
||||||
|
:BasicUpstart(main)
|
||||||
|
.pc = $80d "Program"
|
||||||
|
main: {
|
||||||
|
.label screen = $400
|
||||||
|
ldx #0
|
||||||
|
b1:
|
||||||
|
cpx #5
|
||||||
|
bcc b2
|
||||||
|
lda #'0'
|
||||||
|
jmp b3
|
||||||
|
b2:
|
||||||
|
lda #$57
|
||||||
|
b3:
|
||||||
|
stx $ff
|
||||||
|
clc
|
||||||
|
adc $ff
|
||||||
|
sta screen,x
|
||||||
|
inx
|
||||||
|
cpx #$b
|
||||||
|
bne b1
|
||||||
|
rts
|
||||||
|
}
|
Reference in New Issue
Block a user