1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-02-09 18:31:23 +00:00

Fixed tests

This commit is contained in:
jespergravgaard 2019-05-19 01:16:12 +02:00
parent f31dc244b5
commit 6246871538
7 changed files with 62 additions and 182 deletions

View File

@ -323,7 +323,6 @@ public class Compiler {
constantOptimizations.add(new PassNSimplifyConstantZero(program));
constantOptimizations.add(new PassNSimplifyExpressionWithZero(program));
pass2Execute(constantOptimizations);
}

View File

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

View File

@ -63,6 +63,12 @@ public class TestPrograms {
*/
@Test
public void testTernaryInference() throws IOException, URISyntaxException {
compileAndCompare("ternary-inference");
}
@Test
public void testMul8uMin() throws IOException, URISyntaxException {
compileAndCompare("mul8u-min");
@ -98,11 +104,6 @@ public class TestPrograms {
compileAndCompare("derefidx-word-0");
}
@Test
public void testTernaryInference() throws IOException, URISyntaxException {
compileAndCompare("ternary-inference", log());
}
@Test
public void testFragmentVariations() throws IOException, URISyntaxException {
compileAndCompare("fragment-variations");
@ -188,7 +189,6 @@ public class TestPrograms {
compileAndCompare("sandbox");
}
//@Test
//public void testPointerCast3() throws IOException, URISyntaxException {
// compileAndCompare("pointer-cast-3");

View File

@ -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++] = ' ';
} else if (b == 'x' || b == 'X'){ // hex
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]
b = (byte)w & 0xF; dst[bLen++] = (b < 10 ? '0' : 0x57) + b;
dst[bLen++] = (b < 10 ? '0' : 0x57ub) + 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;
continue;

View File

@ -1,10 +1,8 @@
// Type inference into the ternary operator
void main() {
const byte* screen = 0x400;
for(byte i: 0..10) {
screen[i] = (i<5?0x57:'0')+i;
screen[i] = (i<5?0x57ub:'0')+i;
}
}

View File

@ -152,11 +152,10 @@ Print: {
}
// myprintf(byte* zeropage(8) str, word zeropage(2) w1, word zeropage(4) w2, word zeropage(6) w3)
myprintf: {
.label _17 = $12
.label str = 8
.label bDigits = $11
.label bLen = $10
.label digit = $a
.label b = $a
.label bArg = $b
.label return = $10
.label w1 = 2
@ -228,19 +227,13 @@ myprintf: {
sta bFormat
jmp b27
b26:
lda w+1
sta _17+1
lda w
sta _17
ldy #4
!:
lsr _17+1
ror _17
dey
bne !-
lda _17
and #$f
tax
lsr
lsr
lsr
lsr
ldx #$f
axs #0
cpx #$a
bcc b8
lda #$57
@ -255,8 +248,8 @@ myprintf: {
sta strTemp,y
iny
lda w
and #$f
tax
ldx #$f
axs #0
cpx #$a
bcc b10
lda #$57
@ -277,35 +270,33 @@ myprintf: {
lda w+1
sta utoa.value+1
jsr utoa
ldx #1
lda #1
sta b
b12:
lda buf6,x
ldy b
lda buf6,y
cmp #0
bne b13
lda bTrailing
cmp #0
beq b39
b15:
lda #0
sta digit
ldx #0
b19:
ldy digit
lda buf6,y
lda buf6,x
ldy bLen
sta strTemp,y
inc bLen
inc digit
txa
cmp digit
beq !+
bcs b19
!:
inx
cpx b
bcc b19
lda bTrailing
cmp #0
bne b40
jmp b22
b40:
cpx bDigits
lda b
cmp bDigits
bcc b21
jmp b22
b21:
@ -314,11 +305,13 @@ myprintf: {
sta strTemp,y
inc bLen
dec bDigits
cpx bDigits
lda b
cmp bDigits
bcc b21
jmp b22
b39:
cpx bDigits
lda b
cmp bDigits
bcc b16
jmp b15
b16:
@ -334,11 +327,12 @@ myprintf: {
sta strTemp,y
inc bLen
dec bDigits
cpx bDigits
lda b
cmp bDigits
bcc b16
jmp b15
b13:
inx
inc b
jmp b12
b6:
lda w

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