mirror of
https://github.com/irmen/prog8.git
synced 2024-10-08 06:59:21 +00:00
fix compiler error when initializing var with memory(...) in block scope instead of subroutine
This commit is contained in:
parent
e680de05ea
commit
e93701f50e
@ -198,15 +198,18 @@ 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) {
|
||||||
// move the vardecl (without value) to the scope of the defining subroutine and put a regular assignment in its place here.
|
val subroutine = decl.definingSubroutine() as? INameScope
|
||||||
decl.value = null
|
if(subroutine!=null) {
|
||||||
decl.allowInitializeWithZero = false
|
// move the vardecl (without value) to the scope of the defining subroutine and put a regular assignment in its place here.
|
||||||
val target = AssignTarget(IdentifierReference(listOf(decl.name), decl.position), null, null, decl.position)
|
decl.value = null
|
||||||
val assign = Assignment(target, declValue, decl.position)
|
decl.allowInitializeWithZero = false
|
||||||
return listOf(
|
val target = AssignTarget(IdentifierReference(listOf(decl.name), decl.position), null, null, decl.position)
|
||||||
|
val assign = Assignment(target, declValue, decl.position)
|
||||||
|
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
|
||||||
|
@ -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 ;-)
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user