tiny cleanups

This commit is contained in:
Irmen de Jong 2019-10-13 07:35:51 +02:00
parent f6d4c90dea
commit b5d1e8653d
11 changed files with 57 additions and 47 deletions

View File

@ -1,6 +1,16 @@
<component name="InspectionProjectProfileManager"> <component name="InspectionProjectProfileManager">
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="100" isEnabled="false" name="JavaScript" />
<language isEnabled="false" name="Groovy" />
<language isEnabled="false" name="Style Sheets" />
<language minSize="70" name="Kotlin" />
<language isEnabled="false" name="TypeScript" />
<language isEnabled="false" name="ActionScript" />
</Languages>
</inspection_tool>
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true"> <inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
<option name="processCode" value="false" /> <option name="processCode" value="false" />
<option name="processLiterals" value="true" /> <option name="processLiterals" value="true" />

View File

@ -1721,7 +1721,7 @@ lsr_array_b .proc
.pend .pend
lsr_array_uw .proc lsr_array_uw .proc
.warn "lsl_array_uw" ; TODO .warn "lsr_array_uw" ; TODO
.pend .pend
lsr_array_w .proc lsr_array_w .proc

View File

@ -176,7 +176,7 @@ class Program(val name: String, val modules: MutableList<Module>) {
var actualLoadAddress: Int = 0 var actualLoadAddress: Int = 0
fun entrypoint(): Subroutine? { fun entrypoint(): Subroutine? {
val mainBlocks = modules.flatMap { it.statements }.filter { b -> b is Block && b.name=="main" }.map { it as Block } val mainBlocks = allBlocks().filter { it.name=="main" }
if(mainBlocks.size > 1) if(mainBlocks.size > 1)
throw FatalAstException("more than one 'main' block") throw FatalAstException("more than one 'main' block")
return if(mainBlocks.isEmpty()) { return if(mainBlocks.isEmpty()) {

View File

@ -103,7 +103,7 @@ fun compileProgram(filepath: Path,
// asm generation directly from the Ast, no need for intermediate code // asm generation directly from the Ast, no need for intermediate code
val zeropage = MachineDefinition.C64Zeropage(compilerOptions) val zeropage = MachineDefinition.C64Zeropage(compilerOptions)
programAst.anonscopeVarsCleanup() programAst.anonscopeVarsCleanup()
val assembly = AsmGen(programAst, compilerOptions, zeropage, outputDir).compileToAssembly(optimize) val assembly = AsmGen(programAst, zeropage, compilerOptions, outputDir).compileToAssembly(optimize)
assembly.assemble(compilerOptions) assembly.assemble(compilerOptions)
programName = assembly.name programName = assembly.name
} }

View File

@ -5,7 +5,7 @@ import prog8.compiler.OutputType
import java.nio.file.Path import java.nio.file.Path
import kotlin.system.exitProcess import kotlin.system.exitProcess
class AssemblyProgram(val name: String, val outputDir: Path) { class AssemblyProgram(val name: String, outputDir: Path) {
private val assemblyFile = outputDir.resolve("$name.asm") private val assemblyFile = outputDir.resolve("$name.asm")
private val prgFile = outputDir.resolve("$name.prg") private val prgFile = outputDir.resolve("$name.prg")
private val binFile = outputDir.resolve("$name.bin") private val binFile = outputDir.resolve("$name.bin")

View File

@ -25,10 +25,10 @@ import kotlin.math.absoluteValue
internal class AssemblyError(msg: String) : RuntimeException(msg) internal class AssemblyError(msg: String) : RuntimeException(msg)
internal class AsmGen(val program: Program, internal class AsmGen(private val program: Program,
val options: CompilationOptions, private val zeropage: Zeropage,
val zeropage: Zeropage, private val options: CompilationOptions,
val outputDir: Path) { private val outputDir: Path) {
private val assemblyLines = mutableListOf<String>() private val assemblyLines = mutableListOf<String>()
private val globalFloatConsts = mutableMapOf<Double, String>() // all float values in the entire program (value -> varname) private val globalFloatConsts = mutableMapOf<Double, String>() // all float values in the entire program (value -> varname)

View File

@ -11,7 +11,7 @@ import kotlin.math.log2
import kotlin.math.pow import kotlin.math.pow
/* /*
todo advanced expression optimization: common (sub) expression elimination (turn common expressions into single subroutine call + introduce variable to hold it) todo add more expression optimizations
Also see https://egorbo.com/peephole-optimizations.html Also see https://egorbo.com/peephole-optimizations.html

View File

@ -16,8 +16,8 @@ import kotlin.math.floor
/* /*
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 TODO: remove unreachable code?
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?) 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?)
*/ */

View File

@ -121,7 +121,7 @@ private fun executeImportDirective(program: Program, import: Directive, source:
if(existing!=null) if(existing!=null)
return null return null
val resource = tryGetEmbeddedResource(moduleName+".p8") val resource = tryGetEmbeddedResource("$moduleName.p8")
val importedModule = val importedModule =
if(resource!=null) { if(resource!=null) {
// load the module from the embedded resource // load the module from the embedded resource

View File

@ -173,9 +173,9 @@ class AstVm(val program: Program) {
fun memwrite(address: Int, value: Short): Short { fun memwrite(address: Int, value: Short): Short {
if(address==0xa0 || address==0xa1 || address==0xa2) { if(address==0xa0 || address==0xa1 || address==0xa2) {
// a write to the jiffy clock, update the clock offset for the irq // a write to the jiffy clock, update the clock offset for the irq
val timeHi = if(address==0xa0) value else mem.getUByte_DMA(0xa0) val timeHi = if(address==0xa0) value else mem.getUByteDirectly(0xa0)
val timeMid = if(address==0xa1) value else mem.getUByte_DMA(0xa1) val timeMid = if(address==0xa1) value else mem.getUByteDirectly(0xa1)
val timeLo = if(address==0xa2) value else mem.getUByte_DMA(0xa2) val timeLo = if(address==0xa2) value else mem.getUByteDirectly(0xa2)
val jiffies = (timeHi.toInt() shl 16) + (timeMid.toInt() shl 8) + timeLo val jiffies = (timeHi.toInt() shl 16) + (timeMid.toInt() shl 8) + timeLo
rtcOffset = bootTime - (jiffies*1000/60) rtcOffset = bootTime - (jiffies*1000/60)
} }
@ -260,9 +260,9 @@ class AstVm(val program: Program) {
rtcOffset = timeStamp rtcOffset = timeStamp
} }
// update the C-64 60hz jiffy clock in the ZP addresses: // update the C-64 60hz jiffy clock in the ZP addresses:
mem.setUByte_DMA(0x00a0, (jiffies ushr 16).toShort()) mem.setUByteDirectly(0x00a0, (jiffies ushr 16).toShort())
mem.setUByte_DMA(0x00a1, (jiffies ushr 8 and 255).toShort()) mem.setUByteDirectly(0x00a1, (jiffies ushr 8 and 255).toShort())
mem.setUByte_DMA(0x00a2, (jiffies and 255).toShort()) mem.setUByteDirectly(0x00a2, (jiffies and 255).toShort())
} }
private val runtimeVariables = RuntimeVariables() private val runtimeVariables = RuntimeVariables()

View File

@ -21,7 +21,7 @@ class Memory(private val readObserver: (address: Int, value: Short) -> Short,
else mem[address] else mem[address]
} }
fun getUByte_DMA(address: Int): Short { fun getUByteDirectly(address: Int): Short {
return mem[address] return mem[address]
} }
@ -39,7 +39,7 @@ class Memory(private val readObserver: (address: Int, value: Short) -> Short,
else value else value
} }
fun setUByte_DMA(address: Int, value: Short) { fun setUByteDirectly(address: Int, value: Short) {
if(value !in 0..255) if(value !in 0..255)
throw VmExecutionException("ubyte value out of range $value") throw VmExecutionException("ubyte value out of range $value")
mem[address] = value mem[address] = value