mirror of
https://github.com/irmen/prog8.git
synced 2025-02-03 11:32:41 +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()) {
|
||||
val lit2decl = LiteralsToAutoVars(this, errors)
|
||||
lit2decl.visit(this)
|
||||
if(errors.noErrors())
|
||||
lit2decl.applyModifications()
|
||||
while(errors.noErrors() && lit2decl.applyModifications()>0)
|
||||
lit2decl.visit(this)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,10 +107,22 @@ internal class LiteralsToAutoVars(private val program: Program, private val erro
|
||||
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> {
|
||||
val target = identifier.targetStatement(program)
|
||||
if(target is Alias) {
|
||||
return listOf(IAstModification.ReplaceNode(identifier, target.target.copy(position = identifier.position), parent))
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
// experimental code to be able to alias blocks too:
|
||||
|
@ -741,6 +741,10 @@ main {
|
||||
print2("two")
|
||||
txt.print_ub(width)
|
||||
txt.print_ub(width2)
|
||||
|
||||
; chained aliases
|
||||
alias chained = print2
|
||||
chained("chained")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,61 +1,11 @@
|
||||
%import textio
|
||||
%import string
|
||||
%option no_sysinit
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
str name1 = "alfred"
|
||||
str name2 = "aldrik"
|
||||
str name3 = "aldrik"
|
||||
|
||||
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()
|
||||
alias print = txt.print
|
||||
alias zz=print
|
||||
zz("chained")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user