mirror of
https://github.com/irmen/prog8.git
synced 2024-10-17 10:24:55 +00:00
clearer
This commit is contained in:
parent
c3c82282ba
commit
92a07b87d2
@ -468,9 +468,9 @@ internal class ProgramAndVarsGen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun nonZpVariables2asm(variables2: List<StStaticVariable>) {
|
private fun nonZpVariables2asm(variables: List<StStaticVariable>) {
|
||||||
asmgen.out("")
|
asmgen.out("")
|
||||||
val (varsNoInit, varsWithInit) = variables2.partition { it.uninitialized }
|
val (varsNoInit, varsWithInit) = variables.partition { it.uninitialized }
|
||||||
if(varsNoInit.isNotEmpty()) {
|
if(varsNoInit.isNotEmpty()) {
|
||||||
asmgen.out("; non-zeropage variables without initialization value")
|
asmgen.out("; non-zeropage variables without initialization value")
|
||||||
asmgen.out(" .section BSS")
|
asmgen.out(" .section BSS")
|
||||||
|
@ -41,7 +41,6 @@ internal class BeforeAsmAstChanger(val program: Program,
|
|||||||
if(!options.reinitGlobals) {
|
if(!options.reinitGlobals) {
|
||||||
block.statements.asSequence().filterIsInstance<VarDecl>().forEach {
|
block.statements.asSequence().filterIsInstance<VarDecl>().forEach {
|
||||||
if(it.type==VarDeclType.VAR) {
|
if(it.type==VarDeclType.VAR) {
|
||||||
it.zeropage = ZeropageWish.NOT_IN_ZEROPAGE
|
|
||||||
it.findInitializer(program)?.let { initializer ->
|
it.findInitializer(program)?.let { initializer ->
|
||||||
it.value = initializer.value // put the init value back into the vardecl
|
it.value = initializer.value // put the init value back into the vardecl
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
main {
|
main {
|
||||||
|
|
||||||
uword b_wordvar
|
uword b_wordvar
|
||||||
ubyte b_bb =123
|
uword b_initwordvar = 12345 ; TODO FIX THIS INIT VALUE FOR noreinit=true
|
||||||
|
ubyte b_bb =123 ; TODO FIX THIS INIT VALUE FOR noreinit=true
|
||||||
float b_fl
|
float b_fl
|
||||||
ubyte[10] b_emptyarray
|
ubyte[10] b_emptyarray
|
||||||
ubyte[10] b_filledarray = [1,2,3,4,5,6,7,8,9,10]
|
ubyte[10] b_filledarray = [1,2,3,4,5,6,7,8,9,10]
|
||||||
@ -15,6 +16,7 @@ main {
|
|||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
uword wordvar
|
uword wordvar
|
||||||
|
uword initwordvar = 12345
|
||||||
float fl
|
float fl
|
||||||
ubyte bb =123
|
ubyte bb =123
|
||||||
ubyte[10] emptyarray
|
ubyte[10] emptyarray
|
||||||
@ -25,12 +27,14 @@ main {
|
|||||||
uword slab2 = memory("slab2",200, $1000)
|
uword slab2 = memory("slab2",200, $1000)
|
||||||
|
|
||||||
txt.print("**subroutine scope**\n")
|
txt.print("**subroutine scope**\n")
|
||||||
txt.print("uninit wordvar=")
|
txt.print("init wordvar=")
|
||||||
|
txt.print_uw(initwordvar)
|
||||||
|
txt.print("\ninit bb=")
|
||||||
|
txt.print_ub(bb)
|
||||||
|
txt.print("\nuninit wordvar=")
|
||||||
txt.print_uw(wordvar)
|
txt.print_uw(wordvar)
|
||||||
txt.print("\nuninit float=")
|
txt.print("\nuninit float=")
|
||||||
floats.print_f(fl)
|
floats.print_f(fl)
|
||||||
txt.print("\ninit bb=")
|
|
||||||
txt.print_ub(bb)
|
|
||||||
txt.print("\nuninit emptyarray[2]=")
|
txt.print("\nuninit emptyarray[2]=")
|
||||||
txt.print_ub(emptyarray[2])
|
txt.print_ub(emptyarray[2])
|
||||||
txt.print("\nuninit wordarray[2]=")
|
txt.print("\nuninit wordarray[2]=")
|
||||||
@ -41,12 +45,14 @@ main {
|
|||||||
txt.print_ub(filledarray[2])
|
txt.print_ub(filledarray[2])
|
||||||
|
|
||||||
txt.print("\n**block scope**\n")
|
txt.print("\n**block scope**\n")
|
||||||
txt.print("uninit b_wordvar=")
|
txt.print("init wordvar=")
|
||||||
|
txt.print_uw(b_initwordvar)
|
||||||
|
txt.print("\ninit b_bb=")
|
||||||
|
txt.print_ub(b_bb)
|
||||||
|
txt.print("\nuninit b_wordvar=")
|
||||||
txt.print_uw(b_wordvar)
|
txt.print_uw(b_wordvar)
|
||||||
txt.print("\nuninit b_float=")
|
txt.print("\nuninit b_float=")
|
||||||
floats.print_f(b_fl)
|
floats.print_f(b_fl)
|
||||||
txt.print("\ninit b_bb=")
|
|
||||||
txt.print_ub(b_bb)
|
|
||||||
txt.print("\nuninit b_emptyarray[2]=")
|
txt.print("\nuninit b_emptyarray[2]=")
|
||||||
txt.print_ub(b_emptyarray[2])
|
txt.print_ub(b_emptyarray[2])
|
||||||
txt.print("\nuninit b_wordarray[2]=")
|
txt.print("\nuninit b_wordarray[2]=")
|
||||||
|
@ -23,7 +23,7 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
|
|||||||
|
|
||||||
out.write("\n<INITGLOBALS>\n")
|
out.write("\n<INITGLOBALS>\n")
|
||||||
if(irProgram.options.reinitGlobals) {
|
if(irProgram.options.reinitGlobals) {
|
||||||
// note: this a block of code that loads values and stores them into the global variables to reset their values.
|
// this a code that re-loads startup values into all global (block-level) variables.
|
||||||
writeCodeChunk(irProgram.globalInits)
|
writeCodeChunk(irProgram.globalInits)
|
||||||
}
|
}
|
||||||
out.write("</INITGLOBALS>\n")
|
out.write("</INITGLOBALS>\n")
|
||||||
|
@ -89,7 +89,7 @@ object SysCalls {
|
|||||||
|
|
||||||
when(call) {
|
when(call) {
|
||||||
Syscall.RESET -> {
|
Syscall.RESET -> {
|
||||||
vm.reset()
|
vm.reset(false)
|
||||||
}
|
}
|
||||||
Syscall.EXIT ->{
|
Syscall.EXIT ->{
|
||||||
vm.exit(vm.registers.getUB(SyscallRegisterBase).toInt())
|
vm.exit(vm.registers.getUB(SyscallRegisterBase).toInt())
|
||||||
|
@ -37,7 +37,7 @@ class VirtualMachine(irProgram: IRProgram) {
|
|||||||
val callStack = Stack<Pair<IRCodeChunk, Int>>()
|
val callStack = Stack<Pair<IRCodeChunk, Int>>()
|
||||||
val valueStack = Stack<UByte>() // max 128 entries
|
val valueStack = Stack<UByte>() // max 128 entries
|
||||||
var breakpointHandler: ((pcChunk: IRCodeChunk, pcIndex: Int) -> Unit)? = null // can set custom breakpoint handler
|
var breakpointHandler: ((pcChunk: IRCodeChunk, pcIndex: Int) -> Unit)? = null // can set custom breakpoint handler
|
||||||
var pcChunk: IRCodeChunk
|
var pcChunk = IRCodeChunk(null, null)
|
||||||
var pcIndex = 0
|
var pcIndex = 0
|
||||||
var stepCount = 0
|
var stepCount = 0
|
||||||
var statusCarry = false
|
var statusCarry = false
|
||||||
@ -51,7 +51,7 @@ class VirtualMachine(irProgram: IRProgram) {
|
|||||||
program = VmProgramLoader().load(irProgram, memory)
|
program = VmProgramLoader().load(irProgram, memory)
|
||||||
require(irProgram.st.getAsmSymbols().isEmpty()) { "virtual machine can't yet process asmsymbols defined on command line" }
|
require(irProgram.st.getAsmSymbols().isEmpty()) { "virtual machine can't yet process asmsymbols defined on command line" }
|
||||||
cx16virtualregsBaseAddress = (irProgram.st.lookup("cx16.r0") as? StMemVar)?.address?.toInt() ?: 0xff02
|
cx16virtualregsBaseAddress = (irProgram.st.lookup("cx16.r0") as? StMemVar)?.address?.toInt() ?: 0xff02
|
||||||
pcChunk = program.firstOrNull() ?: IRCodeChunk(null, null)
|
reset(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
@ -81,13 +81,17 @@ class VirtualMachine(irProgram: IRProgram) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset(clearMemory: Boolean) {
|
||||||
|
// "reset" the VM without erasing the currently loaded program
|
||||||
|
// this allows you to re-run the program multiple times without having to reload it
|
||||||
registers.reset()
|
registers.reset()
|
||||||
// memory.reset()
|
if(clearMemory)
|
||||||
|
memory.reset()
|
||||||
pcIndex = 0
|
pcIndex = 0
|
||||||
pcChunk = IRCodeChunk(null, null)
|
pcChunk = program.firstOrNull() ?: IRCodeChunk(null, null)
|
||||||
stepCount = 0
|
stepCount = 0
|
||||||
callStack.clear()
|
callStack.clear()
|
||||||
|
valueStack.clear()
|
||||||
statusCarry = false
|
statusCarry = false
|
||||||
statusNegative = false
|
statusNegative = false
|
||||||
statusZero = false
|
statusZero = false
|
||||||
|
Loading…
Reference in New Issue
Block a user