1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2025-08-05 07:28:18 +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 '\"';
case '\'':
return '\'';
case '\\':
return '\\';
default:
throw new CompileError("Illegal char escape sequence \\" + charString.charAt(1));
}
@@ -99,6 +101,8 @@ public class ConstantChar implements ConstantLiteral<Character> {
return "\\f";
case '\'':
return "\\'";
case '\\':
return "\\\\";
default:
return Character.toString(aChar);
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -35,7 +35,7 @@ main::@return: scope:[main] from main::@1
SYMBOL TABLE SSA
(const string) $0 = (string) "
"'\"
(label) @1
(label) @2
@@ -198,7 +198,7 @@ main: {
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
jmp b1
}
// File Data
// File Data
MESSAGE: .text @"\r\f\n\"'\\"
.byte 0
@@ -272,7 +272,7 @@ main: {
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
jmp b1
}
// File Data
// File Data
MESSAGE: .text @"\r\f\n\"'\\"
.byte 0
@@ -303,7 +303,7 @@ FINAL SYMBOL TABLE
(label) @begin
(label) @end
(byte[]) MESSAGE
(const byte[]) MESSAGE#0 MESSAGE = (string) "
(const byte[]) MESSAGE#0 MESSAGE = (string) "
"'\"
(byte*) SCREEN
@@ -365,6 +365,6 @@ main: {
// [5] phi from main::@2 to main::@1 [phi:main::@2->main::@1]
// [5] phi (byte) main::i#2 = (byte) main::i#1 [phi:main::@2->main::@1#0] -- register_copy
jmp b1
}
}
// File Data
MESSAGE: .text @"\r\f\n\"'\\"

View File

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

View File

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

View File

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

View File

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