mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
some optimizations
This commit is contained in:
parent
39a8b76534
commit
72d58d5856
@ -31,6 +31,7 @@
|
|||||||
float[len(zcoor)] rotatedz
|
float[len(zcoor)] rotatedz
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
set_irqvec()
|
||||||
while true {
|
while true {
|
||||||
if irq.time_changed {
|
if irq.time_changed {
|
||||||
irq.time_changed = 0
|
irq.time_changed = 0
|
||||||
|
@ -420,8 +420,8 @@ interface INameScope {
|
|||||||
namespace.allLabelsAndVariables().forEach {
|
namespace.allLabelsAndVariables().forEach {
|
||||||
println(" ".repeat(4 * (1 + indent)) + "${it.key} -> ${it.value::class.simpleName} at ${it.value.position}")
|
println(" ".repeat(4 * (1 + indent)) + "${it.key} -> ${it.value::class.simpleName} at ${it.value.position}")
|
||||||
}
|
}
|
||||||
namespace.statements.filter { it is INameScope }.forEach {
|
namespace.statements.filterIsInstance<INameScope>().forEach {
|
||||||
printNames(indent+1, it as INameScope)
|
printNames(indent+1, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printNames(0, this)
|
printNames(0, this)
|
||||||
|
@ -61,7 +61,7 @@ class AstChecker(private val namespace: INameScope,
|
|||||||
|
|
||||||
override fun process(module: Module) {
|
override fun process(module: Module) {
|
||||||
super.process(module)
|
super.process(module)
|
||||||
val directives = module.statements.asSequence().filter { it is Directive }.groupBy { (it as Directive).directive }
|
val directives = module.statements.filterIsInstance<Directive>().groupBy { it.directive }
|
||||||
directives.filter { it.value.size > 1 }.forEach{ entry ->
|
directives.filter { it.value.size > 1 }.forEach{ entry ->
|
||||||
when(entry.key) {
|
when(entry.key) {
|
||||||
"%output", "%launcher", "%zeropage", "%address" ->
|
"%output", "%launcher", "%zeropage", "%address" ->
|
||||||
|
@ -28,7 +28,7 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
|||||||
module.statements.remove(mainBlock)
|
module.statements.remove(mainBlock)
|
||||||
module.statements.add(0, mainBlock)
|
module.statements.add(0, mainBlock)
|
||||||
}
|
}
|
||||||
val varDecls = module.statements.filter { it is VarDecl }
|
val varDecls = module.statements.filterIsInstance<VarDecl>()
|
||||||
module.statements.removeAll(varDecls)
|
module.statements.removeAll(varDecls)
|
||||||
module.statements.addAll(0, varDecls)
|
module.statements.addAll(0, varDecls)
|
||||||
val directives = module.statements.filter {it is Directive && it.directive in directivesToMove}
|
val directives = module.statements.filter {it is Directive && it.directive in directivesToMove}
|
||||||
@ -44,7 +44,7 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun process(block: Block): IStatement {
|
override fun process(block: Block): IStatement {
|
||||||
val subroutines = block.statements.asSequence().filter { it is Subroutine }.map { it as Subroutine }.toList()
|
val subroutines = block.statements.filterIsInstance<Subroutine>()
|
||||||
var numSubroutinesAtEnd = 0
|
var numSubroutinesAtEnd = 0
|
||||||
// move all subroutines to the end of the block
|
// move all subroutines to the end of the block
|
||||||
for (subroutine in subroutines) {
|
for (subroutine in subroutines) {
|
||||||
@ -91,7 +91,7 @@ class StatementReorderer(private val namespace: INameScope, private val heap: He
|
|||||||
|
|
||||||
override fun process(subroutine: Subroutine): IStatement {
|
override fun process(subroutine: Subroutine): IStatement {
|
||||||
super.process(subroutine)
|
super.process(subroutine)
|
||||||
val varDecls = subroutine.statements.filter { it is VarDecl }
|
val varDecls = subroutine.statements.filterIsInstance<VarDecl>()
|
||||||
subroutine.statements.removeAll(varDecls)
|
subroutine.statements.removeAll(varDecls)
|
||||||
subroutine.statements.addAll(0, varDecls)
|
subroutine.statements.addAll(0, varDecls)
|
||||||
val directives = subroutine.statements.filter {it is Directive && it.directive in directivesToMove}
|
val directives = subroutine.statements.filter {it is Directive && it.directive in directivesToMove}
|
||||||
|
@ -160,7 +160,7 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processVariables(scope: INameScope) {
|
private fun processVariables(scope: INameScope) {
|
||||||
for(variable in scope.statements.asSequence().filter {it is VarDecl }.map { it as VarDecl })
|
for(variable in scope.statements.filterIsInstance<VarDecl>())
|
||||||
prog.variable(variable.scopedname, variable)
|
prog.variable(variable.scopedname, variable)
|
||||||
for(subscope in scope.subScopes())
|
for(subscope in scope.subScopes())
|
||||||
processVariables(subscope.value)
|
processVariables(subscope.value)
|
||||||
|
@ -94,4 +94,9 @@ class Memory {
|
|||||||
fun clear() {
|
fun clear() {
|
||||||
for(i in 0..65535) mem[i]=0
|
for(i in 0..65535) mem[i]=0
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
fun copy(from: Int, to: Int, numbytes: Int) {
|
||||||
|
for(i in 0 until numbytes)
|
||||||
|
mem[to+i] = mem[from+i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -126,6 +126,7 @@ class StackVm(private var traceOutputFile: String?) {
|
|||||||
var callstack = MyStack<Instruction>()
|
var callstack = MyStack<Instruction>()
|
||||||
private set
|
private set
|
||||||
private var program = listOf<Instruction>()
|
private var program = listOf<Instruction>()
|
||||||
|
private var labels = emptyMap<String, Instruction>()
|
||||||
private var heap = HeapValues()
|
private var heap = HeapValues()
|
||||||
private var traceOutput = if(traceOutputFile!=null) PrintStream(File(traceOutputFile), "utf-8") else null
|
private var traceOutput = if(traceOutputFile!=null) PrintStream(File(traceOutputFile), "utf-8") else null
|
||||||
private var canvas: BitmapScreenPanel? = null
|
private var canvas: BitmapScreenPanel? = null
|
||||||
@ -136,8 +137,10 @@ class StackVm(private var traceOutputFile: String?) {
|
|||||||
var sourceLine: String = ""
|
var sourceLine: String = ""
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
|
||||||
fun load(program: Program, canvas: BitmapScreenPanel?) {
|
fun load(program: Program, canvas: BitmapScreenPanel?) {
|
||||||
this.program = program.program
|
this.program = program.program
|
||||||
|
this.labels = program.labels
|
||||||
this.heap = program.heap
|
this.heap = program.heap
|
||||||
this.canvas = canvas
|
this.canvas = canvas
|
||||||
canvas?.requestFocusInWindow()
|
canvas?.requestFocusInWindow()
|
||||||
@ -158,7 +161,7 @@ class StackVm(private var traceOutputFile: String?) {
|
|||||||
P_irqd = false
|
P_irqd = false
|
||||||
sourceLine = ""
|
sourceLine = ""
|
||||||
currentIns = this.program[0]
|
currentIns = this.program[0]
|
||||||
irqStartInstruction = program.labels["irq.irq"]
|
irqStartInstruction = null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun step(instructionCount: Int = 5000) {
|
fun step(instructionCount: Int = 5000) {
|
||||||
@ -1613,9 +1616,18 @@ class StackVm(private var traceOutputFile: String?) {
|
|||||||
val value = heap.get(iterable.heapId)
|
val value = heap.get(iterable.heapId)
|
||||||
evalstack.push(Value(DataType.UBYTE, if (value.array!!.all { v -> v != 0 }) 1 else 0))
|
evalstack.push(Value(DataType.UBYTE, if (value.array!!.all { v -> v != 0 }) 1 else 0))
|
||||||
}
|
}
|
||||||
Syscall.FUNC_SET_IRQVEC, Syscall.FUNC_SET_IRQVEC_EXCL -> TODO()
|
Syscall.FUNC_SET_IRQVEC, Syscall.FUNC_SET_IRQVEC_EXCL -> {
|
||||||
Syscall.FUNC_RESTORE_IRQVEC -> TODO()
|
irqStartInstruction = labels["irq.irq"]
|
||||||
Syscall.FUNC_MEMCOPY -> TODO()
|
}
|
||||||
|
Syscall.FUNC_RESTORE_IRQVEC -> {
|
||||||
|
irqStartInstruction = null
|
||||||
|
}
|
||||||
|
Syscall.FUNC_MEMCOPY -> {
|
||||||
|
val numbytes = evalstack.pop().integerValue()
|
||||||
|
val to = evalstack.pop().integerValue()
|
||||||
|
val from = evalstack.pop().integerValue()
|
||||||
|
mem.copy(from, to, numbytes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user