mirror of
https://github.com/irmen/prog8.git
synced 2025-05-12 19:47:48 +00:00
no longer allow subroutine name same as its block name due to asm symbol scoping issues
This commit is contained in:
parent
127c470746
commit
fd2bbd2b59
@ -106,6 +106,12 @@ internal class AstIdentifiersChecker(private val program: Program, private val e
|
||||
if(subroutine.isAsmSubroutine && subroutine.statements.any{it !is InlineAssembly}) {
|
||||
errors.err("asmsub can only contain inline assembly (%asm)", subroutine.position)
|
||||
}
|
||||
|
||||
if(subroutine.name == subroutine.definingBlock().name) {
|
||||
// subroutines cannot have the same name as their enclosing block,
|
||||
// because this causes symbol scoping issues in the resulting assembly source
|
||||
nameError(subroutine.name, subroutine.position, subroutine.definingBlock())
|
||||
}
|
||||
}
|
||||
|
||||
super.visit(subroutine)
|
||||
|
@ -1502,7 +1502,7 @@ $label nop""")
|
||||
val saveA = evalBytevalueWillClobberA(ptrAndIndex.first) || evalBytevalueWillClobberA(ptrAndIndex.second)
|
||||
if(saveA)
|
||||
out(" pha")
|
||||
assignExpressionToVariable(ptrAndIndex.first, asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
assignExpressionToVariable(ptrAndIndex.first, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.Y)
|
||||
if(saveA)
|
||||
out(" pla")
|
||||
@ -1514,7 +1514,7 @@ $label nop""")
|
||||
out(" lda (${asmSymbolName(pointervar)}),y")
|
||||
} else {
|
||||
// copy the pointer var to zp first
|
||||
assignExpressionToVariable(ptrAndIndex.first, asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
assignExpressionToVariable(ptrAndIndex.first, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.Y)
|
||||
out(" lda (P8ZP_SCRATCH_W2),y")
|
||||
}
|
||||
|
@ -1696,7 +1696,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge
|
||||
internal fun translateDirectMemReadExpression(expr: DirectMemoryRead, pushResultOnEstack: Boolean) {
|
||||
|
||||
fun assignViaExprEval() {
|
||||
asmgen.assignExpressionToVariable(expr.addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
asmgen.assignExpressionToVariable(expr.addressExpression, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
if (asmgen.isTargetCpu(CpuType.CPU65c02)) {
|
||||
if (pushResultOnEstack) {
|
||||
asmgen.out(" lda (P8ZP_SCRATCH_W2) | dex | sta P8ESTACK_LO+1,x")
|
||||
|
@ -319,10 +319,9 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
||||
register!!
|
||||
if(requiredDt largerThan valueDt) {
|
||||
// we need to sign extend the source, do this via temporary word variable
|
||||
val scratchVar = asmgen.asmVariableName("P8ZP_SCRATCH_W1")
|
||||
asmgen.assignExpressionToVariable(value, scratchVar, DataType.UBYTE, sub)
|
||||
asmgen.signExtendVariableLsb(scratchVar, valueDt)
|
||||
asmgen.assignVariableToRegister(scratchVar, register)
|
||||
asmgen.assignExpressionToVariable(value, "P8ZP_SCRATCH_W1", DataType.UBYTE, sub)
|
||||
asmgen.signExtendVariableLsb("P8ZP_SCRATCH_W1", valueDt)
|
||||
asmgen.assignVariableToRegister("P8ZP_SCRATCH_W1", register)
|
||||
} else {
|
||||
val target: AsmAssignTarget =
|
||||
if(parameter.value.type in ByteDatatypes && (register==RegisterOrPair.AX || register == RegisterOrPair.AY || register==RegisterOrPair.XY || register in Cx16VirtualRegisters))
|
||||
|
@ -115,7 +115,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
}
|
||||
SourceStorageKind.MEMORY -> {
|
||||
fun assignViaExprEval(expression: Expression) {
|
||||
assignExpressionToVariable(expression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, assign.target.scope)
|
||||
assignExpressionToVariable(expression, "P8ZP_SCRATCH_W2", DataType.UWORD, assign.target.scope)
|
||||
if (asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" lda (P8ZP_SCRATCH_W2)")
|
||||
else
|
||||
@ -320,7 +320,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
if(targetDt in WordDatatypes) {
|
||||
|
||||
fun assignViaExprEval(addressExpression: Expression) {
|
||||
asmgen.assignExpressionToVariable(addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
asmgen.assignExpressionToVariable(addressExpression, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
if (asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" lda (P8ZP_SCRATCH_W2)")
|
||||
else
|
||||
@ -2089,7 +2089,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
fun storeViaExprEval() {
|
||||
when(addressExpr) {
|
||||
is NumericLiteralValue, is IdentifierReference -> {
|
||||
assignExpressionToVariable(addressExpr, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
assignExpressionToVariable(addressExpr, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
if (asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" sta (P8ZP_SCRATCH_W2)")
|
||||
else
|
||||
@ -2098,7 +2098,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
||||
else -> {
|
||||
// same as above but we need to save the A register
|
||||
asmgen.out(" pha")
|
||||
assignExpressionToVariable(addressExpr, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, null)
|
||||
assignExpressionToVariable(addressExpr, "P8ZP_SCRATCH_W2", DataType.UWORD, null)
|
||||
asmgen.out(" pla")
|
||||
if (asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" sta (P8ZP_SCRATCH_W2)")
|
||||
|
@ -1778,7 +1778,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
||||
}
|
||||
else -> {
|
||||
asmgen.assignExpressionToVariable(mem.addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, target.scope)
|
||||
asmgen.assignExpressionToVariable(mem.addressExpression, "P8ZP_SCRATCH_W2", DataType.UWORD, target.scope)
|
||||
asmgen.out("""
|
||||
ldy #0
|
||||
lda (P8ZP_SCRATCH_W2),y
|
||||
@ -1846,7 +1846,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
||||
}
|
||||
else -> {
|
||||
asmgen.assignExpressionToVariable(memory.addressExpression, asmgen.asmVariableName("P8ZP_SCRATCH_W2"), DataType.UWORD, target.scope)
|
||||
asmgen.assignExpressionToVariable(memory.addressExpression, "P8ZP_SCRATCH_W2", DataType.UWORD, target.scope)
|
||||
asmgen.out("""
|
||||
ldy #0
|
||||
lda (P8ZP_SCRATCH_W2),y
|
||||
|
@ -2,8 +2,6 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- fix scope compilation errors for sub with same name as block (kefrenbars example, 'irq')
|
||||
|
||||
- test all examples (including imgviewer, assembler and petaxian) before release of the new version
|
||||
|
||||
- simplify cx16.joystick_get2() once this cx16 rom issue is resolved: https://github.com/commanderx16/x16-rom/issues/203
|
||||
|
@ -23,7 +23,7 @@ main {
|
||||
|
||||
c64.SCROLX &= %11110111 ; 38 column mode
|
||||
|
||||
c64.set_rasterirq(&irq.irq, 200, false) ; enable animation via raster interrupt
|
||||
c64.set_rasterirq(&irq.irqhandler, 200, false) ; enable animation via raster interrupt
|
||||
|
||||
ubyte target_height = 10
|
||||
ubyte active_height = 24
|
||||
@ -130,7 +130,7 @@ spritedata $0f00 {
|
||||
|
||||
irq {
|
||||
ubyte smoothx=0
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
smoothx = (smoothx-1) & 7
|
||||
main.perform_scroll = smoothx==7
|
||||
c64.SCROLX = (c64.SCROLX & %11111000) | smoothx
|
||||
|
@ -7,7 +7,7 @@ main {
|
||||
|
||||
sub start() {
|
||||
txt.print("playing the music from boulderdash,\nmade in 1984 by peter liepa.\n\n")
|
||||
c64.set_rasterirq(&irq.irq, 60, true) ; enable playback via raster irq
|
||||
c64.set_rasterirq(&irq.irqhandler, 60, true) ; enable playback via raster irq
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ irq {
|
||||
ubyte note_index = 0
|
||||
ubyte delay = 0
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
c64.EXTCOL++
|
||||
delay++
|
||||
if delay >= 8 {
|
||||
|
@ -26,7 +26,7 @@ main {
|
||||
cx16.screen_set_mode(128) ; low-res bitmap 256 colors
|
||||
cx16.FB_init()
|
||||
cx16.VERA_DC_VSCALE = 0 ; display trick spoiler.......: stretch display all the way to the bottom
|
||||
cx16.set_rasterirq(&irq.irq, 0)
|
||||
cx16.set_rasterirq(&irq.irqhandler, 0)
|
||||
|
||||
repeat {
|
||||
; don't exit
|
||||
@ -44,7 +44,7 @@ irq {
|
||||
|
||||
ubyte[32] pixels = 0 to 31
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
next_irq_line += 6
|
||||
anim1 += 4
|
||||
anim2 += 6
|
||||
|
@ -31,7 +31,7 @@ main {
|
||||
palette.set_color(0, 0)
|
||||
palette.set_color(16, 0)
|
||||
|
||||
cx16.set_rasterirq(&irq.irq, 0)
|
||||
cx16.set_rasterirq(&irq.irqhandler, 0)
|
||||
|
||||
repeat {
|
||||
; don't exit
|
||||
@ -45,7 +45,7 @@ irq {
|
||||
uword next_rasterline = 0
|
||||
const ubyte increment = 4 ; 4 scanlines = 2 lores pixels per color swap (2 scanlines is too tight)
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
if phase & 1 == 0 {
|
||||
%asm {{
|
||||
lda #0 ; activate palette #0 (first set of colors)
|
||||
|
@ -13,7 +13,7 @@ main {
|
||||
txt.plot(14,14)
|
||||
txt.print("raster bars!")
|
||||
|
||||
cx16.set_rasterirq(&irq.irq, 0)
|
||||
cx16.set_rasterirq(&irq.irqhandler, 0)
|
||||
|
||||
repeat {
|
||||
; don't exit
|
||||
@ -39,7 +39,7 @@ irq {
|
||||
ubyte yanim = 0
|
||||
const ubyte barheight = 4
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
uword c = colors[color_idx]
|
||||
color_idx++
|
||||
color_idx &= 31
|
||||
|
@ -5,7 +5,7 @@ main {
|
||||
|
||||
sub start() {
|
||||
c64.SCROLY &= %11101111 ; blank the screen
|
||||
c64.set_rasterirq(&irq.irq, 40, false) ; register exclusive raster irq handler
|
||||
c64.set_rasterirq(&irq.irqhandler, 40, false) ; register exclusive raster irq handler
|
||||
|
||||
repeat {
|
||||
; enjoy the moving bars :)
|
||||
@ -22,7 +22,7 @@ irq {
|
||||
ubyte color = 0
|
||||
ubyte yanim = 0
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
if color!=len(colors) {
|
||||
c64.EXTCOL = colors[color]
|
||||
c64.RASTER += barheight ; next raster Irq for next color
|
||||
|
@ -46,14 +46,14 @@ main {
|
||||
}
|
||||
|
||||
c64.SPENA = 255 ; enable all sprites
|
||||
c64.set_rasterirq(&irq.irq, 255, true) ; enable animation
|
||||
c64.set_rasterirq(&irq.irqhandler, 255, true) ; enable animation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
irq {
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
c64.EXTCOL--
|
||||
|
||||
; float up & wobble horizontally
|
||||
|
105
examples/test.p8
105
examples/test.p8
@ -2,75 +2,42 @@
|
||||
%zeropage dontuse
|
||||
|
||||
main {
|
||||
|
||||
label:
|
||||
sub start() {
|
||||
irq.irq()
|
||||
|
||||
sub2(&label)
|
||||
sub2(&label_local)
|
||||
sub2(&main.sub2.label_in_sub2)
|
||||
uword xx = &label_local
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
xx = &label
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
xx = &main.label
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
xx = &main.sub2.label_in_sub2
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
xx = main.sub2.sub2var
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
xx = &main.start.label_local
|
||||
txt.print_uwhex(xx, true)
|
||||
txt.nl()
|
||||
|
||||
label_local:
|
||||
return
|
||||
}
|
||||
|
||||
sub sub2(uword ad) {
|
||||
uword sub2var = 42
|
||||
|
||||
txt.print_uwhex(ad,true)
|
||||
txt.nl()
|
||||
label_in_sub2:
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
; TODO FIX SCOPE ERRORS (caused by sub with same name as block)
|
||||
|
||||
irq {
|
||||
ubyte[32] pixels
|
||||
|
||||
sub irq() {
|
||||
ubyte xx
|
||||
; if xx > 4 {
|
||||
; xx++
|
||||
; } else {
|
||||
xx = pixels[2] ; OK
|
||||
calc(pixels[2]) ; FAIL on 'calc'
|
||||
calc2(pixels) ; FAIL on 'pixels' and 'calc2'
|
||||
; }
|
||||
}
|
||||
|
||||
sub calc2(uword adr) {
|
||||
adr++
|
||||
}
|
||||
|
||||
sub calc(ubyte aa) {
|
||||
aa++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
;main {
|
||||
;
|
||||
;label:
|
||||
; sub start() {
|
||||
;
|
||||
; sub2(&label)
|
||||
; sub2(&label_local)
|
||||
; sub2(&main.sub2.label_in_sub2)
|
||||
; uword xx = &label_local
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
; xx = &label
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
; xx = &main.label
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
; xx = &main.sub2.label_in_sub2
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
; xx = main.sub2.sub2var
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
; xx = &main.start.label_local
|
||||
; txt.print_uwhex(xx, true)
|
||||
; txt.nl()
|
||||
;
|
||||
;label_local:
|
||||
; return
|
||||
; }
|
||||
;
|
||||
; sub sub2(uword ad) {
|
||||
; uword sub2var = 42
|
||||
;
|
||||
; txt.print_uwhex(ad,true)
|
||||
; txt.nl()
|
||||
;label_in_sub2:
|
||||
; txt.nl()
|
||||
; }
|
||||
;}
|
||||
|
@ -38,7 +38,7 @@ main {
|
||||
c64.SPRPTR[i] = $0a00/64
|
||||
}
|
||||
c64.SPENA = 255 ; enable all sprites
|
||||
c64.set_rasterirq(&irq.irq, 230, true) ; enable animation
|
||||
c64.set_rasterirq(&irq.irqhandler, 230, true) ; enable animation
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ main {
|
||||
irq {
|
||||
ubyte angle
|
||||
|
||||
sub irq() {
|
||||
sub irqhandler() {
|
||||
angle++
|
||||
c64.MSIGX=0
|
||||
ubyte @zp spri
|
||||
|
Loading…
x
Reference in New Issue
Block a user