fix pointer variable usage detection in other block

This commit is contained in:
Irmen de Jong
2025-08-03 20:51:03 +02:00
parent 5cb8bcead7
commit 9e85571a7b
14 changed files with 46 additions and 54 deletions

View File

@@ -1,19 +1,19 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="michael.bull.kotlin.result.jvm" type="repository"> <library name="michael.bull.kotlin.result.jvm" type="repository">
<properties maven-id="com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1" /> <properties maven-id="com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0" />
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.0.1/kotlin-result-jvm-2.0.1.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.1.0/kotlin-result-jvm-2.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.2.0/kotlin-stdlib-2.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC> <JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.0.1/kotlin-result-jvm-2.0.1-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.1.0/kotlin-result-jvm-2.1.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.2.0/kotlin-stdlib-2.2.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
</JAVADOC> </JAVADOC>
<SOURCES> <SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.0.1/kotlin-result-jvm-2.0.1-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/com/michael-bull/kotlin-result/kotlin-result-jvm/2.1.0/kotlin-result-jvm-2.1.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.22/kotlin-stdlib-1.9.22-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.2.0/kotlin-stdlib-2.2.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
</SOURCES> </SOURCES>
</library> </library>

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -7,7 +5,7 @@ plugins {
dependencies { dependencies {
// should have no dependencies to other modules // should have no dependencies to other modules
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
} }
sourceSets { sourceSets {

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -9,7 +7,7 @@ dependencies {
implementation(project(":simpleAst")) implementation(project(":simpleAst"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1") testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1")
testImplementation("io.kotest:kotest-framework-datatest:5.9.1") testImplementation("io.kotest:kotest-framework-datatest:5.9.1")

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -11,7 +9,7 @@ dependencies {
implementation(project(":codeGenIntermediate")) implementation(project(":codeGenIntermediate"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
} }
sourceSets { sourceSets {

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -11,7 +9,7 @@ dependencies {
implementation(project(":intermediate")) implementation(project(":intermediate"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1") testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1") testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -8,7 +6,7 @@ dependencies {
implementation(project(":codeCore")) implementation(project(":codeCore"))
implementation(project(":compilerAst")) implementation(project(":compilerAst"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
// implementation "org.jetbrains.kotlin:kotlin-reflect" // implementation "org.jetbrains.kotlin:kotlin-reflect"
} }

View File

@@ -19,7 +19,7 @@ dependencies {
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// implementation("org.jetbrains.kotlin:kotlin-reflect") // implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.6") implementation("org.jetbrains.kotlinx:kotlinx-cli:0.3.6")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
testImplementation(project(":codeCore")) testImplementation(project(":codeCore"))
testImplementation(project(":intermediate")) testImplementation(project(":intermediate"))

View File

@@ -1707,4 +1707,20 @@ main {
errors.errors[1] shouldContain "assigning this value to struct instance not supported" errors.errors[1] shouldContain "assigning this value to struct instance not supported"
} }
test("pointer variable usage detection in other block") {
val src="""
main {
sub start() {
other.bptr^^ = true
cx16.r0bL = other.bptr^^
}
}
other {
^^bool bptr
}"""
compileText(VMTarget(), false, src, outputDir, writeAssembly = false) shouldNotBe null
compileText(VMTarget(), true, src, outputDir, writeAssembly = false) shouldNotBe null
}
}) })

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -8,7 +6,7 @@ dependencies {
implementation(project(":codeCore")) implementation(project(":codeCore"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.antlr:antlr4-runtime:4.13.2") implementation("org.antlr:antlr4-runtime:4.13.2")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
implementation(project(":parser")) implementation(project(":parser"))
} }

View File

@@ -166,9 +166,13 @@ class CallGraph(private val program: Program) : IAstVisitor {
} }
override fun visit(deref: PtrDereference) { override fun visit(deref: PtrDereference) {
val first = deref.definingScope.lookup(deref.chain.take(1)) val chain = deref.chain.toMutableList()
if(first is VarDecl) { while(chain.isNotEmpty()) {
allIdentifiersAndTargets.add(IdentifierReference(listOf(first.name), first.position) to first) val variable = deref.definingScope.lookup(chain)
if(variable is VarDecl) {
allIdentifiersAndTargets.add(IdentifierReference(listOf(variable.name), variable.position) to variable)
}
chain.removeLastOrNull()
} }
super.visit(deref) super.visit(deref)
} }

View File

@@ -1,7 +1,6 @@
TODO TODO
==== ====
STRUCTS and TYPED POINTERS STRUCTS and TYPED POINTERS
-------------------------- --------------------------

View File

@@ -1,23 +1,12 @@
%import floats
%import textio
%option no_sysinit
%zeropage basicsafe
main { main {
sub start() { sub start() {
pokebool(3000, true) other.bptr^^ = true
pokew(3100, 12345) ; other.bptr = 2222
pokef(3200, 3.1415927) ;cx16.r0bL = other.bptr^^
poke(3300, 222)
txt.print_bool(peekbool(3000))
txt.nl()
txt.print_uw(peekw(3100))
txt.nl()
txt.print_f(peekf(3200))
txt.nl()
txt.print_ub(peek(3300))
txt.nl()
} }
} }
other {
^^bool bptr
}

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -7,7 +5,7 @@ plugins {
dependencies { dependencies {
implementation(project(":codeCore")) implementation(project(":codeCore"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
} }
sourceSets { sourceSets {

View File

@@ -1,5 +1,3 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { plugins {
kotlin("jvm") kotlin("jvm")
} }
@@ -9,7 +7,7 @@ dependencies {
implementation(project(":codeCore")) implementation(project(":codeCore"))
implementation(project(":intermediate")) implementation(project(":intermediate"))
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") // implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.1") implementation("com.michael-bull.kotlin-result:kotlin-result-jvm:2.1.0")
testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1") testImplementation("io.kotest:kotest-runner-junit5-jvm:5.9.1")
testImplementation("io.kotest:kotest-framework-datatest:5.9.1") testImplementation("io.kotest:kotest-framework-datatest:5.9.1")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1") testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")