diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt
index d43e6aea1..eafd5687e 100644
--- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt
+++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt
@@ -77,7 +77,7 @@ class AsmGen(internal val program: Program,
}
internal fun out(str: String, splitlines: Boolean = true) {
- val fragment = (if(splitlines && " | " in str) str.replace("|", "\n") else str).trim('\n')
+ val fragment = (if(splitlines && " | " in str) str.replace("|", "\n") else str).trim('\r', '\n')
if (splitlines) {
for (line in fragment.splitToSequence('\n')) {
val trimmed = if (line.startsWith(' ')) "\t" + line.trim() else line
@@ -838,7 +838,7 @@ $repeatLabel lda $counterVar
if(stmt.definingModule.source is SourceCode.Generated)
throw AssemblyError("%asminclude inside non-library/non-filesystem module not yet supported")
loadAsmIncludeFile(includedName, stmt.definingModule.source).fold(
- success = { assemblyLines.add(it.trimEnd().trimStart('\n')) },
+ success = { assemblyLines.add(it.trimEnd().trimStart('\r', '\n')) },
failure = { errors.err(it.toString(), stmt.position) }
)
}
@@ -909,7 +909,7 @@ $repeatLabel lda $counterVar
}
private fun translate(asm: InlineAssembly) {
- val assembly = asm.assembly.trimEnd().trimStart('\n')
+ val assembly = asm.assembly.trimEnd().trimStart('\r', '\n')
assemblyLines.add(assembly)
}
diff --git a/docs/source/todo.rst b/docs/source/todo.rst
index 94a2f1f08..428c5ced3 100644
--- a/docs/source/todo.rst
+++ b/docs/source/todo.rst
@@ -56,12 +56,9 @@ Libraries:
Expressions:
-- rethink the whole "isAugmentable" business. Because the way this is determined, should always also be exactly mirrorred in the AugmentableAssignmentAsmGen or you'll get a crash at code gen time.
- note: the new Ast doesn't need this any more so maybe we can get rid of it altogether in the old AST - but it's still used for something in the UnusedCodeRemover.
- can we get rid of pieces of asmgen.AssignmentAsmGen by just reusing the AugmentableAssignment ? generated code should not suffer
-- rewrite expression tree evaluation such that it doesn't use an eval stack but flatten the tree into linear code that uses a fixed number of predetermined value 'variables'?
- "Three address code" was mentioned. https://en.wikipedia.org/wiki/Three-address_code
- these variables have to be unique for each subroutine because they could otherwise be interfered with from irq routines etc.
+- rewrite expression tree evaluation such that it doesn't use an eval stack but flatten the tree into linear code
+ that, for instance, uses a fixed number of predetermined value 'variables'?
The VM IL solves this already (by using unlimited registers) but that still lacks a translation to 6502.
- this removes the need for the BinExprSplitter? (which is problematic and very limited now)
and perhaps the assignment splitting in BeforeAsmAstChanger too
diff --git a/examples/bsieve.p8 b/examples/bsieve.p8
index 93d9db3a8..e21b3378a 100644
--- a/examples/bsieve.p8
+++ b/examples/bsieve.p8
@@ -19,7 +19,8 @@ main {
const uword SIZEPL = 8191
uword @zp flags_ptr = memory("flags", SIZEPL, $100)
- txt.print("calculating...\n")
+ txt.print_ub(ITERS)
+ txt.print(" iterations, calculating...\n")
repeat ITERS {
sys.memset(flags_ptr, SIZEPL, 1)
diff --git a/examples/vm/bsieve.p8 b/examples/vm/bsieve.p8
index ae6653b35..92aa2e49e 100644
--- a/examples/vm/bsieve.p8
+++ b/examples/vm/bsieve.p8
@@ -5,7 +5,6 @@
main {
sub start() {
- const ubyte ITERS = 10
uword count
uword i
uword prime
@@ -15,21 +14,19 @@ main {
txt.print("calculating...\n")
- repeat ITERS {
- sys.memset(flags_ptr, SIZEPL, 1)
- count = 0
- for i in 0 to SIZEPL-1 {
- if @(flags_ptr+i) {
- prime = i + i + 3
- k = i + prime
- while k <= SIZEPL-1 {
- @(flags_ptr + k) = false
- k += prime
- }
- txt.print_uw(prime)
- txt.nl()
- count++
+ sys.memset(flags_ptr, SIZEPL, 1)
+ count = 0
+ for i in 0 to SIZEPL-1 {
+ if @(flags_ptr+i) {
+ prime = i + i + 3
+ k = i + prime
+ while k <= SIZEPL-1 {
+ @(flags_ptr + k) = false
+ k += prime
}
+ txt.print_uw(prime)
+ txt.nl()
+ count++
}
}
diff --git a/intermediate/src/prog8/intermediate/IRFileWriter.kt b/intermediate/src/prog8/intermediate/IRFileWriter.kt
index 65c3b4f7e..40497ccc9 100644
--- a/intermediate/src/prog8/intermediate/IRFileWriter.kt
+++ b/intermediate/src/prog8/intermediate/IRFileWriter.kt
@@ -70,7 +70,7 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
}
out.write("\n")
out.write("\n")
- out.write(it.assembly.trimStart('\n').trimEnd(' ', '\n'))
+ out.write(it.assembly.trimStart('\r', '\n').trimEnd(' ', '\r', '\n'))
out.write("\n\n\n")
}
out.write("\n")
@@ -79,7 +79,7 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
private fun writeInlineAsm(chunk: IRInlineAsmChunk) {
out.write("\n")
- out.write(chunk.assembly.trimStart('\n').trimEnd(' ', '\n'))
+ out.write(chunk.assembly.trimStart('\r', '\n').trimEnd(' ', '\r', '\n'))
out.write("\n\n")
}