diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 355f313da..38760660f 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -85,7 +85,7 @@ class AsmGen(internal val program: Program, } internal fun out(str: String, splitlines: Boolean = true) { - val fragment = (if(" | " in str) str.replace("|", "\n") else str).trim('\n') + val fragment = (if(splitlines && " | " in str) str.replace("|", "\n") else str).trim('\n') if (splitlines) { for (line in fragment.splitToSequence('\n')) { val trimmed = if (line.startsWith(' ')) "\t" + line.trim() else line diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt index 5e015b6a7..ce0729530 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/ProgramAndVarsGen.kt @@ -589,7 +589,7 @@ internal class ProgramAndVarsGen( } private fun outputStringvar(varname: String, encoding: Encoding, value: String) { - asmgen.out("$varname\t; $encoding:\"${value.escape().replace("\u0000", "")}\"") + asmgen.out("$varname\t; $encoding:\"${value.escape().replace("\u0000", "")}\"", false) val bytes = compTarget.encodeString(value, encoding).plus(0.toUByte()) val outputBytes = bytes.map { "$" + it.toString(16).padStart(2, '0') } for (chunk in outputBytes.chunked(16)) diff --git a/compiler/test/codegeneration/TestVariables.kt b/compiler/test/codegeneration/TestVariables.kt index d85412c68..8863bcb46 100644 --- a/compiler/test/codegeneration/TestVariables.kt +++ b/compiler/test/codegeneration/TestVariables.kt @@ -50,4 +50,18 @@ class TestVariables: FunSpec({ """ compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null } + + + test("pipe character in string literal") { + val text = """ + main { + sub start() { + str name = "first|second" + str name2 = "first | second" + } + } + """ + compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null + } + }) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index a7c77c161..049a13bbe 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- fix natt's bugs +- fix natt's bug: ubyte - 2 + 10 somehow gets promoted to byte? - optimize pointervar indexing codegen: make them work as subroutine paramers - optimize pointervar indexing codegen: writing (all sorts of things) - pipe operator: (targets other than 'Virtual'): allow non-unary function calls in the pipe that specify the other argument(s) in the calls. Already working for VM target.