mirror of
https://github.com/irmen/prog8.git
synced 2025-03-06 05:29:45 +00:00
cleanups
This commit is contained in:
parent
1a1ab0dac6
commit
86d4a4309f
@ -11,7 +11,7 @@ fun optimizeIntermediateAst(program: PtProgram, options: CompilationOptions, st:
|
||||
return
|
||||
while (errors.noErrors() &&
|
||||
(optimizeBitTest(program, options)
|
||||
+ optimizeAssignTargets(program, st, errors)) > 0
|
||||
+ optimizeAssignTargets(program, st)) > 0
|
||||
) {
|
||||
// keep rolling
|
||||
}
|
||||
@ -27,7 +27,7 @@ private fun walkAst(root: PtNode, act: (node: PtNode, depth: Int) -> Boolean) {
|
||||
}
|
||||
|
||||
|
||||
private fun optimizeAssignTargets(program: PtProgram, st: SymbolTable, errors: IErrorReporter): Int {
|
||||
private fun optimizeAssignTargets(program: PtProgram, st: SymbolTable): Int {
|
||||
var changes = 0
|
||||
walkAst(program) { node: PtNode, depth: Int ->
|
||||
if(node is PtAssignment) {
|
||||
|
@ -2400,12 +2400,10 @@ $shortcutLabel:""")
|
||||
}
|
||||
"&" -> {
|
||||
asmgen.out(" lda $otherName | and $name | sta $name")
|
||||
if(dt.isWord) {
|
||||
if(asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" stz $name+1")
|
||||
else
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
if(asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" stz $name+1")
|
||||
else
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
"|" -> asmgen.out(" lda $otherName | ora $name | sta $name")
|
||||
"^" -> asmgen.out(" lda $otherName | eor $name | sta $name")
|
||||
@ -2822,12 +2820,10 @@ $shortcutLabel:""")
|
||||
"&" -> {
|
||||
asmgen.assignExpressionToRegister(value, RegisterOrPair.A)
|
||||
asmgen.out(" and $name | sta $name")
|
||||
if(dt.isWord) {
|
||||
if(asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" stz $name+1")
|
||||
else
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
if(asmgen.isTargetCpu(CpuType.CPU65c02))
|
||||
asmgen.out(" stz $name+1")
|
||||
else
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
"|" -> {
|
||||
asmgen.assignExpressionToRegister(value, RegisterOrPair.A)
|
||||
@ -2896,11 +2892,7 @@ $shortcutLabel:""")
|
||||
}
|
||||
"<<", ">>" -> {
|
||||
if(value is PtNumber && value.number<=255) {
|
||||
when {
|
||||
dt.isWord -> TODO("shift a word var by ${value.number}")
|
||||
dt.isByte -> TODO("shift a byte var by ${value.number}")
|
||||
else -> throw AssemblyError("weird dt for shift")
|
||||
}
|
||||
TODO("shift a word var by ${value.number}")
|
||||
} else {
|
||||
throw AssemblyError("shift by a word value not supported, max is a byte")
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class TestC64Zeropage: FunSpec({
|
||||
var result = zp.allocate("", DataType.forDt(BaseDataType.FLOAT), null, null, errors)
|
||||
result.expectError { "expect allocation error: in regular zp there aren't 5 sequential bytes free" }
|
||||
|
||||
for (i in 0 until zp.availableBytes()) {
|
||||
(0 until zp.availableBytes()).forEach {
|
||||
val alloc = zp.allocate("", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
||||
alloc.getOrElse { throw it }
|
||||
}
|
||||
@ -196,7 +196,7 @@ class TestC64Zeropage: FunSpec({
|
||||
loc shouldNotBeIn zp.free
|
||||
val num = zp.availableBytes() / 2
|
||||
|
||||
for(i in 0..num-3) {
|
||||
(0..num-3).forEach {
|
||||
zp.allocate("", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
||||
}
|
||||
zp.availableBytes() shouldBe 5
|
||||
@ -205,7 +205,7 @@ class TestC64Zeropage: FunSpec({
|
||||
result = zp.allocate("", DataType.forDt(BaseDataType.UWORD), null, null, errors)
|
||||
result.expectError { "should give allocation error" }
|
||||
|
||||
for(i in 0..4) {
|
||||
(0..4).forEach {
|
||||
zp.allocate("", DataType.forDt(BaseDataType.UBYTE), null, null, errors)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ object InferredTypes {
|
||||
require(!(datatype!=null && (isUnknown || isVoid))) { "invalid combination of args" }
|
||||
}
|
||||
|
||||
val isKnown get() = datatype!=null && !datatype!!.isUndefined
|
||||
val isKnown get() = datatype!=null && !datatype.isUndefined
|
||||
fun getOr(default: DataType) = if(isUnknown || isVoid) default else datatype!!
|
||||
fun getOrUndef() = if(isUnknown || isVoid) DataType.forDt(BaseDataType.UNDEFINED) else datatype!!
|
||||
fun getOrElse(transform: (InferredType) -> DataType): DataType =
|
||||
@ -21,7 +21,7 @@ object InferredTypes {
|
||||
false
|
||||
else if(type==BaseDataType.STR && this.datatype?.base==BaseDataType.STR)
|
||||
true
|
||||
else (this.datatype?.base == type && this.datatype?.sub == null) // strict equality if known
|
||||
else (this.datatype?.base == type && this.datatype.sub == null) // strict equality if known
|
||||
|
||||
companion object {
|
||||
fun unknown() = InferredType(isUnknown = true, isVoid = false, datatype = null)
|
||||
|
@ -100,7 +100,7 @@ class IRSymbolTable {
|
||||
} else {
|
||||
scopedName = try {
|
||||
variable.scopedName
|
||||
} catch (ux: UninitializedPropertyAccessException) {
|
||||
} catch (_: UninitializedPropertyAccessException) {
|
||||
variable.name
|
||||
}
|
||||
varToadd = IRStMemVar(scopedName, variable.dt, variable.address, variable.length)
|
||||
|
@ -56,7 +56,6 @@ class VmProgramLoader {
|
||||
is IRInlineAsmChunk -> throw IRParseException("encountered unconverted inline assembly chunk")
|
||||
is IRInlineBinaryChunk -> throw IRParseException("inline binary data not yet supported in the VM")
|
||||
is IRCodeChunk -> programChunks += chunk
|
||||
else -> throw AssemblyError("weird chunk type")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user