fix proper initialization of zeropagevars with 'noreinit'

This commit is contained in:
Irmen de Jong 2023-02-20 23:05:27 +01:00
parent 92a07b87d2
commit 0ea70ba656
3 changed files with 18 additions and 16 deletions

View File

@ -201,13 +201,20 @@ internal class ProgramAndVarsGen(
val notInitializers = block.children.filterNot { it in initializers }
notInitializers.forEach { asmgen.translate(it) }
if(options.reinitGlobals) {
// generate subroutine to initialize block-level (global) variables
if (initializers.isNotEmpty()) {
asmgen.out("prog8_init_vars\t.block")
initializers.forEach { assign -> asmgen.translate(assign) }
asmgen.out(" rts\n .bend")
// generate subroutine to initialize block-level (global) variables
if (initializers.isNotEmpty()) {
asmgen.out("prog8_init_vars\t.block")
initializers.forEach { assign ->
if(options.reinitGlobals) {
asmgen.translate(assign)
} else {
// only re-init zeropage vars because non-zeropage vars will have a statically defined value
if(allocator.isZpVar(assign.target.identifier!!.name)) {
asmgen.translate(assign)
}
}
}
asmgen.out(" rts\n .bend")
}
asmgen.out(if(block.forceOutput) "\n\t.bend" else "\n\t.pend")
@ -364,11 +371,9 @@ internal class ProgramAndVarsGen(
private fun entrypointInitialization() {
asmgen.out("; program startup initialization")
asmgen.out(" cld")
if(options.reinitGlobals) {
blockVariableInitializers.forEach {
if (it.value.isNotEmpty())
asmgen.out(" jsr ${it.key.name}.prog8_init_vars")
}
blockVariableInitializers.forEach {
if (it.value.isNotEmpty())
asmgen.out(" jsr ${it.key.name}.prog8_init_vars")
}
// string and array variables in zeropage that have initializer value, should be initialized

View File

@ -138,10 +138,8 @@ One or more .p8 module files
``-noreinit``
Don't create code to reinitialize the global (block level) variables on every run of the program.
Also means that all such variables are no longer placed in the zeropage.
Sometimes the program will be a lot shorter when using this, but sometimes the opposite happens.
When using this option, it may no longer be possible to run the program correctly more than once!
*Experimental feature*: this feature has not been tested much yet.
When using this option, it is often no longer be possible to run the program correctly more than once,
however, the program may be a bit shorter as a result.
``-optfloatx``
Also optimize float expressions if optimizations are enabled.

View File

@ -3,7 +3,6 @@ TODO
For next minor release
^^^^^^^^^^^^^^^^^^^^^^
- cleanup handling of noreinit / fix compilation crash of petaxian with this option enabled
- BSS: initialize BSS block (without slabs!) to zeros on start, using 1 loop instead of all those initialization assignments
- BSS subroutine parameters don't have to be set to 0. But meh, the loop should be super fast anyway.
- option to put BSS in specific upper memory block ($a000-$bfff, $c000-$cfff on C64) add a .cerror check for overflow!