From 90c4a26d52ddd6d20b982f6e719837e59190ee7b Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 7 Sep 2020 01:24:10 +0200 Subject: [PATCH] we don't implement asmsub params via @stack yet --- compiler/src/prog8/ast/AstToSourceCode.kt | 2 +- compiler/src/prog8/ast/antlr/Antr2Kotlin.kt | 7 +++---- docs/source/syntaxreference.rst | 22 +++++++++++---------- docs/source/todo.rst | 1 + parser/antlr/prog8.g4 | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/compiler/src/prog8/ast/AstToSourceCode.kt b/compiler/src/prog8/ast/AstToSourceCode.kt index 0336c8857..2e6344c03 100644 --- a/compiler/src/prog8/ast/AstToSourceCode.kt +++ b/compiler/src/prog8/ast/AstToSourceCode.kt @@ -140,7 +140,7 @@ class AstToSourceCode(val output: (text: String) -> Unit, val program: Program): param.second.stack -> "stack" param.second.registerOrPair!=null -> param.second.registerOrPair.toString() param.second.statusflag!=null -> param.second.statusflag.toString() - else -> "?????1" + else -> "?????" } output("${datatypeString(param.first.type)} ${param.first.name} @$reg") if(param.first!==subroutine.parameters.last()) diff --git a/compiler/src/prog8/ast/antlr/Antr2Kotlin.kt b/compiler/src/prog8/ast/antlr/Antr2Kotlin.kt index 0573ae238..dcc941271 100644 --- a/compiler/src/prog8/ast/antlr/Antr2Kotlin.kt +++ b/compiler/src/prog8/ast/antlr/Antr2Kotlin.kt @@ -254,7 +254,7 @@ private fun prog8Parser.Asmsub_declContext.toAst(): AsmsubDecl { val clobbers = asmsub_clobbers()?.clobber()?.toAst() ?: emptySet() val normalParameters = params.map { SubroutineParameter(it.name, it.type, it.position) } val normalReturntypes = returns.map { it.type } - val paramRegisters = params.map { RegisterOrStatusflag(it.registerOrPair, it.statusflag, it.stack) } + val paramRegisters = params.map { RegisterOrStatusflag(it.registerOrPair, it.statusflag, false) } val returnRegisters = returns.map { RegisterOrStatusflag(it.registerOrPair, it.statusflag, it.stack) } return AsmsubDecl(name, normalParameters, normalReturntypes, paramRegisters, returnRegisters, clobbers) } @@ -263,7 +263,7 @@ private class AsmSubroutineParameter(name: String, type: DataType, val registerOrPair: RegisterOrPair?, val statusflag: Statusflag?, - val stack: Boolean, + // TODO implement: val stack: Boolean, position: Position) : SubroutineParameter(name, type, position) private class AsmSubroutineReturn(val type: DataType, @@ -305,8 +305,7 @@ private fun prog8Parser.Asmsub_paramsContext.toAst(): List throw FatalAstException("invalid register or status flag '$name'") } } - AsmSubroutineParameter(vardecl.varname.text, datatype, registerorpair, statusregister, - !it.stack?.text.isNullOrEmpty(), toPosition()) + AsmSubroutineParameter(vardecl.varname.text, datatype, registerorpair, statusregister, toPosition()) } private fun prog8Parser.Functioncall_stmtContext.toAst(): Statement { diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index ca74d66c7..991edefb0 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -514,18 +514,20 @@ and returning stuff in several registers as well. The ``clobbers`` clause is use what CPU registers are clobbered by the call instead of being unchanged or returning a meaningful result value. -Subroutines that are implemented purely in assembly code and which have an assembly calling convention (i.e. -the parameters are strictly passed via cpu registers), are defined like this:: +User subroutines in the program source code that are implemented purely in assembly and which have an assembly calling convention (i.e. +the parameters are strictly passed via cpu registers), are defined with ``asmsub`` like this:: - asmsub FREADS32() clobbers(A,X,Y) { + asmsub clear_screenchars (ubyte char @ A) clobbers(Y) { %asm {{ - lda $62 - eor #$ff - asl a - lda #0 - ldx #$a0 - jmp $bc4f - }} + ldy #0 + _loop sta c64.Screen,y + sta c64.Screen+$0100,y + sta c64.Screen+$0200,y + sta c64.Screen+$02e8,y + iny + bne _loop + rts + }} } the statement body of such a subroutine should consist of just an inline assembly block. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index c6a1c6e78..e6deed03d 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,6 +5,7 @@ TODO - further optimize assignment codegeneration - auto select correct library to import based on target, instead of having c64- and cx16- prefix variants - get rid of all TODO's ;-) +- implement @stack for asmsub parameters - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging) - aliases for imported symbols for example perhaps '%alias print = c64scr.print' ? diff --git a/parser/antlr/prog8.g4 b/parser/antlr/prog8.g4 index 03efaa3bf..2e451c904 100644 --- a/parser/antlr/prog8.g4 +++ b/parser/antlr/prog8.g4 @@ -273,7 +273,7 @@ asmsub_decl : identifier '(' asmsub_params? ')' asmsub_clobbers? asmsub_returns? asmsub_params : asmsub_param (',' EOL? asmsub_param)* ; -asmsub_param : vardecl '@' (identifier | stack='stack') ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed +asmsub_param : vardecl '@' identifier ; // A,X,Y,AX,AY,XY,Pc,Pz,Pn,Pv allowed. TODO implement stack='stack' asmsub_clobbers : 'clobbers' '(' clobber? ')' ;