From f37a82272561442c66da21301253e75b57eda40f Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 14 Aug 2022 13:06:11 +0200 Subject: [PATCH] move --- codeAst/src/prog8/code/ast/AstBase.kt | 2 +- compiler/src/prog8/compiler/Compiler.kt | 3 +-- .../compiler/{ => astprocessing}/IntermediateAstMaker.kt | 7 ++++++- compiler/test/ast/TestIntermediateAst.kt | 2 +- docs/source/todo.rst | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) rename compiler/src/prog8/compiler/{ => astprocessing}/IntermediateAstMaker.kt (98%) diff --git a/codeAst/src/prog8/code/ast/AstBase.kt b/codeAst/src/prog8/code/ast/AstBase.kt index 1f48beb6b..128eb80d6 100644 --- a/codeAst/src/prog8/code/ast/AstBase.kt +++ b/codeAst/src/prog8/code/ast/AstBase.kt @@ -3,7 +3,7 @@ package prog8.code.ast import prog8.code.core.* import java.nio.file.Path -// New (work-in-progress) simplified AST for the code generator. +// New simplified AST for the code generator. sealed class PtNode(val position: Position) { diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index e901e9af8..8bce24256 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -446,13 +446,12 @@ internal fun asmGeneratorFor(program: Program, { if(options.experimentalCodegen) { if (options.compTarget.machine.cpu in arrayOf(CpuType.CPU6502, CpuType.CPU65c02)) { - // TODO for now, use the new Intermediary Ast for this experimental codegen: val intermediateAst = IntermediateAstMaker(program).transform() return prog8.codegen.experimental.AsmGen(intermediateAst, symbolTable, options, errors) } } else { if (options.compTarget.machine.cpu in arrayOf(CpuType.CPU6502, CpuType.CPU65c02)) - // TODO rewrite 6502 codegen on new Intermediary Ast + // TODO rewrite 6502 codegen on new Intermediary Ast or on new Intermediate Representation return prog8.codegen.cpu6502.AsmGen(program, symbolTable, options, errors) if (options.compTarget.name == VMTarget.NAME) { val intermediateAst = IntermediateAstMaker(program).transform() diff --git a/compiler/src/prog8/compiler/IntermediateAstMaker.kt b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt similarity index 98% rename from compiler/src/prog8/compiler/IntermediateAstMaker.kt rename to compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt index beef633c9..600cf11d7 100644 --- a/compiler/src/prog8/compiler/IntermediateAstMaker.kt +++ b/compiler/src/prog8/compiler/astprocessing/IntermediateAstMaker.kt @@ -1,4 +1,4 @@ -package prog8.compiler +package prog8.compiler.astprocessing import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Result @@ -12,11 +12,16 @@ import prog8.code.ast.* import prog8.code.core.DataType import prog8.code.core.Position import prog8.code.core.SourceCode +import prog8.compiler.BuiltinFunctions +import prog8.compiler.builtinFunctionReturnType import java.io.File import kotlin.io.path.Path import kotlin.io.path.isRegularFile +/** + * Convert 'old' compiler-AST into the 'new' simplified AST with baked types. + */ class IntermediateAstMaker(val program: Program) { fun transform(): PtProgram { val ptProgram = PtProgram( diff --git a/compiler/test/ast/TestIntermediateAst.kt b/compiler/test/ast/TestIntermediateAst.kt index 848a09c87..d50a48490 100644 --- a/compiler/test/ast/TestIntermediateAst.kt +++ b/compiler/test/ast/TestIntermediateAst.kt @@ -7,7 +7,7 @@ import io.kotest.matchers.shouldBe import prog8.code.ast.* import prog8.code.core.DataType import prog8.code.target.C64Target -import prog8.compiler.IntermediateAstMaker +import prog8.compiler.astprocessing.IntermediateAstMaker import prog8tests.helpers.compileText class TestIntermediateAst: FunSpec({ diff --git a/docs/source/todo.rst b/docs/source/todo.rst index f504db8e2..21835dd49 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -6,6 +6,7 @@ For next release - vm: intermediate code: don't flatten everything. Instead, as a new intermediary step, convert the new Ast into *structured* intermediary code. Basically keep the blocks and subroutines structure, including full subroutine signature information, + don't do variable and zeropage allocations yet. ...