fix bug: VM MULR float error, another pointer dependency checker error

This commit is contained in:
Irmen de Jong
2025-08-05 21:37:40 +02:00
parent 9e85571a7b
commit 7c0fb10197
5 changed files with 131 additions and 11 deletions

View File

@@ -1707,7 +1707,7 @@ main {
errors.errors[1] shouldContain "assigning this value to struct instance not supported"
}
test("pointer variable usage detection in other block") {
test("pointer variable usage detection in other block 1") {
val src="""
main {
sub start() {
@@ -1723,4 +1723,80 @@ other {
compileText(VMTarget(), true, src, outputDir, writeAssembly = false) shouldNotBe null
}
test("pointer variable usage detection in other block 2") {
val src="""
main {
sub start() {
other.func.variable^^ += 3
}
}
other {
sub func() {
^^ubyte variable
}
}"""
compileText(VMTarget(), false, src, outputDir, writeAssembly = false) shouldNotBe null
compileText(VMTarget(), true, src, outputDir, writeAssembly = false) shouldNotBe null
}
test("float ptr inplace operations") {
val src="""
%option enable_floats
main {
^^float g_floats
sub start() {
^^float l_floats
f_add()
f_sub()
f_mul()
f_div()
sub f_add() {
l_floats^^ += 3.0
g_floats^^ += 3.0
other.g_floats^^ += 3.0
other.func.l_floats^^ += 3.0
}
sub f_sub() {
l_floats^^ -= 3.0
g_floats^^ -= 3.0
other.g_floats^^ -= 3.0
other.func.l_floats^^ -= 3.0
}
sub f_mul() {
l_floats^^ *= 3.0
g_floats^^ *= 3.0
other.g_floats^^ *= 3.0
other.func.l_floats^^ *= 3.0
}
sub f_div() {
l_floats^^ /= 3.0
g_floats^^ /= 3.0
other.g_floats^^ /= 3.0
other.func.l_floats^^ /= 3.0
}
}
}
other {
%option force_output
^^float g_floats
sub func() {
^^float l_floats
}
}"""
compileText(VMTarget(), false, src, outputDir) shouldNotBe null
//compileText(C64Target(), false, src, outputDir) shouldNotBe null
//compileText(Cx16Target(), false, src, outputDir) shouldNotBe null
}
})

View File

@@ -172,6 +172,9 @@ class CallGraph(private val program: Program) : IAstVisitor {
if(variable is VarDecl) {
allIdentifiersAndTargets.add(IdentifierReference(listOf(variable.name), variable.position) to variable)
}
else if(variable is Subroutine) {
notCalledButReferenced += variable
}
chain.removeLastOrNull()
}
super.visit(deref)

View File

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

View File

@@ -1,12 +1,52 @@
%option enable_floats
main {
^^float g_floats
sub start() {
other.bptr^^ = true
; other.bptr = 2222
;cx16.r0bL = other.bptr^^
^^float l_floats
f_add()
f_sub()
f_mul()
f_div()
sub f_add() {
l_floats^^ += 3.0
g_floats^^ += 3.0
other.g_floats^^ += 3.0
other.func.l_floats^^ += 3.0
}
sub f_sub() {
l_floats^^ -= 3.0
g_floats^^ -= 3.0
other.g_floats^^ -= 3.0
other.func.l_floats^^ -= 3.0
}
sub f_mul() {
l_floats^^ *= 3.0
g_floats^^ *= 3.0
other.g_floats^^ *= 3.0
other.func.l_floats^^ *= 3.0
}
sub f_div() {
l_floats^^ /= 3.0
g_floats^^ /= 3.0
other.g_floats^^ /= 3.0
other.func.l_floats^^ /= 3.0
}
}
}
other {
^^bool bptr
%option force_output
^^float g_floats
sub func() {
^^float l_floats
}
}

View File

@@ -679,15 +679,15 @@ val instructionFormats = mutableMapOf(
Opcode.SUBR to InstructionFormat.from("BW,<>r1,<r2 | F,<>fr1,<fr2"),
Opcode.SUB to InstructionFormat.from("BW,<>r1,<i | F,<>fr1,<i"),
Opcode.SUBM to InstructionFormat.from("BW,<r1,<>a | F,<fr1,<>a"),
Opcode.MULR to InstructionFormat.from("BW,<>r1,<r2"),
Opcode.MUL to InstructionFormat.from("BW,<>r1,<i"),
Opcode.MULM to InstructionFormat.from("BW,<r1,<>a"),
Opcode.MULR to InstructionFormat.from("BW,<>r1,<r2 | F,<>fr1,<fr2"),
Opcode.MUL to InstructionFormat.from("BW,<>r1,<i | F,<>fr1,<i"),
Opcode.MULM to InstructionFormat.from("BW,<r1,<>a | F,<fr1,<>a"),
Opcode.MULSR to InstructionFormat.from("BW,<>r1,<r2 | F,<>fr1,<fr2"),
Opcode.MULS to InstructionFormat.from("BW,<>r1,<i | F,<>fr1,<i"),
Opcode.MULSM to InstructionFormat.from("BW,<r1,<>a | F,<fr1,<>a"),
Opcode.DIVR to InstructionFormat.from("BW,<>r1,<r2"),
Opcode.DIV to InstructionFormat.from("BW,<>r1,<i"),
Opcode.DIVM to InstructionFormat.from("BW,<r1,<>a"),
Opcode.DIVR to InstructionFormat.from("BW,<>r1,<r2 | F,<>fr1,<fr2"),
Opcode.DIV to InstructionFormat.from("BW,<>r1,<i | F,<>fr1,<i"),
Opcode.DIVM to InstructionFormat.from("BW,<r1,<>a | F,<fr1,<>a"),
Opcode.DIVSR to InstructionFormat.from("BW,<>r1,<r2 | F,<>fr1,<fr2"),
Opcode.DIVS to InstructionFormat.from("BW,<>r1,<i | F,<>fr1,<i"),
Opcode.DIVSM to InstructionFormat.from("BW,<r1,<>a | F,<fr1,<>a"),