mirror of
https://github.com/irmen/prog8.git
synced 2026-10-22 05:02:58 +00:00
fix error message for conflicting memory() calls
This commit is contained in:
1 parent
d3fe041e01
commit
ad92f39469
3 files changed
+13
-22
No files matched your search
@@ -26,14 +26,14 @@ internal class CodeDesugarer(val program: Program, private val target: ICompilat
|
||||
// - replace ptr^^ by @(ptr) if ptr is just an uword.
|
||||
// - replace p1^^ = p2^^ by memcopy.
|
||||
|
||||
private val globalReservedSlabs = mutableSetOf<String>()
|
||||
private val globalReservedSlabs = mutableMapOf<String, MemorySlabReservation>()
|
||||
|
||||
override fun before(program: Program): Iterable<AstModification> {
|
||||
globalReservedSlabs.clear()
|
||||
// Pre-collect existing reservations from the entire program to avoid duplicates in multiple passes
|
||||
val collector = object : IAstVisitor {
|
||||
override fun visit(reservation: MemorySlabReservation) {
|
||||
globalReservedSlabs.add(reservation.slabName)
|
||||
globalReservedSlabs[reservation.slabName] = reservation
|
||||
}
|
||||
}
|
||||
program.modules.forEach { module ->
|
||||
@@ -297,9 +297,10 @@ _after:
|
||||
val container = containingStmt.parent as IStatementContainer
|
||||
|
||||
val mods = mutableListOf<AstModification>(AstReplaceNode(functionCallExpr, ref, parent))
|
||||
if (slabName !in globalReservedSlabs) {
|
||||
val existing = globalReservedSlabs[slabName]
|
||||
if (existing == null || existing.size != size || existing.align != align) {
|
||||
mods.add(AstInsert.before(containingStmt, reservation, container))
|
||||
globalReservedSlabs.add(slabName)
|
||||
globalReservedSlabs[slabName] = reservation
|
||||
}
|
||||
return mods
|
||||
}
|
||||
@@ -336,11 +337,12 @@ _after:
|
||||
val align = alignNum.toUInt()
|
||||
|
||||
val container = parent as IStatementContainer
|
||||
return if (slabName in globalReservedSlabs) {
|
||||
val existing = globalReservedSlabs[slabName]
|
||||
return if (existing != null && existing.size == size && existing.align == align) {
|
||||
listOf(AstRemove(functionCallStatement, container))
|
||||
} else {
|
||||
globalReservedSlabs.add(slabName)
|
||||
val reservation = MemorySlabReservation(slabName, size, align, functionCallStatement.position)
|
||||
globalReservedSlabs[slabName] = reservation
|
||||
listOf(AstReplaceNode(functionCallStatement, reservation, parent))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ class Continue(override val position: Position) : Statement() {
|
||||
}
|
||||
|
||||
|
||||
class MemorySlabReservation(
|
||||
data class MemorySlabReservation(
|
||||
val slabName: String,
|
||||
val size: UInt,
|
||||
val align: UInt,
|
||||
|
||||
+4
-15
@@ -3,20 +3,9 @@
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
long @shared v = 1234567890
|
||||
long @shared a = v/77777
|
||||
|
||||
;txt.iso()
|
||||
txt.print_l(a) ; expected: 15873
|
||||
txt.nl()
|
||||
txt.print_l(v/88888) ; expected: 13889
|
||||
txt.nl()
|
||||
txt.print_l(v/-5555) ; expected: -222244
|
||||
txt.nl()
|
||||
v = -999999999
|
||||
txt.print_l(v/-77777) ; expected: 12857
|
||||
txt.nl()
|
||||
|
||||
;sys.poweroff_system()
|
||||
cx16.r0 = memory("buffer", 100, 0)
|
||||
cx16.r1 = memory("buffer", 100, 0)
|
||||
cx16.r2 = memory("buffer", 100, 2)
|
||||
;cx16.r3 = memory("buffer")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user