mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
fix chained aliasing
This commit is contained in:
parent
570b574b93
commit
76b05cb5fd
@ -119,8 +119,8 @@ internal fun Program.checkIdentifiers(errors: IErrorReporter, options: Compilati
|
|||||||
if(errors.noErrors()) {
|
if(errors.noErrors()) {
|
||||||
val lit2decl = LiteralsToAutoVars(this, errors)
|
val lit2decl = LiteralsToAutoVars(this, errors)
|
||||||
lit2decl.visit(this)
|
lit2decl.visit(this)
|
||||||
if(errors.noErrors())
|
while(errors.noErrors() && lit2decl.applyModifications()>0)
|
||||||
lit2decl.applyModifications()
|
lit2decl.visit(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,9 +107,21 @@ internal class LiteralsToAutoVars(private val program: Program, private val erro
|
|||||||
return noModifications
|
return noModifications
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun after(alias: Alias, parent: Node): Iterable<IAstModification> {
|
||||||
|
val target = alias.target.targetStatement(program)
|
||||||
|
if(target is Alias) {
|
||||||
|
val newAlias = Alias(alias.alias, target.target, alias.position)
|
||||||
|
return listOf(IAstModification.ReplaceNode(alias, newAlias, parent))
|
||||||
|
}
|
||||||
|
return noModifications
|
||||||
|
}
|
||||||
|
|
||||||
override fun after(identifier: IdentifierReference, parent: Node): Iterable<IAstModification> {
|
override fun after(identifier: IdentifierReference, parent: Node): Iterable<IAstModification> {
|
||||||
val target = identifier.targetStatement(program)
|
val target = identifier.targetStatement(program)
|
||||||
if(target is Alias) {
|
|
||||||
|
// don't replace an identifier in an Alias or when the alias points to another alias (that will be resolved first elsewhere)
|
||||||
|
if(target is Alias && parent !is Alias) {
|
||||||
|
if(target.target.targetStatement(program) !is Alias)
|
||||||
return listOf(IAstModification.ReplaceNode(identifier, target.target.copy(position = identifier.position), parent))
|
return listOf(IAstModification.ReplaceNode(identifier, target.target.copy(position = identifier.position), parent))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,6 +741,10 @@ main {
|
|||||||
print2("two")
|
print2("two")
|
||||||
txt.print_ub(width)
|
txt.print_ub(width)
|
||||||
txt.print_ub(width2)
|
txt.print_ub(width2)
|
||||||
|
|
||||||
|
; chained aliases
|
||||||
|
alias chained = print2
|
||||||
|
chained("chained")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,61 +1,11 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import string
|
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
str name1 = "alfred"
|
alias print = txt.print
|
||||||
str name2 = "aldrik"
|
alias zz=print
|
||||||
str name3 = "aldrik"
|
zz("chained")
|
||||||
|
|
||||||
uword block1 = memory("block1", 1000, 0)
|
|
||||||
uword block2 = memory("block2", 1000, 0)
|
|
||||||
uword block3 = memory("block3", 1000, 0)
|
|
||||||
|
|
||||||
sys.memset(block1, 1000, 0)
|
|
||||||
sys.memset(block2, 1000, 0)
|
|
||||||
sys.memset(block3, 1000, 0)
|
|
||||||
void string.copy(name1, block1+900)
|
|
||||||
void string.copy(name2, block2+900)
|
|
||||||
void string.copy(name3, block3+900)
|
|
||||||
|
|
||||||
txt.print_b(string.compare(name1, name2))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(string.compare(name2, name3))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(string.compare(name2, name1))
|
|
||||||
txt.nl()
|
|
||||||
txt.print_b(sys.memcmp(name1, name2, len(name1)))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(name2, name3, len(name1)))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(name2, name1, len(name1)))
|
|
||||||
txt.nl()
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
name1[1] = 0
|
|
||||||
name2[1] = 0
|
|
||||||
name3[1] = 0
|
|
||||||
txt.print_b(string.compare(name1, name2))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(string.compare(name2, name3))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(string.compare(name2, name1))
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
txt.print_b(sys.memcmp(name1, name2, len(name1)))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(name2, name3, len(name1)))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(name2, name1, len(name1)))
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
txt.print_b(sys.memcmp(block1, block2, 1000))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(block2, block3, 1000))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_b(sys.memcmp(block2, block1, 1000))
|
|
||||||
txt.nl()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user