parser: allow curly brace on next line for asmsub too

downgrade antlr4 one version again to what is used in IntelliJ's antlr plugin, to avoid potential version conflicts
This commit is contained in:
Irmen de Jong 2023-08-09 20:01:12 +02:00
parent a82d21ac05
commit 7c0bde7310
9 changed files with 83 additions and 35 deletions

View File

@ -1,13 +1,13 @@
<component name="libraryTable">
<library name="antlr.antlr4" type="repository">
<properties maven-id="org.antlr:antlr4:4.13.0">
<properties maven-id="org.antlr:antlr4:4.12.0">
<exclude>
<dependency maven-id="com.ibm.icu:icu4j" />
</exclude>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4/4.13.0/antlr4-4.13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4-runtime/4.13.0/antlr4-runtime-4.13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4/4.12.0/antlr4-4.12.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr4-runtime/4.12.0/antlr4-runtime-4.12.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/antlr-runtime/3.5.3/antlr-runtime-3.5.3.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/antlr/ST4/4.3.4/ST4-4.3.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/abego/treelayout/org.abego.treelayout.core/1.0.3/org.abego.treelayout.core-1.0.3.jar!/" />

View File

@ -1001,7 +1001,10 @@ $repeatLabel""")
}
private fun translate(asm: PtInlineAssembly) {
assemblyLines.add(asm.assembly.trimEnd().trimStart('\r', '\n'))
if(asm.isIR)
throw AssemblyError("%asm containing IR code cannot be translated to 6502 assembly")
else
assemblyLines.add(asm.assembly.trimEnd().trimStart('\r', '\n'))
}
private fun translate(incbin: PtIncludeBinary) {

View File

@ -33,7 +33,7 @@ dependencies {
implementation project(':codeGenIntermediate')
implementation project(':codeGenExperimental')
implementation project(':virtualmachine')
implementation "org.antlr:antlr4-runtime:4.13.0"
implementation "org.antlr:antlr4-runtime:4.12.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.5'

View File

@ -1416,6 +1416,11 @@ internal class AstChecker(private val program: Program,
super.visit(memwrite)
}
override fun visit(inlineAssembly: InlineAssembly) {
if(inlineAssembly.isIR && compilerOptions.compTarget.name != VMTarget.NAME)
errors.err("%asm containing IR code cannot be translated to 6502 assembly", inlineAssembly.position)
}
private fun checkFunctionOrLabelExists(target: IdentifierReference, statement: Statement): Statement? {
when (val targetStatement = target.targetStatement(program)) {
is Label, is Subroutine, is BuiltinFunctionPlaceholder -> return targetStatement

View File

@ -19,6 +19,7 @@ import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.code.core.*
import prog8.code.target.C64Target
import prog8.code.target.VMTarget
import prog8.code.target.cbm.PetsciiEncoding
import prog8.parser.ParseError
import prog8.parser.Prog8Parser.parseModule
@ -984,4 +985,44 @@ main {
compileText(C64Target(), false, src, writeAssembly = false) shouldNotBe null
}
test("various alternative curly brace styles are ok") {
val src="""
%zeropage dontuse
main {
; curly braces without newline
sub start () { foo() derp() other() }
sub foo() { cx16.r0++ }
asmsub derp() { %asm {{ nop }} %ir {{ loadr.b r0,1 }} }
; curly braces on next line
sub other()
{
cx16.r0++
asmother()
asmir()
}
asmsub asmother()
{
%asm
{{
txa
tay
}}
}
asmsub asmir()
{
%ir
{{
loadr.b r0,1
}}
}
}"""
compileText(VMTarget(), false, src, writeAssembly = false) shouldNotBe null
}
})

View File

@ -24,7 +24,7 @@ compileTestKotlin {
dependencies {
implementation project(':codeCore')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.antlr:antlr4-runtime:4.13.0"
implementation "org.antlr:antlr4-runtime:4.12.0"
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.18"
implementation project(':parser')
}

View File

@ -1,32 +1,31 @@
%import gfx2
%zeropage dontuse
main {
sub start () {
gfx2.screen_mode(5)
gfx2.monochrome_stipple(false)
for cx16.r0 in 100 to 200 {
for cx16.r1 in 100 to 110 {
gfx2.plot(cx16.r0, cx16.r1, 1)
}
}
sub start () { foo() derp() other() }
sub foo() { cx16.r0++ }
asmsub derp() { %asm {{ nop }} %ir {{ loadr.b r0,1 }} }
gfx2.monochrome_stipple(true)
for cx16.r0 in 100 to 200 {
for cx16.r1 in 110 to 120 {
gfx2.plot(cx16.r0, cx16.r1, 1)
}
}
sub other()
{
cx16.r0++
asmother()
asmir()
}
gfx2.monochrome_stipple(true)
for cx16.r0 in 110 to 190 {
for cx16.r1 in 105 to 115 {
gfx2.plot(cx16.r0, cx16.r1, 0)
}
}
asmsub asmother()
{
%asm
{{
txa
tay
}}
}
gfx2.disc(320, 240, 140, 1)
gfx2.monochrome_stipple(false)
gfx2.disc(320, 240, 100, 0)
asmsub asmir()
{
%ir
{{
loadr.b r0,1
}}
}
}

View File

@ -233,9 +233,9 @@ literalvalue :
| floatliteral
;
inlineasm : '%asm' INLINEASMBLOCK;
inlineasm : '%asm' EOL? INLINEASMBLOCK;
inlineir: '%ir' INLINEASMBLOCK;
inlineir: '%ir' EOL? INLINEASMBLOCK;
inline: 'inline';
@ -255,7 +255,7 @@ statement_block :
sub_params : vardecl (',' EOL? vardecl)* ;
asmsubroutine :
inline? 'asmsub' asmsub_decl statement_block
inline? 'asmsub' asmsub_decl EOL? (statement_block EOL)
;
romsubroutine :

View File

@ -10,8 +10,8 @@ java {
}
dependencies {
antlr 'org.antlr:antlr4:4.13.0'
implementation 'org.antlr:antlr4-runtime:4.13.0'
antlr 'org.antlr:antlr4:4.12.0'
implementation 'org.antlr:antlr4-runtime:4.12.0'
}
configurations.all {