From 1e636155922ee8750ae8c01ed4398e2aeb0d0223 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 2 Apr 2022 17:53:24 +0200 Subject: [PATCH] tweaks --- compiler/src/prog8/CompilerMain.kt | 4 ++-- docs/source/todo.rst | 12 +++++------- examples/cx16/datetime.p8 | 10 +++++----- examples/cx16/keyboardhandler.p8 | 11 ++++++----- examples/plasma.p8 | 1 + examples/test.p8 | 9 +-------- virtualmachine/src/prog8/vm/Instructions.kt | 2 +- 7 files changed, 21 insertions(+), 28 deletions(-) diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index 4b5f7376a..820873e11 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -38,11 +38,11 @@ private fun compileMain(args: Array): Boolean { val dontOptimize by cli.option(ArgType.Boolean, fullName = "noopt", description = "don't perform any optimizations") val dontReinitGlobals by cli.option(ArgType.Boolean, fullName = "noreinit", description = "don't create code to reinitialize globals on multiple runs of the program (experimental!)") val optimizeFloatExpressions by cli.option(ArgType.Boolean, fullName = "optfloatx", description = "optimize float expressions (warning: can increase program size)") - val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watches for file changes), greatly increases compilation speed") + val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watch for file changes)") val slowCodegenWarnings by cli.option(ArgType.Boolean, fullName = "slowwarn", description="show debug warnings about slow/problematic assembly code generation") val quietAssembler by cli.option(ArgType.Boolean, fullName = "quietasm", description = "don't print assembler output results") val asmListfile by cli.option(ArgType.Boolean, fullName = "asmlist", description = "make the assembler produce a listing file as well") - val experimentalCodegen by cli.option(ArgType.Boolean, fullName = "expericodegen", description = "use experimental codegen") + val experimentalCodegen by cli.option(ArgType.Boolean, fullName = "expericodegen", description = "use experimental/alternative codegen") val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler (one of '${C64Target.NAME}', '${C128Target.NAME}', '${Cx16Target.NAME}', '${AtariTarget.NAME}', '${VMTarget.NAME}')") .default(C64Target.NAME) val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths, separated with ${File.pathSeparator}, to search in for imported modules").multiple().delimiter(File.pathSeparator) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 829c34c53..c45887d1b 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,11 +5,10 @@ For next release ^^^^^^^^^^^^^^^^ - vm codegen: When - vm codegen: Pipe expression -- vm codegen: validate that PtFunctionCall translation works okay with resultregister, and multiple paramsters in correct order - vm: support no globals re-init option -- vm: how to remove all unused subroutines? (for asm, 64tass used to do this) -- vm: rather than being able to jump to any 'address' (IPTR), use 'blocks' -- vm codegen/assembler: variable memory locations should also be referenced by the variable name instead of just the address +- 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: 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. It's now done before the vm code generation, but the IL should probably not depend on the allocations already performed. So the CodeGen doesn't do VariableAlloc *before* the codegen, but as a last step. @@ -41,7 +40,6 @@ Compiler: - simplifyConditionalExpression() should not split expression if it still results in stack-based evaluation, but how does it know? - simplifyConditionalExpression() sometimes introduces needless assignment to r9 tempvar (scenario sought) - consider adding McCarthy evaluation to shortcircuit and and or expressions. First do ifs by splitting them up? Then do expressions that compute a value? -- use more of Result<> to handle errors/ nulls better? - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as ``p8v_``? Or not worth it (most 3 letter opcodes as variables are nonsensical anyway) then we can get rid of the instruction lists in the machinedefinitions as well? - [problematic due to 64tass:] add a compiler option to not remove unused subroutines. this allows for building library programs. But this won't work with 64tass's .proc ... @@ -73,8 +71,8 @@ Expressions: Optimizations: -- various optimizers should/do skip stuff if compTarget.name==VMTarget.NAME. Once (if?) 6502-codegen is no longer done from - the old CompilerAst, those checks should probably be removed. +- various optimizers skip stuff if compTarget.name==VMTarget.NAME. Once (if?) 6502-codegen is no longer done from + the old CompilerAst, those checks should probably be removed, or be made permanent - VariableAllocator: can we think of a smarter strategy for allocating variables into zeropage, rather than first-come-first-served - translateUnaryFunctioncall() in BuiltinFunctionsAsmGen: should be able to assign parameters to a builtin function directly from register(s), this will make the use of a builtin function in a pipe expression more efficient without using a temporary variable compare ``aa = startvalue(1) |> sin8u() |> cos8u() |> sin8u() |> cos8u()`` diff --git a/examples/cx16/datetime.p8 b/examples/cx16/datetime.p8 index 8a4e40dd1..7a064a11e 100644 --- a/examples/cx16/datetime.p8 +++ b/examples/cx16/datetime.p8 @@ -7,20 +7,20 @@ main { sub start() { - cx16.clock_set_date_time(mkword(8, 2020 - 1900), mkword(19, 27), mkword(0, 16), 0) + cx16.clock_set_date_time(mkword(8, 2022 - 1900), mkword(19, 27), mkword(30, 16), 0) txt.lowercase() repeat { txt.chrout(19) ; HOME txt.print("\n yyyy-mm-dd HH:MM:SS.jj\n\n") void cx16.clock_get_date_time() - txt.chrout(' ') + txt.spc() print_date() - txt.chrout(' ') + txt.spc() print_time() - txt.chrout('\n') - txt.chrout('\n') + txt.nl() + txt.nl() uword jiffies = c64.RDTIM16() txt.print_uw(jiffies) } diff --git a/examples/cx16/keyboardhandler.p8 b/examples/cx16/keyboardhandler.p8 index 20c196d50..fd0516a50 100644 --- a/examples/cx16/keyboardhandler.p8 +++ b/examples/cx16/keyboardhandler.p8 @@ -23,9 +23,9 @@ main { } sub keyboard_scancode_handler(ubyte prefix, ubyte scancode, ubyte updown) { - txt.print_ub(prefix) - txt.spc() - txt.print_ub(scancode) + txt.print_ubhex(prefix, true) + txt.chrout(':') + txt.print_ubhex(scancode, true) txt.spc() if updown txt.chrout('u') @@ -43,11 +43,12 @@ asm_shim: php pha phx - sta scancode stz updown bcc + inc updown -+ jsr keyboard_scancode_handler ++ stx prefix + sta scancode + jsr keyboard_scancode_handler plx pla plp diff --git a/examples/plasma.p8 b/examples/plasma.p8 index dd145d2ca..afcc0f404 100644 --- a/examples/plasma.p8 +++ b/examples/plasma.p8 @@ -20,6 +20,7 @@ main { sub start() { txt.color(1) + txt.clear_screen() txt.print("creating charset...\n") makechar() diff --git a/examples/test.p8 b/examples/test.p8 index 6ce9e7c67..3cb2d3971 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -7,15 +7,8 @@ main { sub start() { - txt.print("keyboard api test\n") - cx16.kbdbuf_put('l') - cx16.kbdbuf_put('o') - cx16.kbdbuf_put('a') - cx16.kbdbuf_put('d') - cx16.kbdbuf_put(13) - - ; the "pixelshader": + ; a "pixelshader": ; syscall1(8, 0) ; enable lo res creen ; ubyte shifter ; diff --git a/virtualmachine/src/prog8/vm/Instructions.kt b/virtualmachine/src/prog8/vm/Instructions.kt index cab3b571c..17ce86025 100644 --- a/virtualmachine/src/prog8/vm/Instructions.kt +++ b/virtualmachine/src/prog8/vm/Instructions.kt @@ -121,7 +121,7 @@ lsl reg1, reg2, reg3 - reg1 = shift reg2 left by reg3 bi ror reg1, reg2, reg3 - reg1 = rotate reg2 right by reg3 bits, not using carry rol reg1, reg2, reg3 - reg1 = rotate reg2 left by reg3 bits, not using carry -TODO also add ror/rol variants using the carry bit? These do map directly on 6502 and 68k instructions. +TODO also add ror/rol variants using the carry bit? These do map directly on 6502 and 68k instructions. But the VM doesn't have carry status bit yet. MISC