don't prefix 3-letter symbols too aggressively (could cause some compilation errors)

This commit is contained in:
Irmen de Jong 2023-06-23 23:36:59 +02:00
parent 04e4e71f2e
commit 8c617515ba
6 changed files with 48 additions and 25 deletions

View File

@ -403,7 +403,7 @@ romsub $ff53 = joystick_scan() clobbers(A, X, Y)
romsub $ff56 = joystick_get(ubyte joynr @A) -> ubyte @A, ubyte @X, ubyte @Y
romsub $ff56 = joystick_get2(ubyte joynr @A) clobbers(Y) -> uword @AX ; alternative to above to not have the hassle to deal with multiple return values
; Audio (bank 10)
; Audio (rom bank 10)
romsub $C04B = psg_init() clobbers(A,X,Y)
romsub $C063 = ym_init() clobbers(A,X,Y) -> bool @Pc ; (re)init YM chip
romsub $C066 = ym_loaddefpatches() clobbers(A,X,Y) -> bool @Pc ; load default YM patches

View File

@ -1,18 +1,26 @@
package prog8.compiler.astprocessing
import prog8.ast.Node
import prog8.ast.Program
import prog8.ast.expressions.IdentifierReference
import prog8.ast.statements.*
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
class AsmInstructionNamesReplacer(
val program: Program,
val blocks: Set<Block>,
val subroutines: Set<Subroutine>,
val variables: Set<VarDecl>,
val labels: Set<Label>): AstWalker() {
override fun after(identifier: IdentifierReference, parent: Node): Iterable<IAstModification> {
if(identifier.nameInSource.size>1) {
val tgt = identifier.targetStatement(program)
if(tgt==null || tgt.definingModule.isLibrary)
return noModifications
}
val newName = identifier.nameInSource.map { ident ->
if(ident.length==3 && !identifier.definingModule.isLibrary) {
val blockTarget = blocks.firstOrNull { it.name==ident }

View File

@ -33,6 +33,7 @@ internal fun Program.processAstBeforeAsmGeneration(compilerOptions: CompilationO
finder.visit(this)
if(finder.foundAny()) {
val replacer = AsmInstructionNamesReplacer(
this,
finder.blocks,
finder.subroutines,
finder.variables,

View File

@ -222,4 +222,27 @@ main {
result2 shouldNotBe null
}
"3 letter names not prefixed too aggressively" {
val text = """
%import math
main {
sub start() {
ubyte lda = getrandom()
lda++
cx16.r0 = (math.rnd() % 20) * ${'$'}0010
lda = math.rnd() % 5
lda++
}
sub getrandom() -> ubyte {
return cx16.r0L
}
}"""
val result = compileText(C64Target(), false, text, writeAssembly = true)
result shouldNotBe null
val result2 = compileText(VMTarget(), false, text, writeAssembly = true)
result2 shouldNotBe null
}
})

View File

@ -1,6 +1,7 @@
TODO
====
- hiram bank 1 usage configurable or maybe even just keep whatever bank is active at program start?
- replace all the string.compare calls in rockrunner with equalites
...
@ -28,16 +29,16 @@ Compiler:
global initialization values are simply a list of LOAD instructions.
Variables replaced include all subroutine parameters! So the only variables that remain as variables are arrays and strings.
- ir: add more optimizations in IRPeepholeOptimizer
- ir: the @split arrays are also split in _lsb/_msb arrays in the IR, and operations take multiple (byte) instructions that may lead to verbose and slow operation and machine code generation down the line.
- ir: the @split arrays are currently also split in _lsb/_msb arrays in the IR, and operations take multiple (byte) instructions that may lead to verbose and slow operation and machine code generation down the line.
- ir: for expressions with array indexes that occur multiple times, can we avoid loading them into new virtualregs everytime and just reuse a single virtualreg as indexer? (simple form of common subexpression elimination)
- PtAst/IR: more complex common subexpression eliminations
- generate WASM to eventually run prog8 on a browser canvas? Use binaryen toolkit or my binaryen kotlin library?
- can we get rid of pieces of asmgen.AssignmentAsmGen by just reusing the AugmentableAssignment ? generated code should not suffer
- [problematic due to using 64tass:] better support for building library programs, where unused .proc shouldn't be deleted from the assembly?
Perhaps replace all uses of .proc/.pend/.endproc by .block/.bend will fix that with a compiler flag?
But all library code written in asm uses .proc already..... (textual search/replace when writing the actual asm?)
Once new codegen is written that is based on the IR, this point is mostly moot anyway as that will have its own dead code removal on the IR level.
- Zig-like try-based error handling where the V flag could indicate error condition? and/or BRK to jump into monitor on failure? (has to set BRK vector for that) But the V flag is also set on certain normal instructions
- generate WASM to eventually run prog8 on a browser canvas? Use binaryen toolkit or my binaryen kotlin library?
Libraries:
@ -46,7 +47,7 @@ Libraries:
- c128 target: make syslib more complete (missing kernal routines)?
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)
- optimize several inner loops in gfx2 even further?
- add modes 3 and perhaps even 2 to gfx2 (lores 16 color and 4 color)?
- actually implement modes 3 and perhaps even 2 to gfx2 (lores 16 color and 4 color)
Expressions:

View File

@ -1,32 +1,22 @@
%import math
%import textio
%zeropage basicsafe
main {
sub start() {
str name = "name"
uword nameptr = &name
cx16.r0L= name=="foo"
cx16.r1L= name!="foo"
cx16.r2L= name<"foo"
cx16.r3L= name>"foo"
cx16.r0L= nameptr=="foo"
cx16.r1L= nameptr!="foo"
cx16.r2L= nameptr<"foo"
cx16.r3L= nameptr>"foo"
void compare(name, "foo")
void compare(name, "name")
void compare(nameptr, "foo")
void compare(nameptr, "name")
ubyte lda = getrandom()
lda++
cx16.r0 = (math.rnd() % 20) * $0010
lda = math.rnd() % 5
lda++
}
sub compare(str s1, str s2) -> ubyte {
if s1==s2
return 42
return 0
sub getrandom() -> ubyte {
%asm {{
lda #42
rts
}}
}
}