mirror of
https://github.com/irmen/prog8.git
synced 2024-11-19 11:32:17 +00:00
comment corrections
This commit is contained in:
parent
84f75f4156
commit
547b1d3720
@ -219,6 +219,10 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o
|
||||
|
||||
// TODO: somehow figure out if the expr will result in stack-evaluation STILL after being split off,
|
||||
// in that case: do *not* split it off but just keep it as it is (otherwise code size increases)
|
||||
// TODO: do NOT move this to an earler ast transform phase (such as StatementReorderer or StatementOptimizer)
|
||||
// it WILL result in larger code.
|
||||
// TODO: this should be replaced by a general expression-evaluation optimization step.
|
||||
// the actual conditional expression in the statement should be no more than VARIABLE <COMPARISON-OPERATOR> SIMPLE-EXPRESSION
|
||||
|
||||
var leftAssignment: Assignment? = null
|
||||
var leftOperandReplacement: Expression? = null
|
||||
@ -317,6 +321,7 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o
|
||||
throw FatalAstException("0==X should have been swapped to if X==0")
|
||||
|
||||
// TODO simplify the conditional expression, introduce simple assignments if required.
|
||||
// make sure to evaluate it only once, but also right at entry of the while loop
|
||||
// NOTE: sometimes this increases code size because additional stores/loads are generated for the
|
||||
// intermediate variables. We assume these are optimized away from the resulting assembly code later.
|
||||
// NOTE: this is nasty for a while-statement as the condition occurs at the top of the loop
|
||||
@ -408,10 +413,8 @@ internal class BeforeAsmGenerationAstChanger(val program: Program, private val o
|
||||
val modifications = mutableListOf<IAstModification>()
|
||||
val statement = expr.containingStatement
|
||||
val dt = expr.indexer.indexExpr.inferType(program)
|
||||
val register = if(dt istype DataType.UBYTE || dt istype DataType.BYTE ) "retval_interm_ub" else "retval_interm_b"
|
||||
// replace the indexer with just the variable (simply use a cx16 virtual register r9, that we HOPE is not used for other things in the expression...)
|
||||
// assign the indexing expression to the helper variable, but only if that hasn't been done already
|
||||
val target = AssignTarget(IdentifierReference(listOf("prog8_lib", register), expr.indexer.position), null, null, expr.indexer.position)
|
||||
val tempvar = if(dt.isBytes) listOf("prog8_lib","retval_interm_ub") else listOf("prog8_lib","retval_interm_b")
|
||||
val target = AssignTarget(IdentifierReference(tempvar, expr.indexer.position), null, null, expr.indexer.position)
|
||||
val assign = Assignment(target, expr.indexer.indexExpr, expr.indexer.position)
|
||||
modifications.add(IAstModification.InsertBefore(statement, assign, statement.parent as IStatementContainer))
|
||||
modifications.add(IAstModification.ReplaceNode(expr.indexer.indexExpr, target.identifier!!.copy(), expr.indexer))
|
||||
|
@ -41,5 +41,5 @@ More code optimization ideas
|
||||
but the result should not produce larger code ofcourse!
|
||||
- while-expression should now also get the simplifyConditionalExpression() treatment
|
||||
- rewrite expression tree evaluation such that it doesn't use an eval stack but flatten the tree into linear code that uses a fixed number of predetermined value 'variables'
|
||||
- this removes the need for the BinExprSplitter (which is problematic now)
|
||||
- this removes the need for the BinExprSplitter? (which is problematic and very limited now)
|
||||
- introduce byte-index operator to avoid index multiplications in loops over arrays? see github issue #4
|
||||
|
@ -6,16 +6,25 @@ main {
|
||||
sub start() {
|
||||
ubyte @shared bb
|
||||
|
||||
when bb {
|
||||
0,1,2 -> {
|
||||
bb ++
|
||||
}
|
||||
3 -> {
|
||||
bb--
|
||||
}
|
||||
else -> {
|
||||
bb=0
|
||||
}
|
||||
if bb + sin8u(bb) > 100-bb {
|
||||
bb++
|
||||
}
|
||||
|
||||
while bb + sin8u(bb) > 100-bb {
|
||||
bb++
|
||||
}
|
||||
|
||||
do {
|
||||
bb++
|
||||
} until bb + sin8u(bb) > 100-bb
|
||||
|
||||
const ubyte EN_TYPE=2
|
||||
uword eRef = $c000
|
||||
ubyte chance = rnd() % 100
|
||||
|
||||
if eRef[EN_TYPE] and chance < (eRef[EN_TYPE] << 1) {
|
||||
bb++
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user