1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-11-23 23:32:55 +00:00

Added support for \\ escape code. #241

This commit is contained in:
jespergravgaard 2019-08-18 17:00:26 +02:00
parent 577e0f6011
commit 3c12acbb43
10 changed files with 26 additions and 16 deletions

View File

@ -76,6 +76,8 @@ public class ConstantChar implements ConstantLiteral<Character> {
return '\"'; return '\"';
case '\'': case '\'':
return '\''; return '\'';
case '\\':
return '\\';
default: default:
throw new CompileError("Illegal char escape sequence \\" + charString.charAt(1)); throw new CompileError("Illegal char escape sequence \\" + charString.charAt(1));
} }
@ -99,6 +101,8 @@ public class ConstantChar implements ConstantLiteral<Character> {
return "\\f"; return "\\f";
case '\'': case '\'':
return "\\'"; return "\\'";
case '\\':
return "\\\\";
default: default:
return Character.toString(aChar); return Character.toString(aChar);
} }

View File

@ -133,6 +133,9 @@ public class ConstantString implements ConstantLiteral<String> {
case '\'': case '\'':
stringChar = '\''; stringChar = '\'';
break; break;
case '\\':
stringChar = '\\';
break;
default: default:
throw new CompileError("Illegal string escape sequence \\" + escapeChar); throw new CompileError("Illegal string escape sequence \\" + escapeChar);
} }
@ -167,6 +170,9 @@ public class ConstantString implements ConstantLiteral<String> {
case '"': case '"':
stringResult.append("\\\""); stringResult.append("\\\"");
break; break;
case '\\':
stringResult.append("\\\\");
break;
default: default:
stringResult.append(stringChar); stringResult.append(stringChar);
} }

View File

@ -1,6 +1,6 @@
// Test using some simple supported string escapes \r \f \n \' \" // Test using some simple supported string escapes \r \f \n \' \"
char[] MESSAGE = "\r\f\n\"\'"; char[] MESSAGE = "\r\f\n\"\'\\";
char* SCREEN = 0x0400; char* SCREEN = 0x0400;
void main() { void main() {

View File

@ -2,7 +2,7 @@
#pragma encoding(petscii_mixed) #pragma encoding(petscii_mixed)
char[] MESSAGE = "hello\nworld"; char[] MESSAGE = "hello\nworld\\";
const char* memA = 0xff; const char* memA = 0xff;

View File

@ -16,5 +16,5 @@ main: {
iny iny
jmp b1 jmp b1
} }
MESSAGE: .text @"\r\f\n\"'" MESSAGE: .text @"\r\f\n\"'\\"
.byte 0 .byte 0

View File

@ -35,7 +35,7 @@ main::@return: scope:[main] from main::@1
SYMBOL TABLE SSA SYMBOL TABLE SSA
(const string) $0 = (string) " (const string) $0 = (string) "
"'" "'\"
(label) @1 (label) @1
(label) @2 (label) @2
(label) @begin (label) @begin
@ -198,7 +198,7 @@ main: {
jmp b1 jmp b1
} }
// File Data // File Data
MESSAGE: .text @"\r\f\n\"'" MESSAGE: .text @"\r\f\n\"'\\"
.byte 0 .byte 0
REGISTER UPLIFT POTENTIAL REGISTERS REGISTER UPLIFT POTENTIAL REGISTERS
@ -272,7 +272,7 @@ main: {
jmp b1 jmp b1
} }
// File Data // File Data
MESSAGE: .text @"\r\f\n\"'" MESSAGE: .text @"\r\f\n\"'\\"
.byte 0 .byte 0
ASSEMBLER OPTIMIZATIONS ASSEMBLER OPTIMIZATIONS
@ -303,7 +303,7 @@ FINAL SYMBOL TABLE
(label) @end (label) @end
(byte[]) MESSAGE (byte[]) MESSAGE
(const byte[]) MESSAGE#0 MESSAGE = (string) " (const byte[]) MESSAGE#0 MESSAGE = (string) "
"'" "'\"
(byte*) SCREEN (byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024 (const byte*) SCREEN#0 SCREEN = (byte*) 1024
(void()) main() (void()) main()
@ -365,6 +365,6 @@ main: {
jmp b1 jmp b1
} }
// File Data // File Data
MESSAGE: .text @"\r\f\n\"'" MESSAGE: .text @"\r\f\n\"'\\"
.byte 0 .byte 0

View File

@ -3,7 +3,7 @@
(label) @end (label) @end
(byte[]) MESSAGE (byte[]) MESSAGE
(const byte[]) MESSAGE#0 MESSAGE = (string) " (const byte[]) MESSAGE#0 MESSAGE = (string) "
"'" "'\"
(byte*) SCREEN (byte*) SCREEN
(const byte*) SCREEN#0 SCREEN = (byte*) 1024 (const byte*) SCREEN#0 SCREEN = (byte*) 1024
(void()) main() (void()) main()

View File

@ -27,5 +27,5 @@ chrout: {
rts rts
} }
.encoding "petscii_mixed" .encoding "petscii_mixed"
MESSAGE: .text @"hello\nworld" MESSAGE: .text @"hello\nworld\\"
.byte 0 .byte 0

View File

@ -47,7 +47,7 @@ chrout::@return: scope:[chrout] from chrout
SYMBOL TABLE SSA SYMBOL TABLE SSA
(const string) $0 = (string) "hello (const string) $0 = (string) "hello
world"pm world\"pm
(label) @2 (label) @2
(label) @3 (label) @3
(label) @begin (label) @begin
@ -260,7 +260,7 @@ chrout: {
} }
// File Data // File Data
.encoding "petscii_mixed" .encoding "petscii_mixed"
MESSAGE: .text @"hello\nworld" MESSAGE: .text @"hello\nworld\\"
.byte 0 .byte 0
REGISTER UPLIFT POTENTIAL REGISTERS REGISTER UPLIFT POTENTIAL REGISTERS
@ -365,7 +365,7 @@ chrout: {
} }
// File Data // File Data
.encoding "petscii_mixed" .encoding "petscii_mixed"
MESSAGE: .text @"hello\nworld" MESSAGE: .text @"hello\nworld\\"
.byte 0 .byte 0
ASSEMBLER OPTIMIZATIONS ASSEMBLER OPTIMIZATIONS
@ -402,7 +402,7 @@ FINAL SYMBOL TABLE
(label) @end (label) @end
(byte[]) MESSAGE (byte[]) MESSAGE
(const byte[]) MESSAGE#0 MESSAGE = (string) "hello (const byte[]) MESSAGE#0 MESSAGE = (string) "hello
world"pm world\"pm
(void()) chrout((byte) chrout::c) (void()) chrout((byte) chrout::c)
(label) chrout::@return (label) chrout::@return
(byte) chrout::c (byte) chrout::c
@ -491,6 +491,6 @@ chrout: {
} }
// File Data // File Data
.encoding "petscii_mixed" .encoding "petscii_mixed"
MESSAGE: .text @"hello\nworld" MESSAGE: .text @"hello\nworld\\"
.byte 0 .byte 0

View File

@ -3,7 +3,7 @@
(label) @end (label) @end
(byte[]) MESSAGE (byte[]) MESSAGE
(const byte[]) MESSAGE#0 MESSAGE = (string) "hello (const byte[]) MESSAGE#0 MESSAGE = (string) "hello
world"pm world\"pm
(void()) chrout((byte) chrout::c) (void()) chrout((byte) chrout::c)
(label) chrout::@return (label) chrout::@return
(byte) chrout::c (byte) chrout::c