mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
function inlining can no longer get into an infinite loop. Fixes #154
This commit is contained in:
parent
ae669af904
commit
a088ee56b0
@ -224,8 +224,11 @@ class Inliner(private val program: Program, private val options: CompilationOpti
|
||||
noModifications
|
||||
}
|
||||
else -> {
|
||||
if(origNode !== toInline) {
|
||||
sub.hasBeenInlined = true
|
||||
listOf(IAstModification.ReplaceNode(origNode, toInline.copy(), parent))
|
||||
} else
|
||||
noModifications
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,7 +258,7 @@ class Inliner(private val program: Program, private val options: CompilationOpti
|
||||
is Return -> {
|
||||
// is an expression, so we have to have a Return here in the inlined sub
|
||||
// note that we don't have to process any args, because we online inline parameterless subroutines.
|
||||
if(toInline.value!=null) {
|
||||
if(toInline.value!=null && functionCallExpr!==toInline.value) {
|
||||
sub.hasBeenInlined=true
|
||||
listOf(IAstModification.ReplaceNode(functionCallExpr, toInline.value!!.copy(), parent))
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ private fun optimizeAst(program: Program, compilerOptions: CompilationOptions, e
|
||||
}
|
||||
|
||||
removeUnusedCode(program, errors,compilerOptions)
|
||||
while (true) {
|
||||
for(num_cycles in 0..10000) {
|
||||
// keep optimizing expressions and statements until no more steps remain
|
||||
val optsDone1 = program.simplifyExpressions(errors)
|
||||
val optsDone2 = program.optimizeStatements(errors, functions, compilerOptions)
|
||||
@ -444,8 +444,13 @@ private fun optimizeAst(program: Program, compilerOptions: CompilationOptions, e
|
||||
errors.report()
|
||||
break
|
||||
}
|
||||
if (optsDone1 + optsDone2 + optsDone3 == 0)
|
||||
val numOpts = optsDone1 + optsDone2 + optsDone3
|
||||
if (numOpts == 0)
|
||||
break
|
||||
|
||||
if(num_cycles==10000) {
|
||||
throw InternalCompilerException("optimizeAst() is looping endlessly, numOpts = $numOpts")
|
||||
}
|
||||
}
|
||||
removeUnusedCode(program, errors, compilerOptions)
|
||||
if(errors.noErrors()) {
|
||||
|
@ -2,12 +2,7 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
txt.print_ub(sys.sizeof_byte)
|
||||
txt.spc()
|
||||
txt.print_ub(sys.sizeof_word)
|
||||
txt.spc()
|
||||
txt.print_ub(sys.sizeof_float)
|
||||
txt.nl()
|
||||
}
|
||||
sub foo() { foo() }
|
||||
sub bar() -> ubyte { return bar() }
|
||||
sub start() { }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user