mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +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) {
|
||||
val declConstValue = declValue.constValue(program)
|
||||
if(declConstValue==null) {
|
||||
// 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.allowInitializeWithZero = false
|
||||
val target = AssignTarget(IdentifierReference(listOf(decl.name), decl.position), null, null, decl.position)
|
||||
val assign = Assignment(target, declValue, decl.position)
|
||||
return listOf(
|
||||
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.
|
||||
decl.value = null
|
||||
decl.allowInitializeWithZero = false
|
||||
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.InsertFirst(decl, decl.definingSubroutine() as INameScope)
|
||||
)
|
||||
IAstModification.InsertFirst(decl, subroutine)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
return noModifications
|
||||
|
@ -2,6 +2,8 @@
|
||||
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)
|
||||
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)
|
||||
- get rid of all other TODO's in the code ;-)
|
||||
|
@ -8,8 +8,8 @@
|
||||
main {
|
||||
const ubyte database_size = 100
|
||||
|
||||
uword animal_names_buf
|
||||
uword questions_buf
|
||||
uword animal_names_buf = memory("animalnames", 500)
|
||||
uword questions_buf = memory("questions", 2000)
|
||||
uword animal_names_ptr
|
||||
uword questions_ptr
|
||||
|
||||
@ -23,8 +23,6 @@ main {
|
||||
|
||||
sub start() {
|
||||
; initialize the database
|
||||
animal_names_buf = memory("animalnames", 500)
|
||||
questions_buf = memory("questions", 2000)
|
||||
animal_names_ptr = animal_names_buf
|
||||
questions_ptr = questions_buf
|
||||
|
||||
|
@ -1,17 +1,11 @@
|
||||
%import textio
|
||||
%import gfx2
|
||||
%zeropage basicsafe
|
||||
%zeropage dontuse
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
repeat {
|
||||
sys.waitvsync()
|
||||
ubyte joy = lsb(cx16.joystick_get2(0))
|
||||
txt.print_ubbin(joy,1)
|
||||
txt.nl()
|
||||
}
|
||||
uword hash_buckets = memory("buckets", 128*32*2)
|
||||
|
||||
repeat {
|
||||
}
|
||||
sub start() {
|
||||
txt.print_uwhex(hash_buckets,true)
|
||||
txt.print("ok")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user