diff --git a/codeGenVirtual/src/prog8/codegen/virtual/AssemblyProgram.kt b/codeGenVirtual/src/prog8/codegen/virtual/AssemblyProgram.kt index 953c7dd35..7c4449b17 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/AssemblyProgram.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/AssemblyProgram.kt @@ -27,8 +27,10 @@ internal class AssemblyProgram(override val name: String, } out.write("------PROGRAM------\n") - out.write("; global var inits\n") - globalInits.forEach { out.writeLine(it) } + if(!options.dontReinitGlobals) { + out.write("; global var inits\n") + globalInits.forEach { out.writeLine(it) } + } out.write("; actual program code\n") blocks.asSequence().flatMap { it.lines }.forEach { line->out.writeLine(line) } diff --git a/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt b/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt index bc01e28a8..38e0063f3 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt @@ -35,19 +35,16 @@ class CodeGen(internal val program: PtProgram, private val builtinFuncGen = BuiltinFuncGen(this, expressionEval) internal val vmRegisters = VmRegisterPool() - init { - if(options.dontReinitGlobals) - TODO("support no globals re-init in vm") - } - override fun compileToAssembly(): IAssemblyProgram? { val vmprog = AssemblyProgram(program.name, allocations) - // collect global variables initializers - program.allBlocks().forEach { - val code = VmCodeChunk() - it.children.filterIsInstance().forEach { assign -> code += translate(assign) } - vmprog.addGlobalInits(code) + if(!options.dontReinitGlobals) { + // collect global variables initializers + program.allBlocks().forEach { + val code = VmCodeChunk() + it.children.filterIsInstance().forEach { assign -> code += translate(assign) } + vmprog.addGlobalInits(code) + } } for (block in program.allBlocks()) { diff --git a/docs/source/todo.rst b/docs/source/todo.rst index e2ffd2c5f..d0538187e 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,10 +3,10 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- vm: support no globals re-init option -- vm: make registers typed? so that it's immediately obvious what type they represent. Much like regular variables in memory. -- vm: don't store symbol names in instructions to make optimizing the IR easier? but what about jumps to labels. And it's no longer readable by humans. - vm codegen/assembler: variable memory locations should also be referenced by the variable name instead of just the address, to make the output more human-readable +- vm: make registers typed? so that it's immediately obvious what type they represent. Much like regular variables in memory. + so we have a set of byte registers, a set of word registers, and other sets if we introduce other types. +- vm: don't store symbol names in instructions to make optimizing the IR easier? but what about jumps to labels. And it's no longer readable by humans. - vm: how to remove all unused subroutines? (in the assembly codegen, we let 64tass solve this for us) - vm: rather than being able to jump to any 'address' (IPTR), use 'blocks' that have entry and exit points -> even better dead code elimination possible too - when the vm is stable and *if* its language can get promoted to prog8 IL, the variable allocation should be changed. diff --git a/examples/test.p8 b/examples/test.p8 index dfcc5bca3..5fff06771 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,34 +1,16 @@ %import textio -%zeropage basicsafe +%zeropage dontuse + ; NOTE: meant to test to virtual machine output target (use -target vitual) main { - sub func1(ubyte arg1) -> uword { - return arg1 * 3 - } - - sub func2(uword arg1) -> uword { - return arg1+1000 - } - - sub func3(uword arg1) { - txt.print_uw(arg1+2000) - txt.nl() - } + ubyte global = 42 sub start() { - - ubyte source = 99 - - uword result = func2(func1(cos8u(sin8u(source)))) - txt.print_uw(result) ; 1043 - txt.nl() - result = source |> sin8u() |> cos8u() |> func1() |> func2() - txt.print_uw(result) ; 1043 - txt.nl() - source |> sin8u() |> cos8u() |> func1() |> func3() ; 2043 + txt.print_ub(global) + global++ ; a "pixelshader": ; syscall1(8, 0) ; enable lo res creen