fix compiler error when initializing var with memory(...) in block scope instead of subroutine

This commit is contained in:
Irmen de Jong 2021-04-17 15:49:41 +02:00
parent e680de05ea
commit e93701f50e
4 changed files with 20 additions and 23 deletions

View File

@ -198,6 +198,8 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport
if(declValue!=null && decl.type== VarDeclType.VAR && decl.datatype in NumericDatatypes) { if(declValue!=null && decl.type== VarDeclType.VAR && decl.datatype in NumericDatatypes) {
val declConstValue = declValue.constValue(program) val declConstValue = declValue.constValue(program)
if(declConstValue==null) { if(declConstValue==null) {
val subroutine = decl.definingSubroutine() as? INameScope
if(subroutine!=null) {
// move the vardecl (without value) to the scope of the defining subroutine and put a regular assignment in its place here. // move the vardecl (without value) to the scope of the defining subroutine and put a regular assignment in its place here.
decl.value = null decl.value = null
decl.allowInitializeWithZero = false decl.allowInitializeWithZero = false
@ -205,10 +207,11 @@ internal class StatementReorderer(val program: Program, val errors: IErrorReport
val assign = Assignment(target, declValue, decl.position) val assign = Assignment(target, declValue, decl.position)
return listOf( return listOf(
IAstModification.ReplaceNode(decl, assign, parent), IAstModification.ReplaceNode(decl, assign, parent),
IAstModification.InsertFirst(decl, decl.definingSubroutine() as INameScope) IAstModification.InsertFirst(decl, subroutine)
) )
} }
} }
}
return noModifications return noModifications
} }

View File

@ -2,6 +2,8 @@
TODO TODO
==== ====
- allow labels in blocks instead of only in subroutines?
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking) - c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)
- get rid of all other TODO's in the code ;-) - get rid of all other TODO's in the code ;-)

View File

@ -8,8 +8,8 @@
main { main {
const ubyte database_size = 100 const ubyte database_size = 100
uword animal_names_buf uword animal_names_buf = memory("animalnames", 500)
uword questions_buf uword questions_buf = memory("questions", 2000)
uword animal_names_ptr uword animal_names_ptr
uword questions_ptr uword questions_ptr
@ -23,8 +23,6 @@ main {
sub start() { sub start() {
; initialize the database ; initialize the database
animal_names_buf = memory("animalnames", 500)
questions_buf = memory("questions", 2000)
animal_names_ptr = animal_names_buf animal_names_ptr = animal_names_buf
questions_ptr = questions_buf questions_ptr = questions_buf

View File

@ -1,17 +1,11 @@
%import textio %import textio
%import gfx2 %zeropage dontuse
%zeropage basicsafe
main { main {
sub start() { uword hash_buckets = memory("buckets", 128*32*2)
repeat {
sys.waitvsync()
ubyte joy = lsb(cx16.joystick_get2(0))
txt.print_ubbin(joy,1)
txt.nl()
}
repeat { sub start() {
} txt.print_uwhex(hash_buckets,true)
txt.print("ok")
} }
} }