fixed while and repeat warning messages line number

fixed invalid while and repeat asm label names
fixed boolean checking of numbers
This commit is contained in:
Irmen de Jong 2020-02-08 19:45:30 +01:00
parent 11de3db25f
commit 885b22df40
5 changed files with 20 additions and 13 deletions

View File

@ -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

View File

@ -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

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (py3)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.8 virtualenv" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -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

View File

@ -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?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^