mirror of
https://github.com/irmen/prog8.git
synced 2024-10-25 00:24:16 +00:00
fix: again gives proper name redefinition errors in same scope
This commit is contained in:
parent
1e61d84fd1
commit
10bf7f5d07
@ -512,6 +512,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
|
|||||||
} else {
|
} else {
|
||||||
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
|
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
|
||||||
if(ptrAndIndex!=null) {
|
if(ptrAndIndex!=null) {
|
||||||
|
// TODO FIX X REGISTER CORRUPTION
|
||||||
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
|
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
|
||||||
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
|
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
|
||||||
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)
|
||||||
@ -613,6 +614,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
|
|||||||
} else {
|
} else {
|
||||||
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
|
val ptrAndIndex = asmgen.pointerViaIndexRegisterPossible(what.addressExpression)
|
||||||
if(ptrAndIndex!=null) {
|
if(ptrAndIndex!=null) {
|
||||||
|
// TODO FIX X CORRUPTION
|
||||||
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
|
asmgen.assignExpressionToRegister(ptrAndIndex.second, RegisterOrPair.X)
|
||||||
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
|
asmgen.saveRegisterLocal(CpuRegister.X, (fcall as Node).definingSubroutine!!)
|
||||||
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)
|
asmgen.assignExpressionToRegister(ptrAndIndex.first, RegisterOrPair.AY)
|
||||||
|
@ -54,12 +54,16 @@ internal class AstIdentifiersChecker(private val errors: IErrorReporter,
|
|||||||
if(decl.name in compTarget.machine.opcodeNames)
|
if(decl.name in compTarget.machine.opcodeNames)
|
||||||
errors.err("can't use a cpu opcode name as a symbol: '${decl.name}'", decl.position)
|
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))
|
val existingInSameScope = decl.definingScope.lookup(listOf(decl.name))
|
||||||
if (existing != null && existing !== decl && existing is VarDecl) {
|
if(existingInSameScope!=null && existingInSameScope!==decl)
|
||||||
if(existing.parent!==decl.parent)
|
nameError(decl.name, decl.position, existingInSameScope)
|
||||||
nameShadowWarning(decl.name, decl.position, existing)
|
|
||||||
|
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
|
else
|
||||||
nameError(decl.name, decl.position, existing)
|
nameError(decl.name, decl.position, existingOuter)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(decl.definingBlock.name==decl.name)
|
if(decl.definingBlock.name==decl.name)
|
||||||
|
@ -6,6 +6,7 @@ import prog8.ast.Program
|
|||||||
import prog8.ast.expressions.ArrayIndexedExpression
|
import prog8.ast.expressions.ArrayIndexedExpression
|
||||||
import prog8.ast.expressions.BinaryExpression
|
import prog8.ast.expressions.BinaryExpression
|
||||||
import prog8.ast.expressions.DirectMemoryRead
|
import prog8.ast.expressions.DirectMemoryRead
|
||||||
|
import prog8.ast.expressions.Expression
|
||||||
import prog8.ast.statements.AssignTarget
|
import prog8.ast.statements.AssignTarget
|
||||||
import prog8.ast.statements.DirectMemoryWrite
|
import prog8.ast.statements.DirectMemoryWrite
|
||||||
import prog8.ast.statements.VarDecl
|
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) {
|
if(arrayVar!=null && arrayVar.datatype == DataType.UWORD) {
|
||||||
// rewrite pointervar[index] into @(pointervar+index)
|
// rewrite pointervar[index] into @(pointervar+index)
|
||||||
val indexer = arrayIndexedExpression.indexer
|
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) {
|
if(parent is AssignTarget) {
|
||||||
// we're part of the target of an assignment, we have to actually change the assign target itself
|
// we're part of the target of an assignment, we have to actually change the assign target itself
|
||||||
val memwrite = DirectMemoryWrite(add, arrayIndexedExpression.position)
|
val memwrite = DirectMemoryWrite(add, arrayIndexedExpression.position)
|
||||||
|
@ -3,8 +3,10 @@ TODO
|
|||||||
|
|
||||||
For next release
|
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)
|
- 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.
|
- 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?
|
- add McCarthy evaluation to shortcircuit and/or expressions. First do ifs by splitting them up? Then do expressions that compute a value?
|
||||||
|
108
examples/test.p8
108
examples/test.p8
@ -1,4 +1,5 @@
|
|||||||
%import textio
|
%import textio
|
||||||
|
%import test_stack
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
|
|
||||||
@ -30,65 +31,76 @@ main {
|
|||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
; mcCarthy()
|
; mcCarthy()
|
||||||
|
test_stack.test()
|
||||||
|
|
||||||
|
|
||||||
ubyte value = 0
|
ubyte value = 0
|
||||||
ubyte size = 9
|
ubyte one = 1
|
||||||
ubyte[10] data = [11,22,33,4,5,6,7,8,9,10]
|
ubyte[10] data = [11,22,33,4,5,6,7,8,9,10]
|
||||||
uword bitmapbuf = &data
|
uword bitmapbuf = &data
|
||||||
value = bitmapbuf[2]
|
|
||||||
txt.print_ub(value) ;; 33
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
; 11 22 33
|
rol(bitmapbuf[1])
|
||||||
txt.print_ub(bitmapbuf[0])
|
ror(bitmapbuf[1])
|
||||||
txt.spc()
|
value = one+one+one
|
||||||
txt.print_ub(bitmapbuf[1])
|
txt.print_ub(value) ; 3
|
||||||
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()
|
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
|
; value = bitmapbuf[2]
|
||||||
bitmapbuf[1] = one+one
|
; txt.print_ub(value) ;; 33
|
||||||
bitmapbuf[2] = one+one+one
|
; txt.nl()
|
||||||
bitmapbuf[2] += 4
|
;
|
||||||
bitmapbuf[2] -= 2
|
; ; 11 22 33
|
||||||
bitmapbuf[2] -= 2
|
; txt.print_ub(bitmapbuf[0])
|
||||||
swap(bitmapbuf[0], bitmapbuf[1])
|
; 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
|
; value = one+one+one+one+one
|
||||||
txt.print_ub(bitmapbuf[0])
|
; txt.print_ub(value) ; 5
|
||||||
txt.spc()
|
; txt.nl()
|
||||||
txt.print_ub(bitmapbuf[1])
|
|
||||||
txt.spc()
|
|
||||||
txt.print_ub(bitmapbuf[2])
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
for value in data {
|
; bitmapbuf[0] = one
|
||||||
txt.print_ub(value)
|
; bitmapbuf[1] = one+one
|
||||||
txt.spc()
|
; bitmapbuf[2] = one+one+one
|
||||||
}
|
; bitmapbuf[2] += 4
|
||||||
txt.nl()
|
; 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":
|
; ; a "pixelshader":
|
||||||
|
Loading…
Reference in New Issue
Block a user