From beea6bc7944b759db729f8797359c366ebea13dc Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 3 Jul 2022 14:44:04 +0200 Subject: [PATCH] about bool --- .../codegen/virtual/VmPeepholeOptimizer.kt | 11 +++++----- docs/source/todo.rst | 22 +++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/codeGenVirtual/src/prog8/codegen/virtual/VmPeepholeOptimizer.kt b/codeGenVirtual/src/prog8/codegen/virtual/VmPeepholeOptimizer.kt index 25959b682..5d323b846 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/VmPeepholeOptimizer.kt +++ b/codeGenVirtual/src/prog8/codegen/virtual/VmPeepholeOptimizer.kt @@ -41,12 +41,13 @@ internal class VmPeepholeOptimizer(private val vmprog: AssemblyProgram, private var changed = false indexedInstructions.forEach { (idx, ins) -> - // TODO: detect multiple loads to the same target, only keep first - // TODO: detect multiple stores to the same target, only keep first - // TODO: detect multiple ffrom/fto to the same target, only keep first + // TODO: detect multiple loads to the same target registers, only keep first (if source is not I/O memory) + // TODO: detect multiple stores to the same target, only keep first (if target is not I/O memory) + // TODO: detect multiple float ffrom/fto to the same target, only keep first // TODO: detect multiple sequential rnd with same reg1, only keep one - // TODO: double same xors/nots/negs, remove the pair completely as they cancel out - // TODO: multiple same ands, ors, only keep first + // TODO: detect subsequent same xors/nots/negs, remove the pairs completely as they cancel out + // TODO: detect multiple same ands, ors; only keep first + // ... } return changed } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 32c2503fa..ed04f210d 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,7 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- bool data type? see below +... Need help with @@ -16,6 +16,8 @@ Need help with Future Things and Ideas ^^^^^^^^^^^^^^^^^^^^^^^ Compiler: + +- bool data type? see below - add some more optimizations in vmPeepholeOptimizer - vm Instruction needs to know what the read-registers/memory are, and what the write-register/memory is. this info is needed for more advanced optimizations and later code generation steps. @@ -71,7 +73,7 @@ Expressions: Optimizations: -- various optimizers skip stuff if compTarget.name==VMTarget.NAME. Once (if?) 6502-codegen is no longer done from +- various optimizers skip stuff if compTarget.name==VMTarget.NAME. When 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 - AssignmentAsmGen.assignExpression() -> improve code gen for assigning boolean comparison expressions @@ -87,12 +89,18 @@ because the type of boolean values is UBYTE (so theoretically the value can be a So the idea is to add a true 'bool' type -- add BOOL datatype +- add BOOL datatype to enumeration +- optional (lot of work): + - add BooleanLiteral ast node to hold true and false, of type BOOL + - make 'true' and 'false' parse into BooleanLiterals + - make sure everything works again (all places using NumericLiteral also have to consider BooleanLiteral...) + - idea: let BooleanLiteral subclass from NumericLiteral ? +- add 'bool' type to grammar and parser +- remove builtin function boolean() replace with typecast to BOOL - add ARRAY_OF_BOOL array type -- assignments to it automatically do boolean() conversion -- logical expressions don't wrap operand of this type -- bool & 1 -> bool -- before codegen, bool type is discarded and it's just UBYTE +- logical expressions don't cast operands of BOOL type to BOOL anymore... +- boolvar & 1 -> boolvar +- before codegen, BOOL type is simply discarded and replaced by UBYTE STRUCTS again?