2021-12-16 19:27:22 +00:00
|
|
|
package prog8tests.codegeneration
|
|
|
|
|
|
|
|
import io.kotest.core.spec.style.FunSpec
|
2021-12-28 13:23:36 +00:00
|
|
|
import prog8.codegen.target.C64Target
|
2021-12-16 19:27:22 +00:00
|
|
|
import prog8tests.helpers.assertSuccess
|
|
|
|
import prog8tests.helpers.compileText
|
|
|
|
|
|
|
|
|
|
|
|
class TestVariables: FunSpec({
|
|
|
|
|
|
|
|
test("shared variables without refs not removed for inlined asm") {
|
|
|
|
val text = """
|
|
|
|
main {
|
|
|
|
sub start() {
|
2022-01-02 16:07:04 +00:00
|
|
|
ubyte[] @shared arrayvar = [1,2,3,4]
|
|
|
|
str @shared stringvar = "test"
|
2021-12-16 19:27:22 +00:00
|
|
|
ubyte @shared bytevar = 0
|
|
|
|
|
|
|
|
%asm {{
|
2022-01-02 16:07:04 +00:00
|
|
|
lda arrayvar
|
|
|
|
lda stringvar
|
2021-12-16 19:27:22 +00:00
|
|
|
lda bytevar
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2022-02-06 20:29:06 +00:00
|
|
|
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
2021-12-16 19:27:22 +00:00
|
|
|
}
|
2022-01-23 13:23:34 +00:00
|
|
|
|
|
|
|
test("array initialization with array literal") {
|
|
|
|
val text = """
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte[] @shared arrayvar = [1,2,3,4]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
2022-02-06 20:29:06 +00:00
|
|
|
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
2022-01-23 13:23:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test("array initialization with array var assignment") {
|
|
|
|
val text = """
|
|
|
|
main {
|
|
|
|
sub start() {
|
|
|
|
ubyte[3] @shared arrayvar = main.values
|
|
|
|
}
|
|
|
|
|
|
|
|
ubyte[] values = [1,2,3]
|
|
|
|
}
|
|
|
|
"""
|
2022-02-06 20:29:06 +00:00
|
|
|
compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
2022-01-23 13:23:34 +00:00
|
|
|
}
|
2021-12-16 19:27:22 +00:00
|
|
|
})
|