diff --git a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt index 388aff06f..b3515b8fd 100644 --- a/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt +++ b/compilerAst/src/prog8/ast/antlr/Antlr2Kotlin.kt @@ -202,14 +202,14 @@ private class AsmSubroutineReturn(val type: DataType, private fun Prog8ANTLRParser.Asmsub_returnsContext.toAst(): List = asmsub_return().map { - val register = it.register().text + val register = it.register.text var registerorpair: RegisterOrPair? = null var statusregister: Statusflag? = null if(register!=null) { when (register) { in RegisterOrPair.names -> registerorpair = RegisterOrPair.valueOf(register) in Statusflag.names -> statusregister = Statusflag.valueOf(register) - else -> throw FatalAstException("invalid register or status flag in $it") + else -> throw SyntaxError("invalid register or status flag", toPosition()) } } AsmSubroutineReturn( @@ -224,14 +224,17 @@ private fun Prog8ANTLRParser.Asmsub_paramsContext.toAst(): List registerorpair = RegisterOrPair.valueOf(register) in Statusflag.names -> statusregister = Statusflag.valueOf(register) - else -> throw FatalAstException("invalid register or status flag '$register'") + else -> { + val p = toPosition() + throw SyntaxError("invalid register or status flag", Position(p.file, it.register.line, it.register.charPositionInLine, it.register.charPositionInLine+1)) + } } } AsmSubroutineParameter(vardecl.varname.text, datatype, registerorpair, statusregister, toPosition()) @@ -314,8 +317,12 @@ private fun Prog8ANTLRParser.Assign_targetContext.toAst() : AssignTarget { } private fun Prog8ANTLRParser.ClobberContext.toAst() : Set { - val names = this.cpuregister().map { it.text } - return names.map { CpuRegister.valueOf(it) }.toSet() + val names = this.NAME().map { it.text } + try { + return names.map { CpuRegister.valueOf(it) }.toSet() + } catch(ax: IllegalArgumentException) { + throw SyntaxError("invalid pu register", toPosition()) + } } private fun Prog8ANTLRParser.DatatypeContext.toAst() = DataType.valueOf(text.uppercase()) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 559ee9630..e5f30fe17 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,8 +3,11 @@ TODO For next minor release ^^^^^^^^^^^^^^^^^^^^^^ -- fix IR/VM: animals.p8 example somehow doesn't print the animal name correctly in the first question, and exits after 1 animal instead of looping +- check that peekw() and peek() and @(...) accept a[i] where a=uword +- fix pokew() crash with args like: a[i] (where a=uword) , z % twoIMinusOne - fix Github issue with X register https://github.com/irmen/prog8/issues/94 +- fix Github issue with array problems https://github.com/irmen/prog8/issues/99 +- fix IR/VM: animals.p8 example somehow doesn't print the animal name correctly in the first question, and exits after 1 animal instead of looping ... diff --git a/parser/antlr/Prog8ANTLR.g4 b/parser/antlr/Prog8ANTLR.g4 index e9ae0ca5f..38c0fb059 100644 --- a/parser/antlr/Prog8ANTLR.g4 +++ b/parser/antlr/Prog8ANTLR.g4 @@ -55,8 +55,6 @@ ARRAYSIG : '[]' ; -cpuregister: 'A' | 'X' | 'Y'; -register: 'A' | 'X' | 'Y' | 'AX' | 'AY' | 'XY' | 'Pc' | 'Pz' | 'Pn' | 'Pv' | 'R0' | 'R1' | 'R2' | 'R3' | 'R4' | 'R5' | 'R6' | 'R7' | 'R8' | 'R9' | 'R10' | 'R11' | 'R12' | 'R13' | 'R14' | 'R15'; // A module (file) consists of zero or more directives or blocks, in any order. // If there are more than one, then they must be separated by EOL (one or more newlines). @@ -66,7 +64,6 @@ module: EOL* ((directive | block) (EOL+ (directive | block))*)? EOL* EOF; block: identifier integerliteral? '{' EOL (block_statement | EOL)* '}'; - block_statement: directive | variabledeclaration @@ -263,15 +260,15 @@ asmsub_decl : identifier '(' asmsub_params? ')' asmsub_clobbers? asmsub_returns? asmsub_params : asmsub_param (',' EOL? asmsub_param)* ; -asmsub_param : vardecl '@' register ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed. +asmsub_param : vardecl '@' register=NAME ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed. asmsub_clobbers : 'clobbers' '(' clobber? ')' ; -clobber : cpuregister (',' cpuregister)* ; // A,X,Y allowed +clobber : NAME (',' NAME)* ; // A,X,Y allowed asmsub_returns : '->' asmsub_return (',' EOL? asmsub_return)* ; -asmsub_return : datatype '@' register ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed +asmsub_return : datatype '@' register=NAME ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed if_stmt : 'if' expression EOL? (statement | statement_block) EOL? else_part? ; // statement is constrained later