Skip to content

Commit b5d1e86

Browse files
committed
tiny cleanups
1 parent f6d4c90 commit b5d1e86

File tree

11 files changed

+57
-47
lines changed

11 files changed

+57
-47
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/res/prog8lib/prog8lib.asm

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ _l3 ldy c64.SCRATCH_ZPB1 ;where the largest value shall be put
14171417
rts
14181418
.pend
14191419

1420-
1420+
14211421
sort_b .proc
14221422
; 8bit signed sort
14231423
; sorting subroutine coded by mats rosengren ([email protected])
@@ -1471,7 +1471,7 @@ _sort_loop ldy c64.SCRATCH_ZPB1 ;start of subroutine sort
14711471
sta _work3+1
14721472
dey
14731473
jmp _l2
1474-
_l1 dey
1474+
_l1 dey
14751475
dey
14761476
beq _l3
14771477
iny
@@ -1506,12 +1506,12 @@ _l3 ldy c64.SCRATCH_ZPB1 ;where the largest value shall be put
15061506
dec c64.SCRATCH_ZPB1 ;end of the shorter sequence still left
15071507
dec c64.SCRATCH_ZPB1
15081508
bne _sort_loop ;start working with the shorter sequence
1509-
rts
1509+
rts
15101510
_work1 .byte 0
15111511
_work3 .word 0
15121512
.pend
15131513

1514-
1514+
15151515
sort_w .proc
15161516
; 16bit signed sort
15171517
; sorting subroutine coded by mats rosengren ([email protected])
@@ -1532,7 +1532,7 @@ _sort_loop ldy c64.SCRATCH_ZPB1 ;start of subroutine sort
15321532
sta _work3+1
15331533
dey
15341534
jmp _l2
1535-
_l1 dey
1535+
_l1 dey
15361536
dey
15371537
beq _l3
15381538
lda (c64.SCRATCH_ZPWORD1),y
@@ -1543,7 +1543,7 @@ _l1 dey
15431543
sbc c64.SCRATCH_ZPWORD2+1
15441544
bvc +
15451545
eor #$80
1546-
+ bmi _l1
1546+
+ bmi _l1
15471547
_l2 sty _work1 ;index of potentially largest value
15481548
lda (c64.SCRATCH_ZPWORD1),y
15491549
sta c64.SCRATCH_ZPWORD2 ;potentially largest value
@@ -1568,12 +1568,12 @@ _l3 ldy c64.SCRATCH_ZPB1 ;where the largest value shall be put
15681568
dec c64.SCRATCH_ZPB1 ;end of the shorter sequence still left
15691569
dec c64.SCRATCH_ZPB1
15701570
bne _sort_loop ;start working with the shorter sequence
1571-
rts
1571+
rts
15721572
_work1 .byte 0
15731573
_work3 .word 0
1574-
.pend
1575-
1576-
1574+
.pend
1575+
1576+
15771577
reverse_b .proc
15781578
; --- reverse an array of bytes (in-place)
15791579
; inputs: pointer to array in c64.SCRATCH_ZPWORD1, length in A
@@ -1607,7 +1607,7 @@ _loop sty c64.SCRATCH_ZPREG
16071607
rts
16081608
.pend
16091609

1610-
1610+
16111611
reverse_w .proc
16121612
; --- reverse an array of words (in-place)
16131613
; inputs: pointer to array in c64.SCRATCH_ZPWORD1, length in A
@@ -1669,7 +1669,7 @@ _loop_hi sty c64.SCRATCH_ZPREG
16691669
dey
16701670
bne _loop_hi
16711671

1672-
rts
1672+
rts
16731673
.pend
16741674

16751675
ror2_mem_ub .proc
@@ -1687,7 +1687,7 @@ ror2_mem_ub .proc
16871687
+ sta (c64.SCRATCH_ZPWORD1),y
16881688
rts
16891689
.pend
1690-
1690+
16911691
rol2_mem_ub .proc
16921692
; -- in-place 8-bit rol of byte at memory location on stack
16931693
;" lda ${number.toHex()} | cmp #\$80 | rol a | sta ${number.toHex()}"
@@ -1703,59 +1703,59 @@ rol2_mem_ub .proc
17031703
sta (c64.SCRATCH_ZPWORD1),y
17041704
rts
17051705
.pend
1706-
1706+
17071707
lsl_array_b .proc
17081708
.warn "lsl_array_b" ; TODO
17091709
.pend
1710-
1710+
17111711
lsl_array_w .proc
17121712
.warn "lsl_array_w" ; TODO
17131713
.pend
1714-
1714+
17151715
lsr_array_ub .proc
17161716
.warn "lsr_array_ub" ; TODO
17171717
.pend
1718-
1718+
17191719
lsr_array_b .proc
17201720
.warn "lsr_array_b" ; TODO
17211721
.pend
1722-
1722+
17231723
lsr_array_uw .proc
1724-
.warn "lsl_array_uw" ; TODO
1724+
.warn "lsr_array_uw" ; TODO
17251725
.pend
1726-
1726+
17271727
lsr_array_w .proc
17281728
.warn "lsr_array_w" ; TODO
17291729
.pend
1730-
1730+
17311731
rol_array_ub .proc
17321732
.warn "rol_array_ub" ; TODO
17331733
.pend
1734-
1734+
17351735
rol_array_uw .proc
17361736
.warn "rol_array_uw" ; TODO
17371737
.pend
1738-
1738+
17391739
rol2_array_ub .proc
17401740
.warn "rol2_array_ub" ; TODO
17411741
.pend
1742-
1742+
17431743
rol2_array_uw .proc
17441744
.warn "rol2_array_uw" ; TODO
17451745
.pend
1746-
1746+
17471747
ror_array_ub .proc
17481748
.warn "ror_array_ub" ; TODO
17491749
.pend
1750-
1750+
17511751
ror_array_uw .proc
17521752
.warn "ror_array_uw" ; TODO
17531753
.pend
1754-
1754+
17551755
ror2_array_ub .proc
17561756
.warn "ror2_array_ub" ; TODO
17571757
.pend
1758-
1758+
17591759
ror2_array_uw .proc
17601760
.warn "ror2_array_uw" ; TODO
17611761
.pend

compiler/src/prog8/ast/AstToplevel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class Program(val name: String, val modules: MutableList<Module>) {
176176
var actualLoadAddress: Int = 0
177177

178178
fun entrypoint(): Subroutine? {
179-
val mainBlocks = modules.flatMap { it.statements }.filter { b -> b is Block && b.name=="main" }.map { it as Block }
179+
val mainBlocks = allBlocks().filter { it.name=="main" }
180180
if(mainBlocks.size > 1)
181181
throw FatalAstException("more than one 'main' block")
182182
return if(mainBlocks.isEmpty()) {

compiler/src/prog8/compiler/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fun compileProgram(filepath: Path,
103103
// asm generation directly from the Ast, no need for intermediate code
104104
val zeropage = MachineDefinition.C64Zeropage(compilerOptions)
105105
programAst.anonscopeVarsCleanup()
106-
val assembly = AsmGen(programAst, compilerOptions, zeropage, outputDir).compileToAssembly(optimize)
106+
val assembly = AsmGen(programAst, zeropage, compilerOptions, outputDir).compileToAssembly(optimize)
107107
assembly.assemble(compilerOptions)
108108
programName = assembly.name
109109
}

compiler/src/prog8/compiler/target/c64/AssemblyProgram.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import prog8.compiler.OutputType
55
import java.nio.file.Path
66
import kotlin.system.exitProcess
77

8-
class AssemblyProgram(val name: String, val outputDir: Path) {
8+
class AssemblyProgram(val name: String, outputDir: Path) {
99
private val assemblyFile = outputDir.resolve("$name.asm")
1010
private val prgFile = outputDir.resolve("$name.prg")
1111
private val binFile = outputDir.resolve("$name.bin")

compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import kotlin.math.absoluteValue
2525
internal class AssemblyError(msg: String) : RuntimeException(msg)
2626

2727

28-
internal class AsmGen(val program: Program,
29-
val options: CompilationOptions,
30-
val zeropage: Zeropage,
31-
val outputDir: Path) {
28+
internal class AsmGen(private val program: Program,
29+
private val zeropage: Zeropage,
30+
private val options: CompilationOptions,
31+
private val outputDir: Path) {
3232

3333
private val assemblyLines = mutableListOf<String>()
3434
private val globalFloatConsts = mutableMapOf<Double, String>() // all float values in the entire program (value -> varname)

compiler/src/prog8/optimizer/SimplifyExpressions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import kotlin.math.log2
1111
import kotlin.math.pow
1212

1313
/*
14-
todo advanced expression optimization: common (sub) expression elimination (turn common expressions into single subroutine call + introduce variable to hold it)
14+
todo add more expression optimizations
1515
1616
Also see https://egorbo.com/peephole-optimizations.html
1717

compiler/src/prog8/optimizer/StatementOptimizer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import kotlin.math.floor
1616

1717

1818
/*
19-
TODO: analyse for unreachable code and remove that (f.i. code after goto or return that has no label so can never be jumped to) + print warning about this
20-
TODO: proper inlining of small subroutines (correctly renaming/relocating all variables in them and refs to those as well, or restrict to subs without variables?)
19+
TODO: remove unreachable code?
20+
TODO: proper inlining of tiny subroutines (correctly renaming/relocating all variables in them and refs to those as well, or restrict to subs without variables?)
2121
*/
2222

2323

compiler/src/prog8/parser/ModuleParsing.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private fun executeImportDirective(program: Program, import: Directive, source:
121121
if(existing!=null)
122122
return null
123123

124-
val resource = tryGetEmbeddedResource(moduleName+".p8")
124+
val resource = tryGetEmbeddedResource("$moduleName.p8")
125125
val importedModule =
126126
if(resource!=null) {
127127
// load the module from the embedded resource

compiler/src/prog8/vm/astvm/AstVm.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ class AstVm(val program: Program) {
173173
fun memwrite(address: Int, value: Short): Short {
174174
if(address==0xa0 || address==0xa1 || address==0xa2) {
175175
// a write to the jiffy clock, update the clock offset for the irq
176-
val timeHi = if(address==0xa0) value else mem.getUByte_DMA(0xa0)
177-
val timeMid = if(address==0xa1) value else mem.getUByte_DMA(0xa1)
178-
val timeLo = if(address==0xa2) value else mem.getUByte_DMA(0xa2)
176+
val timeHi = if(address==0xa0) value else mem.getUByteDirectly(0xa0)
177+
val timeMid = if(address==0xa1) value else mem.getUByteDirectly(0xa1)
178+
val timeLo = if(address==0xa2) value else mem.getUByteDirectly(0xa2)
179179
val jiffies = (timeHi.toInt() shl 16) + (timeMid.toInt() shl 8) + timeLo
180180
rtcOffset = bootTime - (jiffies*1000/60)
181181
}
@@ -260,9 +260,9 @@ class AstVm(val program: Program) {
260260
rtcOffset = timeStamp
261261
}
262262
// update the C-64 60hz jiffy clock in the ZP addresses:
263-
mem.setUByte_DMA(0x00a0, (jiffies ushr 16).toShort())
264-
mem.setUByte_DMA(0x00a1, (jiffies ushr 8 and 255).toShort())
265-
mem.setUByte_DMA(0x00a2, (jiffies and 255).toShort())
263+
mem.setUByteDirectly(0x00a0, (jiffies ushr 16).toShort())
264+
mem.setUByteDirectly(0x00a1, (jiffies ushr 8 and 255).toShort())
265+
mem.setUByteDirectly(0x00a2, (jiffies and 255).toShort())
266266
}
267267

268268
private val runtimeVariables = RuntimeVariables()

0 commit comments

Comments
 (0)