diff --git a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt index 09bfebc13..f351e7c78 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt @@ -218,15 +218,13 @@ class AstPreprocessor(val program: Program, val namesInSub = symbolsInSub.map{ it.first }.toSet() if(subroutine.asmAddress==null) { if(!subroutine.isAsmSubroutine && subroutine.parameters.isNotEmpty()) { - val vars = subroutine.statements.asSequence().filterIsInstance().map { it.name }.toSet() - if(!vars.containsAll(subroutine.parameters.map{it.name})) { - return subroutine.parameters - .filter { it.name !in namesInSub } - .map { - val vardecl = VarDecl.fromParameter(it) - IAstModification.InsertFirst(vardecl, subroutine) - } - } + val existingVars = subroutine.statements.asSequence().filterIsInstance().map { it.name }.toSet() + return subroutine.parameters + .filter { it.name !in namesInSub && it.name !in existingVars } + .map { + val vardecl = VarDecl.fromParameter(it) + IAstModification.InsertFirst(vardecl, subroutine) + } } } diff --git a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt index ecba0fb95..7dc9c5477 100644 --- a/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt +++ b/compilerAst/src/prog8/ast/AstToSourceTextConverter.kt @@ -41,6 +41,10 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: } override fun visit(block: Block) { + if(block.isInLibrary && skipLibraries) { + outputln("; library block skipped: ${block.name}") + return + } val addr = if(block.address!=null) block.address.toHex() else "" outputln("${block.name} $addr {") scopelevel++ @@ -527,4 +531,8 @@ class AstToSourceTextConverter(val output: (text: String) -> Unit, val program: whenChoice.statements.accept(this) outputln("") } + + override fun visit(alias: Alias) { + output("alias ${alias.alias} = ${alias.target.nameInSource.joinToString(".")}") + } } diff --git a/examples/test.p8 b/examples/test.p8 index 8def12622..559b7d347 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -2,35 +2,9 @@ %zeropage basicsafe main { + alias print = txt.print_ub + sub start() { - foo(42) - bar(9999,55) - txt.nl() - test(1,2,3) - test2(1) - } - - sub foo(ubyte arg) { - txt.print_ub(arg) - txt.nl() - } - - sub bar(uword arg, ubyte arg2) { - txt.print_uw(arg) - txt.spc() - txt.print_ub(arg2) - txt.nl() - } - - asmsub test(ubyte a1 @R1, ubyte a2 @R1, ubyte a3 @R2) { ; TODO should give register reuse error - %asm {{ - rts - }} - } - - asmsub test2(uword a1 @AY) clobbers(A, X) -> ubyte @X { - %asm {{ - rts - }} + print(42) } } diff --git a/syntax-files/IDEA/Prog8.xml b/syntax-files/IDEA/Prog8.xml index a9cc8bbb3..4c8689b12 100644 --- a/syntax-files/IDEA/Prog8.xml +++ b/syntax-files/IDEA/Prog8.xml @@ -11,7 +11,7 @@