1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-09-08 17:54:40 +00:00

Fixed precedence problems for casts and inc/dec

This commit is contained in:
Jesper Gravgaard 2018-03-05 10:10:56 +01:00
parent f4196b9e67
commit 133f8603c7
21 changed files with 59 additions and 59 deletions

View File

@ -66,7 +66,7 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
} else {
return "$ff & " + getAsmConstant(program, operand, Operator.BOOL_AND.getPrecedence(), codeScope);
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long)0xff), Operator.BOOL_AND, operand), outerPrecedence, codeScope);
}
} else if(Operator.CAST_WORD.equals(operator) || Operator.CAST_SWORD.equals(operator) || Operator.CAST_PTRBY.equals(operator)) {
SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand);
@ -74,7 +74,7 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
} else {
return "$ffff & " + getAsmConstant(program, operand, Operator.BOOL_AND.getPrecedence(), codeScope);
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long)0xffff), Operator.BOOL_AND, operand), outerPrecedence, codeScope);
}
} else if(Operator.CAST_DWORD.equals(operator) || Operator.CAST_SDWORD.equals(operator)) {
SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand);
@ -82,7 +82,7 @@ public class AsmFormat {
// No cast needed
return getAsmConstant(program, operand, outerPrecedence, codeScope);
} else {
return "$ffffffff & " + getAsmConstant(program, operand, Operator.BOOL_AND.getPrecedence(), codeScope);
return getAsmConstant(program, new ConstantBinary(new ConstantInteger((long)0xffffffff), Operator.BOOL_AND, operand), outerPrecedence, codeScope);
}
} else if(Operator.LOWBYTE.equals(operator)) {
SymbolType operandType = SymbolTypeInference.inferType(program.getScope(), operand);
@ -91,7 +91,7 @@ public class AsmFormat {
} else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer) {
return "<" + getAsmConstant(program, operand, outerPrecedence, codeScope);
} else if(SymbolType.isDWord(operandType) || SymbolType.isSDWord(operandType)) {
return getAsmConstant(program, operand, outerPrecedence, codeScope) + "&$ffff";
return getAsmConstant(program, new ConstantBinary(operand, Operator.BOOL_AND, new ConstantInteger((long)0xffff)), outerPrecedence, codeScope);
} else {
throw new CompileError("Unhandled type "+operand);
}
@ -102,14 +102,14 @@ public class AsmFormat {
} else if(SymbolType.isWord(operandType) || SymbolType.isSWord(operandType) || operandType instanceof SymbolTypePointer) {
return ">" + getAsmConstant(program, operand, outerPrecedence, codeScope);
} else if(SymbolType.isDWord(operandType) || SymbolType.isSDWord(operandType)) {
return getAsmConstant(program, operand, outerPrecedence, codeScope) + ">>16";
return getAsmConstant(program, new ConstantBinary(operand, Operator.SHIFT_RIGHT, new ConstantInteger((long)16)), outerPrecedence, codeScope);
} else {
throw new CompileError("Unhandled type "+operand);
}
} else if(Operator.INCREMENT.equals(operator)) {
return getAsmConstant(program, operand, Operator.PLUS.getPrecedence(), codeScope) + "+1";
return getAsmConstant(program, new ConstantBinary(operand, Operator.PLUS, new ConstantInteger((long)1)), outerPrecedence, codeScope);
} else if(Operator.DECREMENT.equals(operator)) {
return getAsmConstant(program, operand, Operator.PLUS.getPrecedence(), codeScope) + "-1";
return getAsmConstant(program, new ConstantBinary(operand, Operator.MINUS, new ConstantInteger((long)1)), outerPrecedence, codeScope);
} else {
return operator.getOperator() +
getAsmConstant(program, operand, operator.getPrecedence(), codeScope);

View File

@ -18,7 +18,7 @@ main: {
sta FGCOL
lda #BMM|DEN|RSEL|3
sta D011
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
jsr init_screen
jsr init_plot_tables

View File

@ -4288,7 +4288,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]
@ -5639,7 +5639,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]
@ -7070,7 +7070,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [180] phi from main to init_screen [phi:main->init_screen]

View File

@ -19,7 +19,7 @@ main: {
sta FGCOL
lda #BMM|DEN|RSEL|3
sta D011
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
jsr init_screen
jsr init_plot_tables

View File

@ -1783,7 +1783,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]
@ -2321,7 +2321,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]
@ -2912,7 +2912,7 @@ main: {
lda #BMM|DEN|RSEL|3
sta D011
//SEG12 [7] *((const byte*) D018#0) ← ((byte))((word))(const byte*) SCREEN#0/(byte/signed byte/word/signed word/dword/signed dword) 64|((word))(const byte*) BITMAP#0/(word/signed word/dword/signed dword) 1024 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #$ff & ($ffff & SCREEN/$40|$ffff & BITMAP/$400)
lda #$ff&(($ffff&SCREEN)/$40|($ffff&BITMAP)/$400)
sta D018
//SEG13 [8] call init_screen param-assignment [ ] ( main:2 [ ] )
//SEG14 [63] phi from main to init_screen [phi:main->init_screen]

View File

@ -10,7 +10,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = $ff & sumw>>1+1
.const midw = ($ff&sumw>>1)+1
lda #midw
sta SCREEN+0
lda #midb

View File

@ -346,7 +346,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = $ff & sumw>>1+1
.const midw = ($ff&sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0
@ -421,7 +421,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = $ff & sumw>>1+1
.const midw = ($ff&sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0
@ -520,7 +520,7 @@ main: {
.const sumw = min+max
.const sumb = min+max
.const midb = (sumb>>1)+1
.const midw = $ff & sumw>>1+1
.const midw = ($ff&sumw>>1)+1
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← (const byte) main::midw#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #midw
sta SCREEN+0

View File

@ -488,9 +488,9 @@ div32u16u: {
sta divr16u.divisor
lda #>main.wavelength
sta divr16u.divisor+1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
lda #<0
sta divr16u.rem

View File

@ -6614,9 +6614,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG269 [142] phi (word) divr16u::dividend#5 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG270 [142] phi (word) divr16u::rem#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0
@ -8023,9 +8023,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG269 [142] phi (word) divr16u::dividend#5 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG270 [142] phi (word) divr16u::rem#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0
@ -9444,9 +9444,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG269 [142] phi (word) divr16u::dividend#5 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG270 [142] phi (word) divr16u::rem#10 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0

View File

@ -490,9 +490,9 @@ div32u16u: {
sta divr16u.divisor
lda #>main.wavelength
sta divr16u.divisor+1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
lda #<0
sta divr16u.rem

View File

@ -8046,9 +8046,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG265 [144] phi (word) divr16u::dividend#6 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG266 [144] phi (word) divr16u::rem#11 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0
@ -10178,9 +10178,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG265 [144] phi (word) divr16u::dividend#6 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG266 [144] phi (word) divr16u::rem#11 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0
@ -12310,9 +12310,9 @@ div32u16u: {
lda #>main.wavelength
sta divr16u.divisor+1
//SEG265 [144] phi (word) divr16u::dividend#6 = >(const dword) PI2_u4f28#0 [phi:div32u16u->divr16u#1] -- vwuz1=vwuc1
lda #<PI2_u4f28>>16
lda #<PI2_u4f28>>$10
sta divr16u.dividend
lda #>PI2_u4f28>>16
lda #>PI2_u4f28>>$10
sta divr16u.dividend+1
//SEG266 [144] phi (word) divr16u::rem#11 = (byte/signed byte/word/signed word/dword/signed dword) 0 [phi:div32u16u->divr16u#2] -- vwuz1=vbuc1
lda #<0

View File

@ -5,9 +5,9 @@
jsr main
main: {
.label SCREEN = $400
lda #>PI_u4f28>>16
lda #>PI_u4f28>>$10
sta SCREEN+0
lda #<PI_u4f28>>16
lda #<PI_u4f28>>$10
sta SCREEN+1
lda #>PI_u4f28&$ffff
sta SCREEN+2

View File

@ -241,10 +241,10 @@ bend:
main: {
.label SCREEN = $400
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← >>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28>>16
lda #>PI_u4f28>>$10
sta SCREEN+0
//SEG10 [5] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← <>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #<PI_u4f28>>16
lda #<PI_u4f28>>$10
sta SCREEN+1
//SEG11 [6] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← ><(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28&$ffff
@ -297,10 +297,10 @@ bend:
main: {
.label SCREEN = $400
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← >>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28>>16
lda #>PI_u4f28>>$10
sta SCREEN+0
//SEG10 [5] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← <>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #<PI_u4f28>>16
lda #<PI_u4f28>>$10
sta SCREEN+1
//SEG11 [6] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← ><(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28&$ffff
@ -362,10 +362,10 @@ Score: 36
main: {
.label SCREEN = $400
//SEG9 [4] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 0) ← >>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28>>16
lda #>PI_u4f28>>$10
sta SCREEN+0
//SEG10 [5] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 1) ← <>(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #<PI_u4f28>>16
lda #<PI_u4f28>>$10
sta SCREEN+1
//SEG11 [6] *((const byte*) main::SCREEN#0+(byte/signed byte/word/signed word/dword/signed dword) 2) ← ><(const dword) PI_u4f28#0 [ ] ( main:2 [ ] ) -- _deref_pbuc1=vbuc2
lda #>PI_u4f28&$ffff