diff --git a/compiler/src/prog8/ast/expressions/AstExpressions.kt b/compiler/src/prog8/ast/expressions/AstExpressions.kt index d89de6043..857a0447c 100644 --- a/compiler/src/prog8/ast/expressions/AstExpressions.kt +++ b/compiler/src/prog8/ast/expressions/AstExpressions.kt @@ -302,7 +302,7 @@ class NumericLiteralValue(val type: DataType, // only numerical types allowed } } - val asBooleanValue: Boolean = number!=0 + val asBooleanValue: Boolean = number.toDouble() != 0.0 override fun linkParents(parent: Node) { this.parent = parent diff --git a/compiler/src/prog8/optimizer/StatementOptimizer.kt b/compiler/src/prog8/optimizer/StatementOptimizer.kt index 21290ff5d..b1785b831 100644 --- a/compiler/src/prog8/optimizer/StatementOptimizer.kt +++ b/compiler/src/prog8/optimizer/StatementOptimizer.kt @@ -310,19 +310,20 @@ internal class StatementOptimizer(private val program: Program) : IAstModifyingV if(constvalue!=null) { return if(constvalue.asBooleanValue){ // always true -> print a warning, and optimize into body + jump (if there are no continue and break statements) - printWarning("condition is always true", whileLoop.position) // TODO don't warn this if the condition is just the single value 'true' + printWarning("condition is always true", whileLoop.condition.position) if(hasContinueOrBreak(whileLoop.body)) return whileLoop - val label = Label("_prog8_back", whileLoop.condition.position) + val backLabelName = "_prog8_back${whileLoop.position.line}" + val label = Label(backLabelName, whileLoop.condition.position) whileLoop.body.statements.add(0, label) whileLoop.body.statements.add(Jump(null, - IdentifierReference(listOf("_prog8_back"), whileLoop.condition.position), + IdentifierReference(listOf(backLabelName), whileLoop.condition.position), null, whileLoop.condition.position)) optimizationsDone++ return whileLoop.body } else { // always false -> ditch whole statement - printWarning("condition is always false", whileLoop.position) + printWarning("condition is always false", whileLoop.condition.position) optimizationsDone++ NopStatement.insteadOf(whileLoop) } @@ -336,7 +337,7 @@ internal class StatementOptimizer(private val program: Program) : IAstModifyingV if(constvalue!=null) { return if(constvalue.asBooleanValue){ // always true -> keep only the statement block (if there are no continue and break statements) - printWarning("condition is always true", repeatLoop.position) // TODO don't warn this if the condition is just the single value 'true' + printWarning("condition is always true", repeatLoop.untilCondition.position) if(hasContinueOrBreak(repeatLoop.body)) repeatLoop else { @@ -345,13 +346,14 @@ internal class StatementOptimizer(private val program: Program) : IAstModifyingV } } else { // always false -> print a warning, and optimize into body + jump (if there are no continue and break statements) - printWarning("condition is always false", repeatLoop.position) + printWarning("condition is always false", repeatLoop.untilCondition.position) if(hasContinueOrBreak(repeatLoop.body)) return repeatLoop - val label = Label("__back", repeatLoop.untilCondition.position) + val backLabelName = "_prog8_back${repeatLoop.position.line}" + val label = Label(backLabelName, repeatLoop.untilCondition.position) repeatLoop.body.statements.add(0, label) repeatLoop.body.statements.add(Jump(null, - IdentifierReference(listOf("__back"), repeatLoop.untilCondition.position), + IdentifierReference(listOf(backLabelName), repeatLoop.untilCondition.position), null, repeatLoop.untilCondition.position)) optimizationsDone++ return repeatLoop.body diff --git a/docs/docs.iml b/docs/docs.iml index 436bded7a..9918696de 100644 --- a/docs/docs.iml +++ b/docs/docs.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/docs/source/programming.rst b/docs/source/programming.rst index 1424830b0..4668b1027 100644 --- a/docs/source/programming.rst +++ b/docs/source/programming.rst @@ -282,10 +282,10 @@ a string literal a given number of times using '*':: .. caution:: - It's probably best that you don't change strings after they're created. + Avoid changing strings after they've been created. This is because if your program exits and is restarted (without loading it again), - it will then operate on the changed strings instead of the original ones. - The same is true for arrays by the way. + it will then start working with the changed strings instead of the original ones. + The same is true for arrays. Structs diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 5cf48c9c7..b9a98f2de 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,6 +2,11 @@ TODO ==== +- @"zzz" screencode encoded strings + add this to docs too +- add 'void' keyword to explicitly ignore subroutine return values +- allow: for bb in [1,2,3] + docs? + + Memory Block Operations integrated in language? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^