mirror of
https://gitlab.com/camelot/kickc.git
synced 2025-04-07 06:37:31 +00:00
Added support for character escape sequence '\0'. Closes #642
This commit is contained in:
parent
3757733876
commit
66b73ddd56
@ -165,6 +165,8 @@ public enum StringEncoding {
|
||||
return '\r';
|
||||
case 'f':
|
||||
return '\f';
|
||||
case '0':
|
||||
return '\0';
|
||||
case '"':
|
||||
return '"';
|
||||
case '\'':
|
||||
@ -205,6 +207,8 @@ public enum StringEncoding {
|
||||
return "\\r";
|
||||
case '\f':
|
||||
return "\\f";
|
||||
case '\0':
|
||||
return "\\$00";
|
||||
case '\"':
|
||||
return "\\\"";
|
||||
case '\'':
|
||||
|
@ -1531,6 +1531,11 @@ public class TestProgramsFast extends TestPrograms {
|
||||
assertError("string-escapes-err-0.c", "Unfinished string escape sequence at end of string");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringEscapes7() throws IOException {
|
||||
compileAndCompare("string-escapes-6.c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringEscapes5() throws IOException {
|
||||
compileAndCompare("string-escapes-5.c");
|
||||
|
18
src/test/kc/string-escapes-6.c
Normal file
18
src/test/kc/string-escapes-6.c
Normal file
@ -0,0 +1,18 @@
|
||||
// Test using some simple supported string escape
|
||||
// Uses \0 to add null-characters
|
||||
|
||||
char MESSAGE[] = "a\0bb\0ccc\0";
|
||||
|
||||
char * const SCREEN = (char*)0x0400;
|
||||
|
||||
void main() {
|
||||
char i=0;
|
||||
while(MESSAGE[i]) {
|
||||
while(MESSAGE[i]) {
|
||||
SCREEN[i] = MESSAGE[i];
|
||||
i++;
|
||||
}
|
||||
SCREEN[i] = ' ';
|
||||
i++;
|
||||
}
|
||||
}
|
43
src/test/ref/string-escapes-6.asm
Normal file
43
src/test/ref/string-escapes-6.asm
Normal file
@ -0,0 +1,43 @@
|
||||
// Test using some simple supported string escape
|
||||
// Uses \0 to add null-characters
|
||||
// Commodore 64 PRG executable file
|
||||
.file [name="string-escapes-6.prg", type="prg", segments="Program"]
|
||||
.segmentdef Program [segments="Basic, Code, Data"]
|
||||
.segmentdef Basic [start=$0801]
|
||||
.segmentdef Code [start=$80d]
|
||||
.segmentdef Data [startAfter="Code"]
|
||||
.segment Basic
|
||||
:BasicUpstart(main)
|
||||
.label SCREEN = $400
|
||||
.segment Code
|
||||
main: {
|
||||
ldx #0
|
||||
__b1:
|
||||
// while(MESSAGE[i])
|
||||
lda MESSAGE,x
|
||||
cmp #0
|
||||
bne __b2
|
||||
// }
|
||||
rts
|
||||
__b2:
|
||||
// while(MESSAGE[i])
|
||||
lda MESSAGE,x
|
||||
cmp #0
|
||||
bne __b3
|
||||
// SCREEN[i] = ' '
|
||||
lda #' '
|
||||
sta SCREEN,x
|
||||
// i++;
|
||||
inx
|
||||
jmp __b1
|
||||
__b3:
|
||||
// SCREEN[i] = MESSAGE[i]
|
||||
lda MESSAGE,x
|
||||
sta SCREEN,x
|
||||
// i++;
|
||||
inx
|
||||
jmp __b2
|
||||
}
|
||||
.segment Data
|
||||
MESSAGE: .text @"a\$00bb\$00ccc\$00"
|
||||
.byte 0
|
24
src/test/ref/string-escapes-6.cfg
Normal file
24
src/test/ref/string-escapes-6.cfg
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
void main()
|
||||
main: scope:[main] from
|
||||
[0] phi()
|
||||
to:main::@1
|
||||
main::@1: scope:[main] from main main::@4
|
||||
[1] main::i#3 = phi( main/0, main::@4/main::i#2 )
|
||||
[2] if(0!=MESSAGE[main::i#3]) goto main::@2
|
||||
to:main::@return
|
||||
main::@return: scope:[main] from main::@1
|
||||
[3] return
|
||||
to:@return
|
||||
main::@2: scope:[main] from main::@1 main::@3
|
||||
[4] main::i#4 = phi( main::@1/main::i#3, main::@3/main::i#1 )
|
||||
[5] if(0!=MESSAGE[main::i#4]) goto main::@3
|
||||
to:main::@4
|
||||
main::@4: scope:[main] from main::@2
|
||||
[6] SCREEN[main::i#4] = ' '
|
||||
[7] main::i#2 = ++ main::i#4
|
||||
to:main::@1
|
||||
main::@3: scope:[main] from main::@2
|
||||
[8] SCREEN[main::i#4] = MESSAGE[main::i#4]
|
||||
[9] main::i#1 = ++ main::i#4
|
||||
to:main::@2
|
BIN
src/test/ref/string-escapes-6.log
Normal file
BIN
src/test/ref/string-escapes-6.log
Normal file
Binary file not shown.
BIN
src/test/ref/string-escapes-6.sym
Normal file
BIN
src/test/ref/string-escapes-6.sym
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user