1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-10-10 20:23:47 +00:00

Added error when condition is non-boolean. Closes #134

This commit is contained in:
jespergravgaard 2019-01-17 23:28:39 +01:00
parent bb9a4ac461
commit b6038ccf0a
10 changed files with 5364 additions and 5470 deletions

View File

@ -23,7 +23,7 @@ public class OperatorLogicNot extends OperatorUnary {
@Override
public SymbolType inferType(SymbolTypeSimple operandType) {
return SymbolType.BOOLEAN;
return operandType;
}
}

View File

@ -1,11 +1,13 @@
package dk.camelot64.kickc.passes;
import dk.camelot64.kickc.model.*;
import dk.camelot64.kickc.model.statements.StatementConditionalJump;
import dk.camelot64.kickc.model.values.LValue;
import dk.camelot64.kickc.model.statements.Statement;
import dk.camelot64.kickc.model.statements.StatementAssignment;
import dk.camelot64.kickc.model.types.SymbolType;
import dk.camelot64.kickc.model.types.SymbolTypeInference;
import dk.camelot64.kickc.model.values.RValue;
/**
* Asserts that types match in all assignments and calculations
@ -23,7 +25,20 @@ public class Pass2AssertTypeMatch extends Pass2SsaAssertion {
if(statement instanceof StatementAssignment) {
checkAssignment((StatementAssignment) statement);
}
// TODO: Implement checking for calls / conditional jumps / ...
if(statement instanceof StatementConditionalJump) {
StatementConditionalJump conditionalJump = (StatementConditionalJump) statement;
if(conditionalJump.getOperator()==null) {
RValue rValue = conditionalJump.getrValue2();
SymbolType rValueType = SymbolTypeInference.inferType(getScope(), rValue);
if(!SymbolTypeInference.typeMatch(SymbolType.BOOLEAN, rValueType)) {
getLog().append("ERROR! Type mismatch non-boolean condition from (" + rValueType.getTypeName() + "). In " + statement.toString(getProgram(), false));
throw new CompileError("ERROR! Type mismatch non-boolean condition from (" + rValueType.getTypeName() + "). In " + statement.toString(getProgram(), false), statement.getSource());
}
} else {
// Conditions with operators always result in booleans?
}
}
// TODO: Implement checking for calls / ...
}
}

View File

@ -1137,6 +1137,11 @@ public class TestPrograms {
assertError("no-returninterrupt", "Interrupts cannot return anything.");
}
@Test
public void testConditionTypeMismatch() throws IOException, URISyntaxException {
assertError("condition-type-mismatch", "Type mismatch non-boolean condition");
}
private void assertError(String kcFile, String expectError) throws IOException, URISyntaxException {
try {
compileAndCompare(kcFile);

View File

@ -49,7 +49,7 @@ dword score_bcd = 0;
word lines_bcd = 0;
// Current level BCD-format
byte level_bcd = 0;
// Current level in normal numeric format
// Current level in hexadecimal format
byte level = 0;
// Is the game over?
byte game_over = 0;

View File

@ -154,19 +154,18 @@ void render_playfield() {
}
// Render the current moving piece at position (current_xpos, current_ypos)
// Ignores cases where parts of the tetromino is outside the playfield (sides/bottom) since the movement collision routine prevents this.
void render_moving() {
byte i = 0;
byte ypos2 = current_ypos<<1;
for(byte l:0..3) {
if(ypos2>2 && ypos2<2*PLAYFIELD_LINES) {
if(ypos2>2) {
byte* screen_line = screen_lines_1[render_screen_render+ypos2];
byte xpos = current_xpos;
for(byte c:0..3) {
byte current_cell = current_piece_gfx[i++];
if(current_cell!=0) {
if(xpos<PLAYFIELD_COLS) {
screen_line[xpos] = current_piece_char;
}
screen_line[xpos] = current_piece_char;
}
xpos++;
}

View File

@ -0,0 +1,9 @@
// Tests a condition type mismatch (not boolean)
void main() {
byte b = 12;
if(b) {
byte* screen = $400;
*screen = 'a';
}
}

View File

@ -100,12 +100,12 @@
.label current_piece_16 = 5
.label render_screen_render_30 = 9
.label current_xpos_57 = $a
.label current_piece_gfx_63 = 5
.label render_screen_render_66 = 9
.label current_xpos_126 = $a
.label current_xpos_127 = $a
.label current_piece_gfx_116 = 5
.label current_piece_gfx_117 = 5
.label current_piece_gfx_62 = 5
.label render_screen_render_64 = 9
.label current_xpos_124 = $a
.label current_xpos_125 = $a
.label current_piece_gfx_114 = 5
.label current_piece_gfx_115 = 5
.label current_piece_90 = 5
.label current_piece_91 = 5
.label current_piece_92 = 5
@ -137,11 +137,11 @@ main: {
jsr render_playfield
ldy current_ypos
lda current_xpos
sta current_xpos_126
sta current_xpos_124
lda current_piece_gfx
sta current_piece_gfx_116
sta current_piece_gfx_114
lda current_piece_gfx+1
sta current_piece_gfx_116+1
sta current_piece_gfx_114+1
ldx current_piece_char
lda #$40
sta render_screen_render_30
@ -190,13 +190,13 @@ main: {
jsr render_playfield
ldy current_ypos
lda render_screen_render
sta render_screen_render_66
sta render_screen_render_64
lda current_xpos
sta current_xpos_127
sta current_xpos_125
lda current_piece_gfx
sta current_piece_gfx_117
sta current_piece_gfx_115
lda current_piece_gfx+1
sta current_piece_gfx_117+1
sta current_piece_gfx_115+1
ldx current_piece_char
jsr render_moving
jsr render_score
@ -335,9 +335,8 @@ render_moving: {
lda ypos2
cmp #2
beq !+
bcs b13
bcs b2
!:
b7:
lda #4
clc
adc i
@ -352,11 +351,6 @@ render_moving: {
cmp #4
bne b1
rts
b13:
lda ypos2
cmp #2*PLAYFIELD_LINES
bcc b2
jmp b7
b2:
lda render_screen_render_30
clc
@ -372,14 +366,11 @@ render_moving: {
sta c
b4:
ldy i
lda (current_piece_gfx_63),y
lda (current_piece_gfx_62),y
inc i
cmp #0
beq b5
lda xpos
cmp #PLAYFIELD_COLS
bcs b5
tay
ldy xpos
txa
sta (screen_line),y
b5:

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -317,35 +317,35 @@
(byte*~) current_piece#94 current_piece#94 zp ZP_WORD:5 4.0
(byte*~) current_piece#95 current_piece zp ZP_WORD:26 4.0
(byte) current_piece_char
(byte~) current_piece_char#104 reg byte x 4.0
(byte~) current_piece_char#105 reg byte x 22.0
(byte~) current_piece_char#102 reg byte x 4.0
(byte~) current_piece_char#103 reg byte x 22.0
(byte) current_piece_char#14 current_piece_char zp ZP_BYTE:28 3.628571428571428
(byte) current_piece_char#16 current_piece_char zp ZP_BYTE:28 0.32
(byte) current_piece_char#19 current_piece_char zp ZP_BYTE:28 187.38888888888889
(byte) current_piece_char#27 current_piece_char zp ZP_BYTE:28 6.0
(byte) current_piece_char#76 reg byte x 46.09090909090909
(byte) current_piece_char#64 reg byte x 50.699999999999996
(byte*) current_piece_gfx
(byte*) current_piece_gfx#105 current_piece_gfx zp ZP_WORD:30 187.38888888888889
(byte*~) current_piece_gfx#116 current_piece_gfx#116 zp ZP_WORD:5 2.0
(byte*~) current_piece_gfx#117 current_piece_gfx#117 zp ZP_WORD:5 11.0
(byte*) current_piece_gfx#103 current_piece_gfx zp ZP_WORD:30 187.38888888888889
(byte*~) current_piece_gfx#114 current_piece_gfx#114 zp ZP_WORD:5 2.0
(byte*~) current_piece_gfx#115 current_piece_gfx#115 zp ZP_WORD:5 11.0
(byte*) current_piece_gfx#16 current_piece_gfx zp ZP_WORD:30 7.055555555555554
(byte*) current_piece_gfx#18 current_piece_gfx zp ZP_WORD:30 0.3571428571428571
(byte*) current_piece_gfx#19 current_piece_gfx zp ZP_WORD:30 1.3333333333333333
(byte*) current_piece_gfx#21 current_piece_gfx zp ZP_WORD:30 0.3333333333333333
(byte*) current_piece_gfx#33 current_piece_gfx zp ZP_WORD:30 6.0
(byte*) current_piece_gfx#6 current_piece_gfx zp ZP_WORD:30 4.0
(byte*) current_piece_gfx#63 current_piece_gfx#63 zp ZP_WORD:5 46.09090909090909
(byte*) current_piece_gfx#62 current_piece_gfx#62 zp ZP_WORD:5 50.699999999999996
(byte) current_xpos
(byte) current_xpos#115 current_xpos zp ZP_BYTE:32 20.75925925925926
(byte~) current_xpos#126 current_xpos#126 zp ZP_BYTE:10 1.3333333333333333
(byte~) current_xpos#127 current_xpos#127 zp ZP_BYTE:10 7.333333333333333
(byte) current_xpos#113 current_xpos zp ZP_BYTE:32 20.75925925925926
(byte~) current_xpos#124 current_xpos#124 zp ZP_BYTE:10 1.3333333333333333
(byte~) current_xpos#125 current_xpos#125 zp ZP_BYTE:10 7.333333333333333
(byte) current_xpos#17 current_xpos zp ZP_BYTE:32 7.055555555555554
(byte) current_xpos#20 current_xpos zp ZP_BYTE:32 0.7692307692307692
(byte) current_xpos#24 current_xpos zp ZP_BYTE:32 0.4666666666666666
(byte) current_xpos#28 current_xpos zp ZP_BYTE:32 0.43478260869565216
(byte) current_xpos#41 current_xpos zp ZP_BYTE:32 6.0
(byte) current_xpos#5 current_xpos zp ZP_BYTE:32 4.0
(byte) current_xpos#57 current_xpos#57 zp ZP_BYTE:10 5.181818181818182
(byte) current_xpos#57 current_xpos#57 zp ZP_BYTE:10 5.7
(byte) current_xpos#7 current_xpos zp ZP_BYTE:32 4.0
(byte) current_ypos
(byte~) current_ypos#100 reg byte y 1.0
@ -887,41 +887,39 @@
(byte) render_init::vicSelectGfxBank1_toDd001_return
(const byte) render_init::vicSelectGfxBank1_toDd001_return#0 vicSelectGfxBank1_toDd001_return = (byte/signed byte/word/signed word/dword/signed dword) 3^>((word))(const byte*) PLAYFIELD_CHARSET#0>>(byte/signed byte/word/signed word/dword/signed dword) 6
(void()) render_moving()
(byte~) render_moving::$5 reg byte a 202.0
(byte~) render_moving::$2 reg byte a 202.0
(label) render_moving::@1
(label) render_moving::@10
(label) render_moving::@13
(label) render_moving::@2
(label) render_moving::@3
(label) render_moving::@4
(label) render_moving::@5
(label) render_moving::@7
(label) render_moving::@9
(label) render_moving::@6
(label) render_moving::@8
(label) render_moving::@return
(byte) render_moving::c
(byte) render_moving::c#1 c zp ZP_BYTE:15 1501.5
(byte) render_moving::c#2 c zp ZP_BYTE:15 286.0
(byte) render_moving::c#2 c zp ZP_BYTE:15 333.6666666666667
(byte) render_moving::current_cell
(byte) render_moving::current_cell#0 reg byte a 1001.0
(byte) render_moving::i
(byte) render_moving::i#1 i zp ZP_BYTE:13 202.0
(byte) render_moving::i#10 i zp ZP_BYTE:13 429.0
(byte) render_moving::i#3 i zp ZP_BYTE:13 50.5
(byte) render_moving::i#2 i zp ZP_BYTE:13 500.5
(byte) render_moving::i#3 i zp ZP_BYTE:13 60.599999999999994
(byte) render_moving::i#4 i zp ZP_BYTE:13 1552.0
(byte) render_moving::i#8 i zp ZP_BYTE:13 300.75
(byte) render_moving::l
(byte) render_moving::l#1 l zp ZP_BYTE:12 151.5
(byte) render_moving::l#4 l zp ZP_BYTE:12 11.222222222222221
(byte) render_moving::l#4 l zp ZP_BYTE:12 12.625
(byte*) render_moving::screen_line
(byte*) render_moving::screen_line#0 screen_line zp ZP_WORD:7 100.18181818181819
(byte*) render_moving::screen_line#0 screen_line zp ZP_WORD:7 110.19999999999999
(byte) render_moving::xpos
(byte) render_moving::xpos#0 xpos zp ZP_BYTE:14 202.0
(byte) render_moving::xpos#1 xpos zp ZP_BYTE:14 667.3333333333334
(byte) render_moving::xpos#2 xpos zp ZP_BYTE:14 684.1666666666667
(byte) render_moving::xpos#2 xpos zp ZP_BYTE:14 620.8
(byte) render_moving::ypos2
(byte) render_moving::ypos2#0 ypos2 zp ZP_BYTE:11 4.0
(byte) render_moving::ypos2#1 ypos2 zp ZP_BYTE:11 67.33333333333333
(byte) render_moving::ypos2#2 ypos2 zp ZP_BYTE:11 29.823529411764707
(byte) render_moving::ypos2#2 ypos2 zp ZP_BYTE:11 27.06666666666667
(void()) render_playfield()
(byte~) render_playfield::$2 reg byte a 202.0
(byte~) render_playfield::$3 reg byte a 202.0
@ -1010,9 +1008,9 @@
(byte) render_screen_render#11 render_screen_render zp ZP_BYTE:3 3.25
(byte) render_screen_render#17 render_screen_render zp ZP_BYTE:3 0.7551020408163266
(byte) render_screen_render#21 reg byte x 8.615384615384615
(byte) render_screen_render#30 render_screen_render#30 zp ZP_BYTE:9 5.090909090909091
(byte~) render_screen_render#66 render_screen_render#66 zp ZP_BYTE:9 5.5
(byte~) render_screen_render#67 reg byte x 22.0
(byte) render_screen_render#30 render_screen_render#30 zp ZP_BYTE:9 5.6
(byte~) render_screen_render#64 render_screen_render#64 zp ZP_BYTE:9 5.5
(byte~) render_screen_render#65 reg byte x 22.0
(byte) render_screen_show
(byte) render_screen_show#13 render_screen_show zp ZP_BYTE:2 4.333333333333333
(byte) render_screen_show#16 render_screen_show zp ZP_BYTE:2 0.48571428571428577
@ -1128,20 +1126,20 @@ interrupt(HARDWARE_CLOBBER)(void()) sprites_irq()
zp ZP_BYTE:2 [ render_screen_show#16 render_screen_show#13 play_init::idx#2 play_init::idx#1 sprites_init::xpos#2 sprites_init::xpos#1 render_screen_original::y#6 render_screen_original::y#1 ]
zp ZP_BYTE:3 [ render_screen_render#17 render_screen_render#11 ]
zp ZP_BYTE:4 [ current_movedown_counter#16 current_movedown_counter#14 current_movedown_counter#12 play_remove_lines::y#8 play_remove_lines::y#1 play_lock_current::l#6 play_lock_current::l#1 play_spawn_current::$3 play_update_score::lines_before#0 ]
zp ZP_WORD:5 [ render_score::screen#2 render_bcd::screen#6 render_bcd::screen#0 render_bcd::screen#1 render_bcd::screen#2 render_bcd::screen#3 render_bcd::screen#4 render_bcd::screen#5 current_piece_gfx#63 current_piece_gfx#116 current_piece_gfx#117 render_playfield::screen_line#2 render_playfield::screen_line#0 render_playfield::screen_line#1 current_piece#16 current_piece#90 current_piece#91 current_piece#92 current_piece#93 current_piece#94 play_collision::piece_gfx#0 play_init::pli#2 play_init::pli#1 render_init::li_1#2 render_init::li_1#1 render_screen_original::oscr#2 render_screen_original::oscr#4 render_screen_original::oscr#1 play_lock_current::playfield_line#0 ]
zp ZP_WORD:5 [ render_score::screen#2 render_bcd::screen#6 render_bcd::screen#0 render_bcd::screen#1 render_bcd::screen#2 render_bcd::screen#3 render_bcd::screen#4 render_bcd::screen#5 current_piece_gfx#62 current_piece_gfx#114 current_piece_gfx#115 render_playfield::screen_line#2 render_playfield::screen_line#0 render_playfield::screen_line#1 current_piece#16 current_piece#90 current_piece#91 current_piece#92 current_piece#93 current_piece#94 play_collision::piece_gfx#0 play_init::pli#2 play_init::pli#1 render_init::li_1#2 render_init::li_1#1 render_screen_original::oscr#2 render_screen_original::oscr#4 render_screen_original::oscr#1 play_lock_current::playfield_line#0 ]
zp ZP_WORD:7 [ render_bcd::offset#6 render_bcd::screen_pos#3 render_bcd::screen_pos#0 render_bcd::screen_pos#2 render_bcd::screen_pos#1 render_init::li_2#2 render_init::li_2#1 render_screen_original::ocols#2 render_screen_original::ocols#4 render_screen_original::ocols#1 render_moving::screen_line#0 play_collision::playfield_line#0 ]
reg byte y [ render_bcd::only_low#6 ]
reg byte x [ render_bcd::bcd#6 render_bcd::bcd#0 render_bcd::bcd#1 render_bcd::bcd#2 render_bcd::bcd#3 render_bcd::bcd#4 render_bcd::bcd#5 ]
reg byte y [ current_ypos#11 current_ypos#100 current_ypos#101 ]
zp ZP_BYTE:9 [ render_screen_render#30 render_screen_render#66 render_playfield::l#2 render_playfield::l#1 play_movement::return#2 play_movement::render#1 play_movement::return#0 play_movement::render#2 play_remove_lines::removed#11 play_remove_lines::removed#7 play_remove_lines::removed#1 play_lock_current::i#2 play_lock_current::i#3 play_lock_current::i#7 play_lock_current::i#9 keyboard_event_pressed::keycode#5 keyboard_event_scan::row#2 keyboard_event_scan::row#1 ]
zp ZP_BYTE:10 [ current_xpos#57 current_xpos#126 current_xpos#127 render_playfield::i#2 render_playfield::i#3 render_playfield::i#1 play_move_rotate::orientation#3 play_move_rotate::orientation#1 play_move_rotate::orientation#2 play_remove_lines::x#2 play_remove_lines::x#1 play_lock_current::col#2 play_lock_current::col#0 play_lock_current::col#1 keyboard_event_scan::keycode#10 keyboard_event_scan::keycode#11 keyboard_event_scan::keycode#14 keyboard_event_scan::keycode#1 keyboard_event_scan::keycode#15 keyboard_event_pressed::row_bits#0 ]
reg byte x [ current_piece_char#76 current_piece_char#104 current_piece_char#105 ]
zp ZP_BYTE:9 [ render_screen_render#30 render_screen_render#64 render_playfield::l#2 render_playfield::l#1 play_movement::return#2 play_movement::render#1 play_movement::return#0 play_movement::render#2 play_remove_lines::removed#11 play_remove_lines::removed#7 play_remove_lines::removed#1 play_lock_current::i#2 play_lock_current::i#3 play_lock_current::i#7 play_lock_current::i#9 keyboard_event_pressed::keycode#5 keyboard_event_scan::row#2 keyboard_event_scan::row#1 ]
zp ZP_BYTE:10 [ current_xpos#57 current_xpos#124 current_xpos#125 render_playfield::i#2 render_playfield::i#3 render_playfield::i#1 play_move_rotate::orientation#3 play_move_rotate::orientation#1 play_move_rotate::orientation#2 play_remove_lines::x#2 play_remove_lines::x#1 play_lock_current::col#2 play_lock_current::col#0 play_lock_current::col#1 keyboard_event_scan::keycode#10 keyboard_event_scan::keycode#11 keyboard_event_scan::keycode#14 keyboard_event_scan::keycode#1 keyboard_event_scan::keycode#15 keyboard_event_pressed::row_bits#0 ]
reg byte x [ current_piece_char#64 current_piece_char#102 current_piece_char#103 ]
zp ZP_BYTE:11 [ render_moving::ypos2#2 render_moving::ypos2#0 render_moving::ypos2#1 render_playfield::c#2 render_playfield::c#1 play_collision::ypos#5 play_collision::ypos#0 play_collision::ypos#1 play_collision::ypos#2 play_collision::ypos#3 play_collision::ypos#4 play_collision::ypos2#2 play_collision::ypos2#0 play_collision::ypos2#1 play_remove_lines::full#4 play_remove_lines::full#2 play_lock_current::i#1 keyboard_event_scan::row_scan#0 ]
zp ZP_BYTE:12 [ render_moving::l#4 render_moving::l#1 play_collision::xpos#6 play_collision::xpos#0 play_collision::xpos#1 play_collision::xpos#2 play_collision::xpos#3 play_collision::xpos#4 play_remove_lines::c#0 ]
zp ZP_BYTE:13 [ render_moving::i#4 render_moving::i#3 render_moving::i#8 render_moving::i#10 render_moving::i#1 play_collision::l#6 play_collision::l#1 ]
zp ZP_BYTE:13 [ render_moving::i#4 render_moving::i#3 render_moving::i#8 render_moving::i#2 render_moving::i#1 play_collision::l#6 play_collision::l#1 ]
zp ZP_BYTE:14 [ render_moving::xpos#2 render_moving::xpos#0 render_moving::xpos#1 play_collision::i#2 play_collision::i#3 play_collision::i#11 play_collision::i#13 ]
zp ZP_BYTE:15 [ render_moving::c#2 render_moving::c#1 play_collision::col#2 play_collision::col#9 play_collision::col#1 ]
reg byte x [ render_screen_render#21 render_screen_render#67 ]
reg byte x [ render_screen_render#21 render_screen_render#65 ]
reg byte a [ play_move_rotate::return#2 ]
reg byte x [ play_collision::orientation#5 play_collision::orientation#0 play_collision::orientation#1 play_collision::orientation#2 play_collision::orientation#3 ]
reg byte x [ play_collision::c#2 play_collision::c#1 ]
@ -1157,8 +1155,8 @@ zp ZP_BYTE:25 [ level_bcd#32 level_bcd#19 level_bcd#11 level_bcd#17 level_bcd#64
zp ZP_WORD:26 [ current_piece#27 current_piece#95 current_piece#20 current_piece#14 current_piece#88 render_screen_original::cols#6 render_screen_original::cols#5 render_screen_original::cols#4 render_screen_original::cols#7 render_screen_original::cols#3 render_screen_original::cols#1 render_screen_original::cols#2 ]
zp ZP_BYTE:28 [ current_piece_char#27 current_piece_char#19 current_piece_char#14 current_piece_char#16 ]
zp ZP_BYTE:29 [ current_orientation#36 current_orientation#12 current_orientation#16 current_orientation#19 current_orientation#24 current_orientation#7 ]
zp ZP_WORD:30 [ current_piece_gfx#33 current_piece_gfx#105 current_piece_gfx#16 current_piece_gfx#21 current_piece_gfx#18 current_piece_gfx#19 current_piece_gfx#6 ]
zp ZP_BYTE:32 [ current_xpos#41 current_xpos#115 current_xpos#17 current_xpos#28 current_xpos#20 current_xpos#24 current_xpos#7 current_xpos#5 ]
zp ZP_WORD:30 [ current_piece_gfx#33 current_piece_gfx#103 current_piece_gfx#16 current_piece_gfx#21 current_piece_gfx#18 current_piece_gfx#19 current_piece_gfx#6 ]
zp ZP_BYTE:32 [ current_xpos#41 current_xpos#113 current_xpos#17 current_xpos#28 current_xpos#20 current_xpos#24 current_xpos#7 current_xpos#5 ]
reg byte x [ play_move_down::return#3 ]
zp ZP_BYTE:33 [ game_over#70 game_over#26 game_over#19 game_over#14 game_over#15 ]
reg byte x [ play_spawn_current::piece_idx#2 play_spawn_current::piece_idx#1 ]
@ -1190,7 +1188,7 @@ reg byte a [ render_bcd::$3 ]
reg byte a [ render_bcd::$4 ]
reg byte a [ render_bcd::$5 ]
reg byte a [ render_bcd::$6 ]
reg byte a [ render_moving::$5 ]
reg byte a [ render_moving::$2 ]
reg byte a [ render_moving::current_cell#0 ]
reg byte a [ render_playfield::$2 ]
reg byte a [ render_playfield::$3 ]