remove needless library module imports in unit tests

This commit is contained in:
Irmen de Jong
2025-10-05 13:09:37 +02:00
parent 961095bfec
commit 4195e3968a
10 changed files with 77 additions and 104 deletions

View File

@@ -1564,33 +1564,34 @@ main {
test("hoist variable decl and initializer correctly in case of pointer type variable as well") { test("hoist variable decl and initializer correctly in case of pointer type variable as well") {
val src=""" val src="""
%import textio
main { main {
sub start() { sub start() {
txt.print("one\n") stuff()
if true { if true {
txt.print("two\n") stuff()
^^bool @shared successor = find_successor() ; testcase here ^^bool @shared successor = find_successor() ; testcase here
} }
txt.print("four\n") stuff()
sub find_successor() -> uword { sub find_successor() -> uword {
txt.print("three\n") stuff()
cx16.r0++ cx16.r0++
return 0 return 0
} }
} }
sub stuff() {
}
}""" }"""
compileText(C64Target(), false, src, outputDir) shouldNotBe null compileText(C64Target(), false, src, outputDir) shouldNotBe null
val result = compileText(VMTarget(), false, src, outputDir)!! val result = compileText(VMTarget(), false, src, outputDir)!!
val st = result.compilerAst.entrypoint.statements val st = result.compilerAst.entrypoint.statements
st.size shouldBe 6 st.size shouldBe 6
st[0] shouldBe instanceOf<VarDecl>() st[0] shouldBe instanceOf<VarDecl>()
(st[1] as FunctionCallStatement).target.nameInSource shouldBe listOf("txt", "print") (st[1] as FunctionCallStatement).target.nameInSource shouldBe listOf("stuff")
st[2] shouldBe instanceOf<IfElse>() st[2] shouldBe instanceOf<IfElse>()
(st[3] as FunctionCallStatement).target.nameInSource shouldBe listOf("txt", "print") (st[3] as FunctionCallStatement).target.nameInSource shouldBe listOf("stuff")
st[4] shouldBe instanceOf<Return>() st[4] shouldBe instanceOf<Return>()
st[5] shouldBe instanceOf<Subroutine>() st[5] shouldBe instanceOf<Subroutine>()
} }

View File

@@ -193,17 +193,20 @@ main {
test("word to byte casts") { test("word to byte casts") {
val text = """ val text = """
%import textio
main { main {
sub func(ubyte arg) -> word { sub func(ubyte arg) -> word {
return arg-99 return arg-99
} }
sub start() { sub start() {
txt.print_ub(func(0) as ubyte) funcub(func(0) as ubyte)
txt.print_uw(func(0) as ubyte) funcuw(func(0) as ubyte)
txt.print_w(func(0) as ubyte) funcw(func(0) as ubyte)
} }
sub funcub(ubyte arg) { }
sub funcuw(uword arg) { }
sub funcw(word arg) { }
}""" }"""
val result = compileText(C64Target(), false, text, outputDir, writeAssembly = false)!! val result = compileText(C64Target(), false, text, outputDir, writeAssembly = false)!!
val stmts = result.compilerAst.entrypoint.statements val stmts = result.compilerAst.entrypoint.statements

View File

@@ -63,17 +63,19 @@ class TestAstChecks: FunSpec({
test("can't do str or array expression without using address-of") { test("can't do str or array expression without using address-of") {
val text = """ val text = """
%import textio
main { main {
sub start() { sub start() {
ubyte[] array = [1,2,3,4] ubyte[] array = [1,2,3,4]
str s1 = "test" str s1 = "test"
ubyte ff = 1 ubyte ff = 1
txt.print(s1+ff) print(s1+ff)
txt.print(array+ff) print(array+ff)
txt.print_uwhex(s1+ff, true) print_uwhex(s1+ff, true)
txt.print_uwhex(array+ff, true) print_uwhex(array+ff, true)
} }
sub print(str s) { cx16.r0++ }
sub print_uwhex(uword w, bool prefix) { cx16.r0++ }
} }
""" """
val errors = ErrorReporterForTests() val errors = ErrorReporterForTests()
@@ -83,21 +85,23 @@ class TestAstChecks: FunSpec({
test("str or array expression with address-of") { test("str or array expression with address-of") {
val text = """ val text = """
%import textio
main { main {
sub start() { sub start() {
ubyte[] array = [1,2,3,4] ubyte[] array = [1,2,3,4]
str s1 = "test" str s1 = "test"
bool bb1, bb2 bool bb1, bb2
ubyte ff = 1 ubyte ff = 1
txt.print(&s1+ff) print(&s1+ff)
txt.print(&array+ff) print(&array+ff)
txt.print_uwhex(&s1+ff, true) print_uwhex(&s1+ff, true)
txt.print_uwhex(&array+ff, true) print_uwhex(&array+ff, true)
; also good: ; also good:
bb1 = (s1 == "derp") bb1 = (s1 == "derp")
bb2 = (s1 != "derp") bb2 = (s1 != "derp")
} }
sub print(str s) { cx16.r0++ }
sub print_uwhex(uword w, bool prefix) { cx16.r0++ }
} }
""" """
compileText(C64Target(), false, text, outputDir, writeAssembly = false) shouldNotBe null compileText(C64Target(), false, text, outputDir, writeAssembly = false) shouldNotBe null

View File

@@ -407,7 +407,6 @@ main {
test("const evaluation of signed bitwise operations") { test("const evaluation of signed bitwise operations") {
val src=""" val src="""
%import textio
main { main {
sub start() { sub start() {
byte @shared a = -1 byte @shared a = -1
@@ -417,26 +416,16 @@ main {
const byte cb = -15 const byte cb = -15
const ubyte cub = 2 const ubyte cub = 2
txt.print_ub( a & b ) print_ub( a & b )
txt.spc() print_ub( a | b )
txt.print_ub( a | b ) print_ub( a ^ b )
txt.spc() print_b( a << ub )
txt.print_ub( a ^ b ) print_b( a >> ub )
txt.spc() print_ub( ca & cb )
txt.print_b( a << ub ) print_ub( ca | cb )
txt.spc() print_ub( ca ^ cb )
txt.print_b( a >> ub ) print_b( ca << cub )
txt.nl() print_b( ca >> cub )
txt.print_ub( ca & cb )
txt.spc()
txt.print_ub( ca | cb )
txt.spc()
txt.print_ub( ca ^ cb )
txt.spc()
txt.print_b( ca << cub )
txt.spc()
txt.print_b( ca >> cub )
txt.nl()
word @shared aw = -1 word @shared aw = -1
word @shared bw = -15 word @shared bw = -15
@@ -445,23 +434,21 @@ main {
const word cbw = -15 const word cbw = -15
const uword cuw = 2 const uword cuw = 2
txt.print_uw( aw & bw ) print_uw( aw & bw )
txt.spc() print_uw( aw | bw )
txt.print_uw( aw | bw ) print_uw( aw ^ bw )
txt.spc() print_uw( caw & cbw )
txt.print_uw( aw ^ bw ) print_uw( caw | cbw )
txt.nl() print_uw( caw ^ cbw )
txt.print_uw( caw & cbw ) print_w( cbw << cuw )
txt.spc() print_w( cbw >> cuw )
txt.print_uw( caw | cbw )
txt.spc()
txt.print_uw( caw ^ cbw )
txt.nl()
txt.print_w( cbw << cuw )
txt.spc()
txt.print_w( cbw >> cuw )
txt.nl()
} }
sub print_ub(ubyte v) {}
sub print_b(byte v) {}
sub print_uw(uword v) {}
sub print_w(word v) {}
}""" }"""
compileText(C64Target(), false, src, outputDir, writeAssembly = false) shouldNotBe null compileText(C64Target(), false, src, outputDir, writeAssembly = false) shouldNotBe null

View File

@@ -970,9 +970,6 @@ class TestProg8Parser: FunSpec( {
test("line comment in array literal is ok") { test("line comment in array literal is ok") {
val src=""" val src="""
%import textio
%zeropage basicsafe
main { main {
sub start() { sub start() {
byte[] foo = [ 1, 2, ; this comment is ok byte[] foo = [ 1, 2, ; this comment is ok
@@ -991,8 +988,6 @@ main {
test("various alternative curly brace styles are ok") { test("various alternative curly brace styles are ok") {
val src=""" val src="""
%zeropage dontuse
main { main {
; curly braces without newline ; curly braces without newline
sub start () { foo() derp() other() } sub start () { foo() derp() other() }

View File

@@ -118,10 +118,10 @@ class TestProgram: FunSpec({
} }
test("block sort order") { test("block sort order") {
val src=""" val src= """
%import textio %import textio
main ${'$'}0a00 { main $0a00 {
sub start() { sub start() {
otherblock1.foo() otherblock1.foo()
otherblock2.foo() otherblock2.foo()
@@ -132,16 +132,12 @@ otherblock1 {
sub foo() { sub foo() {
txt.print("main.start: ") txt.print("main.start: ")
txt.print_uwhex(&main.start, true) txt.print_uwhex(&main.start, true)
txt.nl()
txt.print("datablock1 array: ") txt.print("datablock1 array: ")
txt.print_uwhex(&datablock1.array1, true) txt.print_uwhex(&datablock1.array1, true)
txt.nl()
txt.print("datablock2 array: ") txt.print("datablock2 array: ")
txt.print_uwhex(&datablock2.array2, true) txt.print_uwhex(&datablock2.array2, true)
txt.nl()
txt.print("otherblock1.foo: ") txt.print("otherblock1.foo: ")
txt.print_uwhex(&foo, true) txt.print_uwhex(&foo, true)
txt.nl()
} }
} }
@@ -149,15 +145,14 @@ otherblock2 {
sub foo() { sub foo() {
txt.print("otherblock2.foo: ") txt.print("otherblock2.foo: ")
txt.print_uwhex(&otherblock2.foo, true) txt.print_uwhex(&otherblock2.foo, true)
txt.nl()
} }
} }
datablock1 ${'$'}9000 { datablock1 $9000 {
ubyte[5] @shared array1 = [1,2,3,4,5] ubyte[5] @shared array1 = [1,2,3,4,5]
} }
datablock2 ${'$'}8000 { datablock2 $8000 {
ubyte[5] @shared array2 = [1,2,3,4,5] ubyte[5] @shared array2 = [1,2,3,4,5]
} }
""" """

View File

@@ -413,8 +413,6 @@ main {
test("various array indexed assignment scenarios") { test("various array indexed assignment scenarios") {
val src=""" val src="""
%import floats %import floats
%import textio
%zeropage basicsafe
main { main {
bool[10] barray bool[10] barray
@@ -456,14 +454,10 @@ main {
dump() dump()
sub dump() { sub dump() {
txt.print_bool(barray[2]) bool @shared bb = barray[2]
txt.spc() uword @shared ww = warrayns[2]
txt.print_uw(warrayns[2]) uword @shared ww2 = warray[2]
txt.spc() float @shared ff = farray[2]
txt.print_uw(warray[2])
txt.spc()
txt.print_f(farray[2])
txt.nl()
} }
} }
}""" }"""

View File

@@ -197,8 +197,6 @@ main {
"identifiers can have the names of cpu instructions" { "identifiers can have the names of cpu instructions" {
val text=""" val text="""
%import textio
nop { nop {
sub lda(ubyte sec) -> ubyte { sub lda(ubyte sec) -> ubyte {
asl: asl:
@@ -223,13 +221,15 @@ main {
sub start() { sub start() {
ubyte col = 10 ubyte col = 10
ubyte row = 20 ubyte row = 20
txt.print_ub(nop.lda(42)) print_ub(nop.lda(42))
txt.nl() print_uw(nop.lda.asl)
txt.print_uw(nop.lda.asl)
void ffalse(99) void ffalse(99)
void ftrue(99) void ftrue(99)
} }
sub print_ub(ubyte v) {}
sub print_uw(uword v) {}
} }
""" """
val result = compileText(C64Target(), false, text, outputDir, writeAssembly = true) val result = compileText(C64Target(), false, text, outputDir, writeAssembly = true)

View File

@@ -19,14 +19,11 @@ class TestLibrary: FunSpec({
val outputDir = tempdir().toPath() val outputDir = tempdir().toPath()
test("library compilation (x16)") { test("library compilation (x16)") {
val src=""" val src= $$"""
%address ${'$'}A050 %address $A050
%memtop ${'$'}C000 %memtop $C000
%output library %output library
%import textio
main { main {
; Create a jump table as first thing in the library. ; Create a jump table as first thing in the library.
uword[] @shared @nosplit jumptable = [ uword[] @shared @nosplit jumptable = [
@@ -105,23 +102,20 @@ library {
} }
test("library compilation (c64)") { test("library compilation (c64)") {
val src=""" val src= $$"""
%address ${'$'}8050 %address $8050
%memtop ${'$'}a000 %memtop $a000
%output library %output library
%import textio
main { main {
; Create a jump table as first thing in the library. ; Create a jump table as first thing in the library.
uword[] @shared @nosplit jumptable = [ uword[] @shared @nosplit jumptable = [
; NOTE: the compiler has inserted a single JMP instruction at the start of the 'main' block, that jumps to the start() routine. ; NOTE: the compiler has inserted a single JMP instruction at the start of the 'main' block, that jumps to the start() routine.
; This is convenient because the rest of the jump table simply follows it, ; This is convenient because the rest of the jump table simply follows it,
; making the first jump neatly be the required initialization routine for the library (initializing variables and BSS region). ; making the first jump neatly be the required initialization routine for the library (initializing variables and BSS region).
; btw, ${'$'}4c = opcode for JMP. ; btw, $4c = opcode for JMP.
${'$'}4c00, &library.func1, $4c00, &library.func1,
${'$'}4c00, &library.func2, $4c00, &library.func2,
] ]
sub start() { sub start() {

View File

@@ -4,4 +4,4 @@ org.gradle.parallel=true
org.gradle.daemon=true org.gradle.daemon=true
org.gradle.configuration-cache=false org.gradle.configuration-cache=false
kotlin.code.style=official kotlin.code.style=official
version=12.0-BETA4 version=12.0-SNAPSHOT