fix: again gives proper name redefinition errors in same scope

This commit is contained in:
Irmen de Jong 2022-06-04 19:43:53 +02:00
parent 1e61d84fd1
commit 10bf7f5d07
5 changed files with 80 additions and 55 deletions

View File

@ -512,6 +512,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
} else {
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
if(ptrAndIndex!=null) {
// TODO FIX X REGISTER CORRUPTION
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)
@ -613,6 +614,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
} else {
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
if(ptrAndIndex!=null) {
// TODO FIX X CORRUPTION
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)

View File

@ -54,12 +54,16 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
if(decl.name in compTarget.machine.opcodeNames)
errors.err("can't use a cpu opcode name as a symbol: '${decl.name}'", decl.position)
val existing = decl.parent.definingScope.lookup(listOf(decl.name))
if (existing != null && existing !== decl && existing is VarDecl) {
if(existing.parent!==decl.parent)
nameShadowWarning(decl.name, decl.position, existing)
val existingInSameScope = decl.definingScope.lookup(listOf(decl.name))
if(existingInSameScope!=null && existingInSameScope!==decl)
nameError(decl.name, decl.position, existingInSameScope)
val existingOuter = decl.parent.definingScope.lookup(listOf(decl.name))
if (existingOuter != null && existingOuter !== decl && existingOuter is VarDecl) {
if(existingOuter.parent!==decl.parent)
nameShadowWarning(decl.name, decl.position, existingOuter)
else
nameError(decl.name, decl.position, existing)
nameError(decl.name, decl.position, existingOuter)
}
if(decl.definingBlock.name==decl.name)

View File

@ -6,6 +6,7 @@ import prog8.ast.Program
import prog8.ast.expressions.ArrayIndexedExpression
import prog8.ast.expressions.BinaryExpression
import prog8.ast.expressions.DirectMemoryRead
import prog8.ast.expressions.Expression
import prog8.ast.statements.AssignTarget
import prog8.ast.statements.DirectMemoryWrite
import prog8.ast.statements.VarDecl
@ -36,7 +37,11 @@ internal class AstOnetimeTransforms(private val program: Program, private val op
if(arrayVar!=null && arrayVar.datatype == DataType.UWORD) {
// rewrite pointervar[index] into @(pointervar+index)
val indexer = arrayIndexedExpression.indexer
val add = BinaryExpression(arrayIndexedExpression.arrayvar.copy(), "+", indexer.indexExpr, arrayIndexedExpression.position)
val add: Expression =
if(indexer.indexExpr.constValue(program)?.number==0.0)
arrayIndexedExpression.arrayvar.copy()
else
BinaryExpression(arrayIndexedExpression.arrayvar.copy(), "+", indexer.indexExpr, arrayIndexedExpression.position)
if(parent is AssignTarget) {
// we're part of the target of an assignment, we have to actually change the assign target itself
val memwrite = DirectMemoryWrite(add, arrayIndexedExpression.position)

View File

@ -3,8 +3,10 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- BUG in 6502 codegen: ubyte one = 1 | value = one+one+one+one+one is not 5
- BUG in 6502 codegen: ubyte one = 1 | value = one+one+one+one+one is not 5 if rol(ptr[1]) is inbetween
caused by X register corruption in the ROL and ROR code
- add unit test for name error and name shadowing warning.
- optimize pointervar indexing codegen: writing (all sorts of things)
- pipe operator: (targets other than 'Virtual'): allow non-unary function calls in the pipe that specify the other argument(s) in the calls. Already working for VM target.
- add McCarthy evaluation to shortcircuit and/or expressions. First do ifs by splitting them up? Then do expressions that compute a value?

View File

@ -1,4 +1,5 @@
%import textio
%import test_stack
%zeropage basicsafe
@ -30,65 +31,76 @@ main {
sub start() {
; mcCarthy()
test_stack.test()
ubyte value = 0
ubyte size = 9
ubyte one = 1
ubyte[10] data = [11,22,33,4,5,6,7,8,9,10]
uword bitmapbuf = &data
value = bitmapbuf[2]
txt.print_ub(value) ;; 33
txt.nl()
; 11 22 33
txt.print_ub(bitmapbuf[0])
txt.spc()
txt.print_ub(bitmapbuf[1])
txt.spc()
txt.print_ub(bitmapbuf[2])
txt.nl()
rol(bitmapbuf[0])
rol(bitmapbuf[0])
txt.print_ub(bitmapbuf[0]) ; 44
txt.spc()
ror(bitmapbuf[0])
ror(bitmapbuf[0])
txt.print_ub(bitmapbuf[0]) ; 11
rol(bitmapbuf[1])
ror(bitmapbuf[1])
value = one+one+one
txt.print_ub(value) ; 3
txt.nl()
test_stack.test()
; 22 44 66
txt.print_ub(bitmapbuf[0]*2)
txt.spc()
txt.print_ub(bitmapbuf[1]*2)
txt.spc()
txt.print_ub(bitmapbuf[2]*2)
txt.nl()
ubyte one = 1
value = one+one+one+one+one
txt.print_ub(value) ; 5
txt.nl()
bitmapbuf[0] = one
bitmapbuf[1] = one+one
bitmapbuf[2] = one+one+one
bitmapbuf[2] += 4
bitmapbuf[2] -= 2
bitmapbuf[2] -= 2
swap(bitmapbuf[0], bitmapbuf[1])
; value = bitmapbuf[2]
; txt.print_ub(value) ;; 33
; txt.nl()
;
; ; 11 22 33
; txt.print_ub(bitmapbuf[0])
; txt.spc()
; txt.print_ub(bitmapbuf[1])
; txt.spc()
; txt.print_ub(bitmapbuf[2])
; txt.nl()
; rol(bitmapbuf[0])
; rol(bitmapbuf[0])
; txt.print_ub(bitmapbuf[0]) ; 44
; txt.spc()
; ror(bitmapbuf[0])
; ror(bitmapbuf[0])
; txt.print_ub(bitmapbuf[0]) ; 11
; txt.nl()
;
; ; 22 44 66
; txt.print_ub(bitmapbuf[0]*2)
; txt.spc()
; txt.print_ub(bitmapbuf[1]*2)
; txt.spc()
; txt.print_ub(bitmapbuf[2]*2)
; txt.nl()
; 2 1 3
txt.print_ub(bitmapbuf[0])
txt.spc()
txt.print_ub(bitmapbuf[1])
txt.spc()
txt.print_ub(bitmapbuf[2])
txt.nl()
; value = one+one+one+one+one
; txt.print_ub(value) ; 5
; txt.nl()
for value in data {
txt.print_ub(value)
txt.spc()
}
txt.nl()
; bitmapbuf[0] = one
; bitmapbuf[1] = one+one
; bitmapbuf[2] = one+one+one
; bitmapbuf[2] += 4
; bitmapbuf[2] -= 2
; bitmapbuf[2] -= 2
; swap(bitmapbuf[0], bitmapbuf[1])
;
; ; 2 1 3
; txt.print_ub(bitmapbuf[0])
; txt.spc()
; txt.print_ub(bitmapbuf[1])
; txt.spc()
; txt.print_ub(bitmapbuf[2])
; txt.nl()
;
; for value in data {
; txt.print_ub(value)
; txt.spc()
; }
; txt.nl()
; ; a "pixelshader":