Skip to content

Commit

Permalink
renamed "intermediate AST" to "simplified AST"
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Jan 10, 2025
1 parent 66558f7 commit 2ab2130
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion codeCore/src/prog8/code/optimize/Optimizer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import prog8.code.ast.*
import prog8.code.core.*


fun optimizeIntermediateAst(program: PtProgram, options: CompilationOptions, st: SymbolTable, errors: IErrorReporter) {
fun optimizeSimplifiedAst(program: PtProgram, options: CompilationOptions, st: SymbolTable, errors: IErrorReporter) {
if (!options.optimize)
return
while (errors.noErrors() && optimizeAssignTargets(program, st) > 0) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/prog8/CompilerMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ private fun compileMain(args: Array<String>): Boolean {
val dontWriteAssembly by cli.option(ArgType.Boolean, fullName = "noasm", description="don't create assembly code")
val dontOptimize by cli.option(ArgType.Boolean, fullName = "noopt", description = "don't perform code optimizations")
val outputDir by cli.option(ArgType.String, fullName = "out", description = "directory for output files instead of current directory").default(".")
val printAst1 by cli.option(ArgType.Boolean, fullName = "printast1", description = "print out the compiler AST")
val plainText by cli.option(ArgType.Boolean, fullName = "plaintext", description = "output only plain text, no colors or fancy symbols")
val printAst2 by cli.option(ArgType.Boolean, fullName = "printast2", description = "print out the intermediate AST that is used for code generation")
val printAst1 by cli.option(ArgType.Boolean, fullName = "printast1", description = "print out the internal compiler AST")
val printAst2 by cli.option(ArgType.Boolean, fullName = "printast2", description = "print out the simplified AST that is used for code generation")
val quietAssembler by cli.option(ArgType.Boolean, fullName = "quietasm", description = "don't print assembler output results")
val slabsGolden by cli.option(ArgType.Boolean, fullName = "slabsgolden", description = "put memory() slabs in 'golden ram' memory area instead of at the end of the program. On the cx16 target this is $0400-07ff. This is unavailable on other systems.")
val slabsHighBank by cli.option(ArgType.Int, fullName = "slabshigh", description = "put memory() slabs in high memory area instead of at the end of the program. On the cx16 target the value specifies the HiRAM bank to use, on other systems this value is ignored.")
Expand Down
20 changes: 10 additions & 10 deletions compiler/src/prog8/compiler/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import prog8.code.ast.PtProgram
import prog8.code.ast.printAst
import prog8.code.ast.verifyFinalAstBeforeAsmGen
import prog8.code.core.*
import prog8.code.optimize.optimizeIntermediateAst
import prog8.code.optimize.optimizeSimplifiedAst
import prog8.code.target.*
import prog8.codegen.vm.VmCodeGen
import prog8.compiler.astprocessing.*
Expand Down Expand Up @@ -128,22 +128,22 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
println("*********** COMPILER AST END *************\n")
}

val intermediateAst = IntermediateAstMaker(program, args.errors).transform()
val intermediateAst = SimplifiedAstMaker(program, args.errors).transform()
val stMaker = SymbolTableMaker(intermediateAst, compilationOptions)
val symbolTable = stMaker.make()

postprocessIntermediateAst(intermediateAst, symbolTable, args.errors)
postprocessSimplifiedAst(intermediateAst, symbolTable, args.errors)
args.errors.report()

if(compilationOptions.optimize) {
optimizeIntermediateAst(intermediateAst, compilationOptions, symbolTable, args.errors)
optimizeSimplifiedAst(intermediateAst, compilationOptions, symbolTable, args.errors)
args.errors.report()
}

if(args.printAst2) {
println("\n*********** INTERMEDIATE AST *************")
println("\n*********** SIMPLIFIED AST *************")
printAst(intermediateAst, true, ::println)
println("*********** INTERMEDIATE AST END *************\n")
println("*********** SIMPLIFIED AST END *************\n")
}

verifyFinalAstBeforeAsmGen(intermediateAst, compilationOptions, symbolTable, args.errors)
Expand All @@ -161,7 +161,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
println("*********** COMPILER AST END *************\n")
}
if(args.printAst2) {
System.err.println("There is no intermediate Ast available if assembly generation is disabled.")
System.err.println("There is no simplified Ast available if assembly generation is disabled.")
}
}
}
Expand All @@ -184,11 +184,11 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
}
if (args.printAst2) {
if(ast==null)
println("There is no intermediate AST available because of compilation errors.")
println("There is no simplified AST available because of compilation errors.")
else {
println("\n*********** INTERMEDIATE AST *************")
println("\n*********** SIMPLIFIED AST *************")
printAst(ast, true, ::println)
println("*********** INTERMEDIATE AST END *************\n")
println("*********** SIMPLIFIED AST END *************\n")
}
}
if(!ac.message.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.io.path.isRegularFile
/**
* Convert 'old' compiler-AST into the 'new' simplified AST with baked types.
*/
class IntermediateAstMaker(private val program: Program, private val errors: IErrorReporter) {
class SimplifiedAstMaker(private val program: Program, private val errors: IErrorReporter) {
fun transform(): PtProgram {
val ptProgram = PtProgram(
program.name,
Expand Down Expand Up @@ -535,7 +535,7 @@ class IntermediateAstMaker(private val program: Program, private val errors: IEr

private fun transformSub(srcSub: Subroutine): PtSub {
val (vardecls, statements) = srcSub.statements.partition { it is VarDecl }
// if a sub returns 'str', replace with uword. Intermediate AST and I.R. don't contain 'str' datatype anymore.
// if a sub returns 'str', replace with uword. Simplified AST and I.R. don't contain 'str' datatype anymore.
var returnTypes = srcSub.returntypes.map {
if(it.isString) DataType.forDt(BaseDataType.UWORD) else it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import prog8.code.ast.*
import prog8.code.core.*


internal fun postprocessIntermediateAst(program: PtProgram, st: SymbolTable, errors: IErrorReporter) {
internal fun postprocessSimplifiedAst(program: PtProgram, st: SymbolTable, errors: IErrorReporter) {
processDefers(program, st, errors)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import prog8.code.core.BaseDataType
import prog8.code.core.DataType
import prog8.code.core.Position

class TestIntermediateAst: FunSpec({
class TestSimplifiedAst: FunSpec({

test("isSame on binaryExpressions") {
val expr1 = PtBinaryExpression("/", DataType.forDt(BaseDataType.UBYTE), Position.DUMMY)
Expand Down
4 changes: 2 additions & 2 deletions compiler/test/codegeneration/TestAsmGenSymbols.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import prog8.code.source.SourceCode
import prog8.code.target.C64Target
import prog8.code.target.VMTarget
import prog8.codegen.cpu6502.AsmGen6502Internal
import prog8.compiler.astprocessing.IntermediateAstMaker
import prog8.compiler.astprocessing.SimplifiedAstMaker
import prog8tests.helpers.*

class TestAsmGenSymbols: StringSpec({
Expand Down Expand Up @@ -79,7 +79,7 @@ class TestAsmGenSymbols: StringSpec({
fun createTestAsmGen6502(program: Program): AsmGen6502Internal {
val errors = ErrorReporterForTests()
val options = CompilationOptions(OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.FULL, emptyList(), CompilationOptions.AllZeropageAllowed, false, true, C64Target(), 999u, 0xffffu)
val ptProgram = IntermediateAstMaker(program, errors).transform()
val ptProgram = SimplifiedAstMaker(program, errors).transform()
val st = SymbolTableMaker(ptProgram, options).make()
return AsmGen6502Internal(ptProgram, st, options, errors, 0)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/source/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ One or more .p8 module files
Prints the "compiler AST" (the internal representation of the program) after all processing steps.

``-printast2``
Prints the "intermediate AST" which is the reduced representation of the program.
Prints the "simplified AST" which is the reduced representation of the program.
This is what is used in the code generators, to generate the executable code from.

``-quietasm``
Expand Down
2 changes: 1 addition & 1 deletion docs/source/technical.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Some notes and references into the compiler's source code modules:
syntax nodes closely representing the Prog8 program structure. (``compilerAst`` module)
#. For code generation, a much simpler AST has been defined that replaces the *Compiler AST*.
Most notably, node type information is now baked in. (``codeCore`` module, Pt- classes)
#. An *Intermediate Representation* has been defined that is generated from the intermediate AST. This IR
#. An *Intermediate Representation* has been defined that is generated from the simplified AST. This IR
is more or less a machine code language for a virtual machine - and indeed this is what the built-in
prog8 VM will execute if you use the 'virtual' compilation target and use ``-emu`` to launch the VM.
(``intermediate`` and ``codeGenIntermediate`` modules, and ``virtualmachine`` module for the VM related stuff)
Expand Down
1 change: 0 additions & 1 deletion docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ TODO
====

- change library routines that now return 1 value + say, another in R0, to just return 2 values now that this is supported for normal subroutines too.
- rename "intermediate AST" into "simplified AST" (docs + classes in code)

- add paypal donation button as well?
- announce prog8 on the 6502.org site?
Expand Down

0 comments on commit 2ab2130

Please sign in to comment.