mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
fix new Ast gosub node translation
This commit is contained in:
parent
c57af5e81b
commit
6be3b62d78
@ -4,6 +4,7 @@ import com.github.michaelbull.result.Ok
|
||||
import com.github.michaelbull.result.Result
|
||||
import com.github.michaelbull.result.getOrElse
|
||||
import com.github.michaelbull.result.mapError
|
||||
import prog8.ast.IFunctionCall
|
||||
import prog8.ast.IStatementContainer
|
||||
import prog8.ast.Program
|
||||
import prog8.ast.base.FatalAstException
|
||||
@ -232,15 +233,14 @@ class IntermediateAstMaker(val program: Program) {
|
||||
}
|
||||
// instead of just assigning to the parameters, another way is to use push()/pop()
|
||||
if(previousNodes.isNotEmpty()) {
|
||||
val first = previousNodes[0] as? FunctionCallStatement
|
||||
if(first!=null && first.target.nameInSource == listOf("pop")) {
|
||||
val numPops = previousNodes.indexOfFirst { (it as? FunctionCallStatement)?.target?.nameInSource != listOf("pop") }
|
||||
val first = previousNodes[0] as? IFunctionCall
|
||||
if(first!=null && (first.target.nameInSource.singleOrNull() in arrayOf("pop", "popw"))) {
|
||||
val numPops = previousNodes.indexOfFirst { (it as? IFunctionCall)?.target?.nameInSource?.singleOrNull() !in arrayOf("pop", "popw") }
|
||||
val pops = previousNodes.subList(0, numPops)
|
||||
val pushes = previousNodes.subList(numPops, numPops+numPops)
|
||||
// TODO one of these has to be reversed?
|
||||
val pushes = previousNodes.subList(numPops, numPops+numPops).reversed()
|
||||
for ((push, pop) in pushes.zip(pops)) {
|
||||
val name = ((pop as FunctionCallStatement).args.single() as IdentifierReference).nameInSource.last()
|
||||
val arg = (push as FunctionCallStatement).args.single()
|
||||
val name = ((pop as IFunctionCall).args.single() as IdentifierReference).nameInSource.last()
|
||||
val arg = (push as IFunctionCall).args.single()
|
||||
paramValues[name] = arg
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,6 @@ internal class BeforeAsmAstChanger(val program: Program,
|
||||
}
|
||||
|
||||
override fun after(containment: ContainmentCheck, parent: Node): Iterable<IAstModification> {
|
||||
if(containment.element !is IdentifierReference && containment.element !is NumericLiteral)
|
||||
throw InternalCompilerException("element in containmentcheck should be identifier or constant number")
|
||||
if(containment.iterable !is IdentifierReference)
|
||||
throw InternalCompilerException("iterable in containmentcheck should be identifier (referencing string or array)")
|
||||
return noModifications
|
||||
|
@ -3,7 +3,7 @@ TODO
|
||||
|
||||
For next release
|
||||
^^^^^^^^^^^^^^^^
|
||||
- fix assembler application compiler crash
|
||||
- fix assembler application included file loading problem (hello4.asm)
|
||||
- x16: add new keyboard APIs https://github.com/commanderx16/x16-docs/blob/master/Commander%20X16%20Programmer%27s%20Reference%20Guide.md#keyboard
|
||||
- x16: optimize diskio load_raw because headerless files are now supported https://github.com/commanderx16/x16-rom/pull/216
|
||||
note: must still work on c64/c128 that don't have this!
|
||||
|
Loading…
Reference in New Issue
Block a user