mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
vm: support noreinit option
This commit is contained in:
parent
95f16c38a9
commit
5b3ccab7dc
@ -27,8 +27,10 @@ internal class AssemblyProgram(override val name: String,
|
|||||||
}
|
}
|
||||||
out.write("------PROGRAM------\n")
|
out.write("------PROGRAM------\n")
|
||||||
|
|
||||||
|
if(!options.dontReinitGlobals) {
|
||||||
out.write("; global var inits\n")
|
out.write("; global var inits\n")
|
||||||
globalInits.forEach { out.writeLine(it) }
|
globalInits.forEach { out.writeLine(it) }
|
||||||
|
}
|
||||||
|
|
||||||
out.write("; actual program code\n")
|
out.write("; actual program code\n")
|
||||||
blocks.asSequence().flatMap { it.lines }.forEach { line->out.writeLine(line) }
|
blocks.asSequence().flatMap { it.lines }.forEach { line->out.writeLine(line) }
|
||||||
|
@ -35,20 +35,17 @@ class CodeGen(internal val program: PtProgram,
|
|||||||
private val builtinFuncGen = BuiltinFuncGen(this, expressionEval)
|
private val builtinFuncGen = BuiltinFuncGen(this, expressionEval)
|
||||||
internal val vmRegisters = VmRegisterPool()
|
internal val vmRegisters = VmRegisterPool()
|
||||||
|
|
||||||
init {
|
|
||||||
if(options.dontReinitGlobals)
|
|
||||||
TODO("support no globals re-init in vm")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun compileToAssembly(): IAssemblyProgram? {
|
override fun compileToAssembly(): IAssemblyProgram? {
|
||||||
val vmprog = AssemblyProgram(program.name, allocations)
|
val vmprog = AssemblyProgram(program.name, allocations)
|
||||||
|
|
||||||
|
if(!options.dontReinitGlobals) {
|
||||||
// collect global variables initializers
|
// collect global variables initializers
|
||||||
program.allBlocks().forEach {
|
program.allBlocks().forEach {
|
||||||
val code = VmCodeChunk()
|
val code = VmCodeChunk()
|
||||||
it.children.filterIsInstance<PtAssignment>().forEach { assign -> code += translate(assign) }
|
it.children.filterIsInstance<PtAssignment>().forEach { assign -> code += translate(assign) }
|
||||||
vmprog.addGlobalInits(code)
|
vmprog.addGlobalInits(code)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (block in program.allBlocks()) {
|
for (block in program.allBlocks()) {
|
||||||
vmprog.addBlock(translate(block))
|
vmprog.addBlock(translate(block))
|
||||||
|
@ -3,10 +3,10 @@ TODO
|
|||||||
|
|
||||||
For next release
|
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 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: 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
|
- 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.
|
- when the vm is stable and *if* its language can get promoted to prog8 IL, the variable allocation should be changed.
|
||||||
|
@ -1,34 +1,16 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%zeropage basicsafe
|
%zeropage dontuse
|
||||||
|
|
||||||
|
|
||||||
; NOTE: meant to test to virtual machine output target (use -target vitual)
|
; NOTE: meant to test to virtual machine output target (use -target vitual)
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub func1(ubyte arg1) -> uword {
|
ubyte global = 42
|
||||||
return arg1 * 3
|
|
||||||
}
|
|
||||||
|
|
||||||
sub func2(uword arg1) -> uword {
|
|
||||||
return arg1+1000
|
|
||||||
}
|
|
||||||
|
|
||||||
sub func3(uword arg1) {
|
|
||||||
txt.print_uw(arg1+2000)
|
|
||||||
txt.nl()
|
|
||||||
}
|
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
txt.print_ub(global)
|
||||||
ubyte source = 99
|
global++
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
; a "pixelshader":
|
; a "pixelshader":
|
||||||
; syscall1(8, 0) ; enable lo res creen
|
; syscall1(8, 0) ; enable lo res creen
|
||||||
|
Loading…
x
Reference in New Issue
Block a user