mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
added ast printing of when statement
This commit is contained in:
parent
9bc36b4d99
commit
3581017489
@ -1,5 +1,6 @@
|
|||||||
package prog8.compiler
|
package prog8.compiler
|
||||||
|
|
||||||
|
import prog8.ast.antlr.escape
|
||||||
import prog8.ast.IFunctionCall
|
import prog8.ast.IFunctionCall
|
||||||
import prog8.ast.IStatement
|
import prog8.ast.IStatement
|
||||||
import prog8.ast.Module
|
import prog8.ast.Module
|
||||||
@ -245,7 +246,7 @@ class AstToSourceCode(val output: (text: String) -> Unit): IAstVisitor {
|
|||||||
override fun visit(literalValue: LiteralValue) {
|
override fun visit(literalValue: LiteralValue) {
|
||||||
when {
|
when {
|
||||||
literalValue.isNumeric -> output(literalValue.asNumericValue.toString())
|
literalValue.isNumeric -> output(literalValue.asNumericValue.toString())
|
||||||
literalValue.isString -> output("\"${literalValue.strvalue}\"")
|
literalValue.isString -> output("\"${escape(literalValue.strvalue!!)}\"")
|
||||||
literalValue.isArray -> {
|
literalValue.isArray -> {
|
||||||
if(literalValue.arrayvalue!=null) {
|
if(literalValue.arrayvalue!=null) {
|
||||||
output("[")
|
output("[")
|
||||||
@ -385,6 +386,30 @@ class AstToSourceCode(val output: (text: String) -> Unit): IAstVisitor {
|
|||||||
output(builtinFunctionStatementPlaceholder.name)
|
output(builtinFunctionStatementPlaceholder.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun visit(whenStatement: WhenStatement) {
|
||||||
|
output("when ")
|
||||||
|
whenStatement.condition.accept(this)
|
||||||
|
outputln(" {")
|
||||||
|
scopelevel++
|
||||||
|
whenStatement.choices.forEach { it.accept(this) }
|
||||||
|
scopelevel--
|
||||||
|
outputlni("}")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visit(whenChoice: WhenChoice) {
|
||||||
|
if(whenChoice.value==null)
|
||||||
|
outputi("else -> ")
|
||||||
|
else {
|
||||||
|
outputi("")
|
||||||
|
whenChoice.value.accept(this)
|
||||||
|
output(" -> ")
|
||||||
|
}
|
||||||
|
if(whenChoice.statements.statements.size==1)
|
||||||
|
whenChoice.statements.statements.single().accept(this)
|
||||||
|
else
|
||||||
|
whenChoice.statements.accept(this)
|
||||||
|
outputln("")
|
||||||
|
}
|
||||||
override fun visit(nopStatement: NopStatement) {
|
override fun visit(nopStatement: NopStatement) {
|
||||||
TODO("NOP???")
|
TODO("NOP???")
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,6 @@ fun compileProgram(filepath: Path,
|
|||||||
val time3 = measureTimeMillis {
|
val time3 = measureTimeMillis {
|
||||||
programAst.reorderStatements() // reorder statements and add type casts, to please the compiler later
|
programAst.reorderStatements() // reorder statements and add type casts, to please the compiler later
|
||||||
}
|
}
|
||||||
printAst(programAst)
|
|
||||||
//println(" time3: $time3")
|
//println(" time3: $time3")
|
||||||
val time4 = measureTimeMillis {
|
val time4 = measureTimeMillis {
|
||||||
programAst.checkValid(compilerOptions) // check if tree is valid
|
programAst.checkValid(compilerOptions) // check if tree is valid
|
||||||
|
@ -9,6 +9,9 @@
|
|||||||
Y=22
|
Y=22
|
||||||
uword uw = A*Y
|
uword uw = A*Y
|
||||||
|
|
||||||
|
str teststring = "hello"
|
||||||
|
c64scr.print(&teststring)
|
||||||
|
|
||||||
when uw {
|
when uw {
|
||||||
12345 -> {
|
12345 -> {
|
||||||
A=44
|
A=44
|
||||||
|
Loading…
Reference in New Issue
Block a user