From a086d6e009994f191fec2d535f0e3e515d359162 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sun, 18 Apr 2021 23:03:18 +0200 Subject: [PATCH] allow labels also in blocks instead of only in subroutines --- compilerAst/src/prog8/ast/antlr/Antr2Kotlin.kt | 3 ++- docs/source/todo.rst | 2 -- examples/test.p8 | 5 +++++ parser/antlr/prog8.g4 | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compilerAst/src/prog8/ast/antlr/Antr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antr2Kotlin.kt index f50e12e0f..42397489e 100644 --- a/compilerAst/src/prog8/ast/antlr/Antr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antr2Kotlin.kt @@ -45,7 +45,8 @@ private fun prog8Parser.BlockContext.toAst(isInLibrary: Boolean, encoding: IStri it.subroutinedeclaration()!=null -> it.subroutinedeclaration().toAst(encoding) it.directive()!=null -> it.directive().toAst() it.inlineasm()!=null -> it.inlineasm().toAst() - else -> throw FatalAstException("weird block statement $it") + it.labeldef()!=null -> it.labeldef().toAst() + else -> throw FatalAstException("weird block node $it") } } return Block(identifier().text, integerliteral()?.toAst()?.number?.toInt(), blockstatements.toMutableList(), isInLibrary, toPosition()) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index a9ff5829d..c33f96647 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,8 +2,6 @@ TODO ==== -- allow labels in blocks instead of only in subroutines? - - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking) - get rid of all other TODO's in the code ;-) diff --git a/examples/test.p8 b/examples/test.p8 index 6bd687d3b..fb227a48e 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -3,7 +3,12 @@ %import test_stack main { + +blocklabel: + sub start() { + +label1: ubyte xx=99 if 0==xx { txt.print("fout") diff --git a/parser/antlr/prog8.g4 b/parser/antlr/prog8.g4 index 780dff4db..8c15a60c1 100644 --- a/parser/antlr/prog8.g4 +++ b/parser/antlr/prog8.g4 @@ -80,6 +80,7 @@ block_statement: | variabledeclaration | subroutinedeclaration | inlineasm + | labeldef ;