mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
working on new ast
This commit is contained in:
parent
48d782c69c
commit
dc93691fd9
@ -1,6 +1,7 @@
|
||||
package prog8.codegen.experimental6502
|
||||
|
||||
import prog8.ast.Program
|
||||
import prog8.ast.base.FatalAstException
|
||||
import prog8.compilerinterface.*
|
||||
|
||||
class AsmGen(internal val program: Program,
|
||||
@ -17,6 +18,8 @@ class AsmGen(internal val program: Program,
|
||||
// TODO temporary location to do this:
|
||||
val intermediateAst = IntermediateAstMaker.transform(program)
|
||||
intermediateAst.print()
|
||||
val entry = intermediateAst.entrypoint() ?: throw FatalAstException("no main.start() found")
|
||||
println(entry)
|
||||
|
||||
println("..todo: create assembly code into ${options.outputDir.toAbsolutePath()}..")
|
||||
return AssemblyProgram("dummy")
|
||||
|
@ -1,6 +1,8 @@
|
||||
package prog8tests.ast
|
||||
|
||||
import io.kotest.assertions.fail
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.ints.shouldBeGreaterThan
|
||||
import io.kotest.matchers.shouldBe
|
||||
import prog8.codegen.experimental6502.IntermediateAstMaker
|
||||
import prog8.codegen.target.C64Target
|
||||
@ -26,6 +28,11 @@ class TestIntermediateAst: FunSpec({
|
||||
val ast = IntermediateAstMaker.transform(result.program)
|
||||
ast.name shouldBe result.program.name
|
||||
ast.builtinFunctions.names shouldBe result.program.builtinFunctions.names
|
||||
val entry = ast.entrypoint() ?: fail("no main.start() found")
|
||||
entry.name shouldBe "start"
|
||||
val blocks = ast.allBlocks().toList()
|
||||
blocks.size shouldBeGreaterThan 1
|
||||
blocks[0].name shouldBe "main"
|
||||
ast.print()
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,12 @@ class PtProgram(
|
||||
override fun printProperties() {
|
||||
print("'$name'")
|
||||
}
|
||||
|
||||
fun allBlocks(): Sequence<PtBlock> =
|
||||
children.asSequence().flatMap { it.children }.filterIsInstance<PtBlock>()
|
||||
|
||||
fun entrypoint(): PtSub? =
|
||||
allBlocks().firstOrNull { it.name == "main" }?.children?.firstOrNull { it is PtSub && it.name == "start" } as PtSub?
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user