diff --git a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt index 52b3439d2..0a25af72f 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstPreprocessor.kt @@ -150,10 +150,10 @@ class AstPreprocessor(val program: Program, val errors: IErrorReporter, val comp private fun wrapWithBooleanConversion(expr: Expression): Expression { return if(expr is IFunctionCall && expr.target.nameInSource==listOf("boolean")) expr - else if(expr is BinaryExpression && expr.operator in LogicalOperators+ComparisonOperators-"not") // TODO should work for 'not' too but now causes assembler to generate wrong code - expr - else if(expr is PrefixExpression && expr.operator in LogicalOperators-"not") // TODO should work for 'not' too but now causes assembler to generate wrong code + else if(expr is BinaryExpression && expr.operator in LogicalOperators+ComparisonOperators) expr +// else if(expr is PrefixExpression && expr.operator == "not") // TODO should work for 'not' too but now causes assembler to generate wrong code (even without optimizations) +// expr else FunctionCallExpression(IdentifierReference(listOf("boolean"), expr.position), mutableListOf(expr), expr.position) } diff --git a/docs/source/todo.rst b/docs/source/todo.rst index fcd1af295..a53f4b038 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -6,7 +6,7 @@ For next release - petaxian roller.p8 line 49 (also see test.p8) generates large code compared to 8.2 - code gen for if statements has become inefficient? vm/6502? - if not diskio.iteration_in_progress or not num_bytes + if not a or not b return 0 - code gen for while loops has become inefficient: (until loops probably as well) (maybe solved when if statements code has been fixed) @@ -22,8 +22,8 @@ For next release can do this for instance by replacing and/or/xor with their bitwise versions &, |, ^ - ...or: 6502: fix logical and/or/xor routines to just be bitwise routines. -- not-problem: assembler generates faulty code when in wrapWithBooleanConversion() the "not" exception is removed - so that these are not wrapped - apparently 'not' codegen doesn't directly generate correct code? +- not-problem: assembler generates faulty code when in wrapWithBooleanConversion() the "not" rule is enabled + so that these are not wrapped (even without optimizations) - re-enable unittest "various 'not' operator rewrites even without optimizations on" when not-problem is fixed - compiling logical.p8 to virtual with optimization generates a lot larger code as without optimizations. diff --git a/examples/test.p8 b/examples/test.p8 index 836e28d2f..91e8de0da 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -21,6 +21,10 @@ main { a1++ } + if not a1 or not a2 { + a1++ + } + if a1!=99 and not a2 { a1++ }