mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
simplified CompilationResult a bit
This commit is contained in:
parent
2b6f5dbd59
commit
db7ae028b2
@ -81,10 +81,10 @@ private fun compileMain(args: Array<String>): Boolean {
|
||||
if(watchMode==true) {
|
||||
val watchservice = FileSystems.getDefault().newWatchService()
|
||||
val allImportedFiles = mutableSetOf<Path>()
|
||||
|
||||
val results = mutableListOf<CompilationResult>()
|
||||
while(true) {
|
||||
println("Continuous watch mode active. Modules: $moduleFiles")
|
||||
val results = mutableListOf<CompilationResult>()
|
||||
results.clear()
|
||||
for(filepathRaw in moduleFiles) {
|
||||
val filepath = pathFrom(filepathRaw).normalize()
|
||||
val compilerArgs = CompilerArguments(
|
||||
@ -102,7 +102,8 @@ private fun compileMain(args: Array<String>): Boolean {
|
||||
outputPath
|
||||
)
|
||||
val compilationResult = compileProgram(compilerArgs)
|
||||
results.add(compilationResult)
|
||||
if(compilationResult!=null)
|
||||
results.add(compilationResult)
|
||||
}
|
||||
|
||||
val allNewlyImportedFiles = results.flatMap { it.importedFiles }
|
||||
@ -152,21 +153,23 @@ private fun compileMain(args: Array<String>): Boolean {
|
||||
srcdirs,
|
||||
outputPath
|
||||
)
|
||||
compilationResult = compileProgram(compilerArgs)
|
||||
if (!compilationResult.success)
|
||||
val result = compileProgram(compilerArgs)
|
||||
if(result==null)
|
||||
return false
|
||||
else
|
||||
compilationResult = result
|
||||
} catch (x: AstException) {
|
||||
return false
|
||||
}
|
||||
|
||||
if(startEmulator1==true || startEmulator2==true) {
|
||||
if (compilationResult.programName.isEmpty()) {
|
||||
if (compilationResult.program.name.isEmpty()) {
|
||||
println("\nCan't start emulator because no program was assembled.")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
val programNameInPath = outputPath.resolve(compilationResult.programName)
|
||||
val programNameInPath = outputPath.resolve(compilationResult.program.name)
|
||||
|
||||
if(startEmulator1==true || startEmulator2==true) {
|
||||
if (compilationResult.compilationOptions.launcher != CbmPrgLauncherType.NONE || compilationTarget=="atari") {
|
||||
|
@ -27,9 +27,7 @@ import kotlin.math.round
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
|
||||
class CompilationResult(val success: Boolean,
|
||||
val program: Program,
|
||||
val programName: String,
|
||||
class CompilationResult(val program: Program,
|
||||
val compilationOptions: CompilationOptions,
|
||||
val importedFiles: List<Path>)
|
||||
|
||||
@ -48,7 +46,7 @@ class CompilerArguments(val filepath: Path,
|
||||
val errors: IErrorReporter = ErrorReporter())
|
||||
|
||||
|
||||
fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
fun compileProgram(args: CompilerArguments): CompilationResult? {
|
||||
var programName = ""
|
||||
lateinit var program: Program
|
||||
lateinit var importedFiles: List<Path>
|
||||
@ -104,12 +102,15 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
// println("*********** AST BEFORE ASSEMBLYGEN *************")
|
||||
// printProgram(program)
|
||||
|
||||
println("***program.name = ${program.name}")
|
||||
println("***programName = $programName")
|
||||
|
||||
if (args.writeAssembly) {
|
||||
when (val result = writeAssembly(program, args.errors, compilationOptions)) {
|
||||
is WriteAssemblyResult.Ok -> programName = result.filename
|
||||
is WriteAssemblyResult.Fail -> {
|
||||
System.err.println(result.error)
|
||||
return CompilationResult(false, program, programName, compilationOptions, importedFiles)
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,7 +119,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
System.err.flush()
|
||||
val seconds = totalTime/1000.0
|
||||
println("\nTotal compilation+assemble time: ${round(seconds*100.0)/100.0} sec.")
|
||||
return CompilationResult(true, program, programName, compilationOptions, importedFiles)
|
||||
return CompilationResult(program, compilationOptions, importedFiles)
|
||||
} catch (px: ParseError) {
|
||||
System.err.print("\n\u001b[91m") // bright red
|
||||
System.err.println("${px.position.toClickableStr()} parse error: ${px.message}".trim())
|
||||
@ -151,14 +152,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult {
|
||||
throw x
|
||||
}
|
||||
|
||||
val failedProgram = Program("failed", BuiltinFunctionsFacade(BuiltinFunctions), compTarget, compTarget)
|
||||
val dummyoptions = CompilationOptions(
|
||||
OutputType.RAW, CbmPrgLauncherType.NONE, ZeropageType.DONTUSE, emptyList(),
|
||||
floats = false,
|
||||
noSysInit = true,
|
||||
compTarget = compTarget
|
||||
)
|
||||
return CompilationResult(false, failedProgram, programName, dummyoptions, emptyList())
|
||||
return null
|
||||
}
|
||||
|
||||
private class BuiltinFunctionsFacade(functions: Map<String, FSignature>): IBuiltinFunctions {
|
||||
|
@ -2,11 +2,10 @@ package prog8tests
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -25,7 +24,7 @@ class TestAstChecks: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
|
||||
compileText(C64Target(), true, text, writeAssembly = true, errors=errors).assertSuccess()
|
||||
compileText(C64Target(), true, text, writeAssembly = true, errors=errors) shouldNotBe null
|
||||
errors.errors.size shouldBe 0
|
||||
errors.warnings.size shouldBe 2
|
||||
errors.warnings[0] shouldContain "converted to float"
|
||||
@ -50,7 +49,7 @@ class TestAstChecks: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), true, text, writeAssembly = true, errors=errors).assertFailure()
|
||||
compileText(C64Target(), true, text, writeAssembly = true, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.warnings.size shouldBe 0
|
||||
errors.errors[0] shouldContain ":7:28: assignment value is invalid"
|
||||
@ -73,7 +72,7 @@ class TestAstChecks: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.filter { it.contains("missing &") }.size shouldBe 4
|
||||
}
|
||||
|
||||
@ -95,6 +94,6 @@ class TestAstChecks: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -26,7 +26,7 @@ class TestCallgraph: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), false, sourcecode)!!
|
||||
val graph = CallGraph(result.program)
|
||||
|
||||
graph.imports.size shouldBe 1
|
||||
@ -67,7 +67,7 @@ class TestCallgraph: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), false, sourcecode)!!
|
||||
val graph = CallGraph(result.program)
|
||||
|
||||
graph.imports.size shouldBe 1
|
||||
@ -110,7 +110,7 @@ class TestCallgraph: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), false, sourcecode)!!
|
||||
val graph = CallGraph(result.program)
|
||||
graph.allIdentifiers.size shouldBeGreaterThanOrEqual 9
|
||||
val empties = graph.allIdentifiers.keys.filter { it.nameInSource==listOf("empty") }
|
||||
|
@ -12,7 +12,6 @@ import prog8.ast.expressions.IdentifierReference
|
||||
import prog8.ast.expressions.NumericLiteral
|
||||
import prog8.codegen.target.Cx16Target
|
||||
import prog8.compilerinterface.Encoding
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -32,7 +31,7 @@ class TestCompilerOnCharLit: FunSpec({
|
||||
chrout('\n')
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -56,7 +55,7 @@ class TestCompilerOnCharLit: FunSpec({
|
||||
chrout(ch)
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -91,7 +90,7 @@ class TestCompilerOnCharLit: FunSpec({
|
||||
chrout(ch)
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
|
@ -1,13 +1,17 @@
|
||||
package prog8tests
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8.codegen.target.Cx16Target
|
||||
import prog8.compiler.CompilationResult
|
||||
import prog8.compiler.CompilerArguments
|
||||
import prog8.compiler.compileProgram
|
||||
import prog8.compilerinterface.ICompilationTarget
|
||||
import prog8tests.helpers.*
|
||||
import prog8tests.helpers.assumeDirectory
|
||||
import prog8tests.helpers.cartesianProduct
|
||||
import prog8tests.helpers.outputDir
|
||||
import prog8tests.helpers.workingDir
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.absolute
|
||||
import kotlin.io.path.exists
|
||||
@ -21,7 +25,7 @@ import kotlin.io.path.exists
|
||||
|
||||
private val examplesDir = assumeDirectory(workingDir, "../examples")
|
||||
|
||||
private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilationTarget): CompilationResult {
|
||||
private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilationTarget): CompilationResult? {
|
||||
val args = CompilerArguments(
|
||||
filepath,
|
||||
optimize,
|
||||
@ -75,7 +79,7 @@ class TestCompilerOnExamplesC64: FunSpec({
|
||||
val target = C64Target()
|
||||
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
|
||||
test(displayName) {
|
||||
compileTheThing(filepath, optimize, target).assertSuccess()
|
||||
compileTheThing(filepath, optimize, target) shouldNotBe null
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -107,7 +111,7 @@ class TestCompilerOnExamplesCx16: FunSpec({
|
||||
val target = Cx16Target()
|
||||
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
|
||||
test(displayName) {
|
||||
compileTheThing(filepath, optimize, target).assertSuccess()
|
||||
compileTheThing(filepath, optimize, target) shouldNotBe null
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -148,10 +152,10 @@ class TestCompilerOnExamplesBothC64andCx16: FunSpec({
|
||||
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, c64target)
|
||||
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, cx16target)
|
||||
test(displayNameC64) {
|
||||
compileTheThing(filepathC64, optimize, c64target).assertSuccess()
|
||||
compileTheThing(filepathC64, optimize, c64target) shouldNotBe null
|
||||
}
|
||||
test(displayNameCx16) {
|
||||
compileTheThing(filepathCx16, optimize, cx16target).assertSuccess()
|
||||
compileTheThing(filepathCx16, optimize, cx16target) shouldNotBe null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -28,8 +28,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
|
||||
assumeReadableFile(fixturesDir, "foo_bar.p8")
|
||||
|
||||
val platform = Cx16Target()
|
||||
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)
|
||||
.assertSuccess()
|
||||
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -51,8 +50,7 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
|
||||
assumeReadableFile(fixturesDir, "foo_bar.asm")
|
||||
|
||||
val platform = Cx16Target()
|
||||
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)
|
||||
.assertSuccess()
|
||||
val result = compileFile(platform, optimize = false, fixturesDir, filepath.name)!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -76,16 +74,14 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
|
||||
val p8Path = assumeReadableFile(fixturesDir, "asmBinaryNonExisting.p8")
|
||||
assumeNotExists(fixturesDir, "i_do_not_exist.bin")
|
||||
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
|
||||
.assertFailure()
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir) shouldBe null
|
||||
}
|
||||
|
||||
test("testAsmbinaryDirectiveWithNonReadableFile") {
|
||||
val p8Path = assumeReadableFile(fixturesDir, "asmBinaryNonReadable.p8")
|
||||
assumeDirectory(fixturesDir, "subFolder")
|
||||
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
|
||||
.assertFailure()
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir) shouldBe null
|
||||
}
|
||||
|
||||
val tests = listOf(
|
||||
@ -104,12 +100,11 @@ class TestCompilerOnImportsAndIncludes: FunSpec({
|
||||
outputDir.normalize().toAbsolutePath() shouldNotBe workingDir.normalize().toAbsolutePath()
|
||||
}
|
||||
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir)
|
||||
.assertSuccess(
|
||||
"argument to assembler directive .binary " +
|
||||
"should be relative to the generated .asm file (in output dir), " +
|
||||
"NOT relative to .p8 neither current working dir"
|
||||
)
|
||||
withClue("argument to assembler directive .binary " +
|
||||
"should be relative to the generated .asm file (in output dir), " +
|
||||
"NOT relative to .p8 neither current working dir") {
|
||||
compileFile(Cx16Target(), false, p8Path.parent, p8Path.name, outputDir) shouldNotBe null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package prog8tests
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import io.kotest.matchers.types.instanceOf
|
||||
import prog8.ast.base.DataType
|
||||
@ -35,7 +36,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
cs[0] = 23 ; keep optimizer from removing it
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -67,7 +68,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
cs[0] = 23 ; keep optimizer from removing it
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -119,9 +120,9 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
""")
|
||||
if (optEnableFloats != "" && (sizeInDecl=="" || sizeInDecl=="42"))
|
||||
result.assertSuccess()
|
||||
result shouldNotBe null
|
||||
else
|
||||
result.assertFailure()
|
||||
result shouldBe null
|
||||
|
||||
}
|
||||
}
|
||||
@ -138,7 +139,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -172,7 +173,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -198,7 +199,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -224,7 +225,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""", errors, false).assertFailure()
|
||||
""", errors, false) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain ".p8:5:30: range expression from value must be integer"
|
||||
errors.errors[1] shouldContain ".p8:5:45: range expression to value must be integer"
|
||||
@ -240,7 +241,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
|
||||
val program = result.program
|
||||
val startSub = program.entrypoint
|
||||
@ -272,7 +273,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
val statements = result.program.entrypoint.statements
|
||||
val array = (statements[0] as VarDecl).value
|
||||
array shouldBe instanceOf<ArrayLiteral>()
|
||||
@ -293,7 +294,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
}
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
val statements = result.program.entrypoint.statements
|
||||
val forloop = (statements.dropLast(1).last() as ForLoop)
|
||||
forloop.iterable shouldBe instanceOf<RangeExpression>()
|
||||
@ -339,7 +340,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
xx++
|
||||
}
|
||||
}
|
||||
}""", writeAssembly = true).assertSuccess()
|
||||
}""", writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("if containment check on all possible iterable expressions") {
|
||||
@ -400,7 +401,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
xx++
|
||||
}
|
||||
}
|
||||
}""", writeAssembly = true).assertSuccess()
|
||||
}""", writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("containment check in expressions") {
|
||||
@ -426,6 +427,6 @@ class TestCompilerOnRanges: FunSpec({
|
||||
xx = ww in [9000,8000,7000]
|
||||
xx = ww in wvalues
|
||||
}
|
||||
}""", writeAssembly = true).assertSuccess()
|
||||
}""", writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package prog8tests
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import prog8.codegen.target.Cx16Target
|
||||
import prog8.compiler.CompilationResult
|
||||
import prog8.compiler.CompilerArguments
|
||||
@ -35,7 +36,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
|
||||
tempFileInWorkingDir.deleteExisting()
|
||||
}
|
||||
|
||||
fun compileFile(filePath: Path, sourceDirs: List<String>): CompilationResult {
|
||||
fun compileFile(filePath: Path, sourceDirs: List<String>): CompilationResult? {
|
||||
val args = CompilerArguments(
|
||||
filepath = filePath,
|
||||
optimize = false,
|
||||
@ -55,39 +56,33 @@ class TestCompilerOptionSourcedirs: FunSpec({
|
||||
|
||||
test("testAbsoluteFilePathInWorkingDir") {
|
||||
val filepath = assumeReadableFile(tempFileInWorkingDir.absolute())
|
||||
compileFile(filepath, listOf())
|
||||
.assertSuccess()
|
||||
compileFile(filepath, listOf()) shouldNotBe null
|
||||
}
|
||||
|
||||
test("testFilePathInWorkingDirRelativeToWorkingDir") {
|
||||
val filepath = assumeReadableFile(workingDir.relativize(tempFileInWorkingDir.absolute()))
|
||||
compileFile(filepath, listOf())
|
||||
.assertSuccess()
|
||||
compileFile(filepath, listOf()) shouldNotBe null
|
||||
}
|
||||
|
||||
test("testFilePathInWorkingDirRelativeTo1stInSourcedirs") {
|
||||
val filepath = assumeReadableFile(tempFileInWorkingDir)
|
||||
compileFile(filepath.fileName, listOf(workingDir.toString()))
|
||||
.assertSuccess()
|
||||
compileFile(filepath.fileName, listOf(workingDir.toString())) shouldNotBe null
|
||||
}
|
||||
|
||||
test("testAbsoluteFilePathOutsideWorkingDir") {
|
||||
val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8")
|
||||
compileFile(filepath.absolute(), listOf())
|
||||
.assertSuccess()
|
||||
compileFile(filepath.absolute(), listOf()) shouldNotBe null
|
||||
}
|
||||
|
||||
test("testFilePathOutsideWorkingDirRelativeToWorkingDir") {
|
||||
val filepath = workingDir.relativize(assumeReadableFile(fixturesDir, "ast_simple_main.p8").absolute())
|
||||
compileFile(filepath, listOf())
|
||||
.assertSuccess()
|
||||
compileFile(filepath, listOf()) shouldNotBe null
|
||||
}
|
||||
|
||||
test("testFilePathOutsideWorkingDirRelativeTo1stInSourcedirs") {
|
||||
val filepath = assumeReadableFile(fixturesDir, "ast_simple_main.p8")
|
||||
val sourcedirs = listOf("$fixturesDir")
|
||||
compileFile(filepath.fileName, sourcedirs)
|
||||
.assertSuccess()
|
||||
compileFile(filepath.fileName, sourcedirs) shouldNotBe null
|
||||
}
|
||||
|
||||
})
|
||||
|
@ -10,7 +10,6 @@ import prog8.compiler.determineCompilationOptions
|
||||
import prog8.compiler.parseImports
|
||||
import prog8.compilerinterface.ZeropageType
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
import prog8tests.helpers.outputDir
|
||||
|
||||
@ -27,7 +26,7 @@ main {
|
||||
; nothing
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
result.program.toplevelModule.name shouldStartWith "on_the_fly_test"
|
||||
|
||||
val moduleNames = result.program.modules.map { it.name }
|
||||
@ -60,7 +59,7 @@ main {
|
||||
; nothing
|
||||
}
|
||||
}
|
||||
""").assertSuccess()
|
||||
""")!!
|
||||
result.program.toplevelModule.name shouldStartWith "on_the_fly_test"
|
||||
val options = determineCompilationOptions(result.program, C64Target())
|
||||
options.floats shouldBe true
|
||||
|
@ -2,6 +2,7 @@ package prog8tests
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import prog8.ast.Module
|
||||
import prog8.ast.Program
|
||||
import prog8.ast.base.DataType
|
||||
@ -229,7 +230,7 @@ class TestMemory: FunSpec({
|
||||
uword @shared mem = memory("a b c", 100, $100)
|
||||
}
|
||||
}
|
||||
""", writeAssembly = true).assertSuccess()
|
||||
""", writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("memory() with invalid argument") {
|
||||
@ -239,6 +240,6 @@ class TestMemory: FunSpec({
|
||||
uword @shared mem1 = memory("abc", 100, -2)
|
||||
}
|
||||
}
|
||||
""", writeAssembly = true).assertFailure()
|
||||
""", writeAssembly = true) shouldBe null
|
||||
}
|
||||
})
|
||||
|
@ -4,14 +4,13 @@ import io.kotest.assertions.throwables.shouldThrow
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.doubles.plusOrMinus
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import prog8.ast.toHex
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8.codegen.target.cbm.Mflpt5
|
||||
import prog8.compilerinterface.InternalCompilerException
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -126,7 +125,7 @@ class TestNumbers: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests(keepMessagesAfterReporting = true)
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertSuccess()
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors) shouldNotBe null
|
||||
errors.errors.size shouldBe 0
|
||||
errors.warnings.size shouldBe 2
|
||||
errors.warnings[0] shouldContain "converted to float"
|
||||
@ -146,7 +145,7 @@ class TestNumbers: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.warnings.size shouldBe 0
|
||||
errors.errors[0] shouldContain "converted to float"
|
||||
@ -163,7 +162,7 @@ class TestNumbers: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), true, src, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.warnings.size shouldBe 0
|
||||
errors.errors[0] shouldContain "out of range"
|
||||
@ -179,6 +178,6 @@ class TestNumbers: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), true, src, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), true, src, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -35,7 +35,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), true, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), true, sourcecode)!!
|
||||
val toplevelModule = result.program.toplevelModule
|
||||
val mainBlock = toplevelModule.statements.single() as Block
|
||||
val startSub = mainBlock.statements.single() as Subroutine
|
||||
@ -60,7 +60,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), true, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), true, sourcecode)!!
|
||||
val toplevelModule = result.program.toplevelModule
|
||||
val mainBlock = toplevelModule.statements.single() as Block
|
||||
val startSub = mainBlock.statements[0] as Subroutine
|
||||
@ -119,7 +119,7 @@ class TestOptimization: FunSpec({
|
||||
cx16.r7s = llw - 900 + 999
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), true, source, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), true, source, writeAssembly = false)!!
|
||||
// expected:
|
||||
// uword load_location
|
||||
// load_location = 12345
|
||||
@ -172,7 +172,7 @@ class TestOptimization: FunSpec({
|
||||
cx16.r4s = llw * 90 / 5 ; not optimized because of loss of integer division precision
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), true, source, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), true, source, writeAssembly = false)!!
|
||||
printProgram(result.program)
|
||||
// expected:
|
||||
// word llw
|
||||
@ -229,7 +229,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, sourcecode).assertSuccess()
|
||||
val result = compileText(C64Target(), false, sourcecode)!!
|
||||
val mainsub = result.program.entrypoint
|
||||
mainsub.statements.size shouldBe 10
|
||||
val declTest = mainsub.statements[0] as VarDecl
|
||||
@ -267,7 +267,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false)!!
|
||||
|
||||
// ww = ((( not bb as uword) or not ww) as uword)
|
||||
val wwAssign = result.program.entrypoint.statements.last() as Assignment
|
||||
@ -288,7 +288,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false)!!
|
||||
|
||||
// bb = (( not bb as uword) or not ww)
|
||||
val bbAssign = result.program.entrypoint.statements.last() as Assignment
|
||||
@ -340,7 +340,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), true, src, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), true, src, writeAssembly = true)!!
|
||||
/* turned into:
|
||||
ubyte r
|
||||
r = 0
|
||||
@ -376,7 +376,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=false, src, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=false, src, writeAssembly = false)!!
|
||||
val assignFF = result.program.entrypoint.statements.last() as Assignment
|
||||
assignFF.isAugmentable shouldBe true
|
||||
assignFF.target.identifier!!.nameInSource shouldBe listOf("ff")
|
||||
@ -385,7 +385,7 @@ class TestOptimization: FunSpec({
|
||||
(value.left as? IdentifierReference)?.nameInSource shouldBe listOf("ff")
|
||||
value.right shouldBe instanceOf<TypecastExpression>()
|
||||
|
||||
compileText(C64Target(), optimize=false, src, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), optimize=false, src, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("unused variable removal") {
|
||||
@ -402,7 +402,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
result.program.entrypoint.statements.size shouldBe 7
|
||||
val alldecls = result.program.entrypoint.allDefinedSymbols.toList()
|
||||
alldecls.map { it.first } shouldBe listOf("unused_but_shared", "usedvar_only_written", "usedvar")
|
||||
@ -425,7 +425,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
printProgram(result.program)
|
||||
result.program.entrypoint.statements.size shouldBe 3
|
||||
val ifstmt = result.program.entrypoint.statements[0] as IfElse
|
||||
@ -454,7 +454,7 @@ class TestOptimization: FunSpec({
|
||||
z6 = z1+z6-5
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
/* expected:
|
||||
ubyte z1
|
||||
z1 = 10
|
||||
@ -521,7 +521,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 6
|
||||
val assign=stmts.last() as Assignment
|
||||
@ -538,7 +538,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 6
|
||||
val assign=stmts.last() as Assignment
|
||||
@ -557,7 +557,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 10
|
||||
stmts.filterIsInstance<VarDecl>().size shouldBe 5
|
||||
@ -573,7 +573,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), optimize=true, src, writeAssembly=false, errors = errors).assertFailure()
|
||||
compileText(C64Target(), optimize=true, src, writeAssembly=false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "type of value BYTE doesn't match target UBYTE"
|
||||
errors.errors[1] shouldContain "out of range"
|
||||
@ -592,7 +592,7 @@ class TestOptimization: FunSpec({
|
||||
q=r
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize=false, src, writeAssembly=true).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=false, src, writeAssembly=true)!!
|
||||
result.program.entrypoint.statements.size shouldBe 11
|
||||
result.program.entrypoint.statements.last() shouldBe instanceOf<Return>()
|
||||
}
|
||||
@ -610,7 +610,7 @@ class TestOptimization: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
printProgram(result.program)
|
||||
/* expected result:
|
||||
uword yy
|
||||
@ -640,7 +640,7 @@ class TestOptimization: FunSpec({
|
||||
xx = xx+10 ; so this should not be changed into xx=10
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize=true, src, writeAssembly=false)!!
|
||||
/*
|
||||
expected result:
|
||||
uword xx
|
||||
|
@ -147,7 +147,7 @@ class TestPipes: FunSpec({
|
||||
return ww+2222
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize = false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize = false, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 7
|
||||
val pipef = stmts[0] as Pipe
|
||||
@ -203,7 +203,7 @@ class TestPipes: FunSpec({
|
||||
return ww+2222
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize = true, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize = true, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 7
|
||||
val pipef = stmts[0] as Pipe
|
||||
@ -249,7 +249,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "incompatible"
|
||||
}
|
||||
@ -281,7 +281,7 @@ class TestPipes: FunSpec({
|
||||
return ww+2222
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), optimize = false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize = false, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 8
|
||||
val assignf = stmts[1] as Assignment
|
||||
@ -348,7 +348,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), optimize = true, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), optimize = true, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 8
|
||||
val assignf = stmts[1] as Assignment
|
||||
@ -397,7 +397,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "incompatible"
|
||||
}
|
||||
@ -415,7 +415,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), true, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
stmts.size shouldBe 7
|
||||
val pipeww = stmts[4] as Pipe
|
||||
@ -442,7 +442,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), optimize = false, text, writeAssembly = true, errors=errors).assertFailure()
|
||||
compileText(C64Target(), optimize = false, text, writeAssembly = true, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "UWORD incompatible"
|
||||
errors.errors[1] shouldContain "UWORD incompatible"
|
||||
@ -466,7 +466,7 @@ class TestPipes: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), optimize = false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), optimize = false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 3
|
||||
errors.errors[0] shouldContain ":4:32: invalid number of arguments"
|
||||
errors.errors[1] shouldContain ":7:44: invalid number of arguments"
|
||||
|
@ -3,6 +3,7 @@ package prog8tests
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import io.kotest.matchers.types.instanceOf
|
||||
import io.kotest.matchers.types.shouldBeSameInstanceAs
|
||||
@ -12,8 +13,6 @@ import prog8.ast.expressions.NumericLiteral
|
||||
import prog8.ast.statements.*
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -27,7 +26,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false)!!
|
||||
val module = result.program.toplevelModule
|
||||
module.parent shouldBe instanceOf<GlobalNamespace>()
|
||||
module.program shouldBeSameInstanceAs result.program
|
||||
@ -46,7 +45,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = false)!!
|
||||
val module = result.program.toplevelModule
|
||||
val mainBlock = module.statements.single() as Block
|
||||
val start = mainBlock.statements.single() as Subroutine
|
||||
@ -120,7 +119,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, src, writeAssembly = true)!!
|
||||
val module = result.program.toplevelModule
|
||||
val mainBlock = module.statements.single() as Block
|
||||
val start = mainBlock.statements.single() as Subroutine
|
||||
@ -145,7 +144,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
|
||||
test("wrong subroutine call without qualified names") {
|
||||
@ -161,7 +160,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors= ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "undefined symbol: routine2"
|
||||
}
|
||||
@ -181,7 +180,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
|
||||
test("wrong subroutine calls with qualified names (not from root)") {
|
||||
@ -200,7 +199,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors= ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 4
|
||||
errors.errors[0] shouldContain "undefined symbol: start.routine2"
|
||||
errors.errors[1] shouldContain "undefined symbol: wrong.start.routine2"
|
||||
@ -232,7 +231,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
|
||||
test("wrong variables without qualified names") {
|
||||
@ -264,7 +263,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors= ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 5
|
||||
errors.errors[0] shouldContain "undefined symbol: v3"
|
||||
errors.errors[1] shouldContain "undefined symbol: v4"
|
||||
@ -297,7 +296,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
|
||||
test("wrong variable refs with qualified names 1 (not from root)") {
|
||||
@ -324,7 +323,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors= ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 5
|
||||
errors.errors[0] shouldContain "undefined symbol: routine.value"
|
||||
errors.errors[1] shouldContain "undefined symbol: routine.arg"
|
||||
@ -362,7 +361,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
|
||||
test("various wrong goto targets") {
|
||||
@ -380,7 +379,7 @@ class TestScoping: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "wrong address"
|
||||
errors.errors[1] shouldContain "takes parameters"
|
||||
|
@ -6,6 +6,8 @@ import com.github.michaelbull.result.getOrElse
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNot
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8.codegen.target.Cx16Target
|
||||
@ -13,8 +15,6 @@ import prog8.codegen.target.cbm.AtasciiEncoding
|
||||
import prog8.codegen.target.cbm.IsoEncoding
|
||||
import prog8.codegen.target.cbm.PetsciiEncoding
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -221,7 +221,7 @@ class TestStringEncodings: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, source, errors, false).assertFailure()
|
||||
compileText(C64Target(), false, source, errors, false) shouldBe null
|
||||
errors.errors.size shouldBe 0
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ class TestStringEncodings: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, source, errors, writeAssembly = false).assertFailure()
|
||||
compileText(C64Target(), false, source, errors, writeAssembly = false) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "text encoding"
|
||||
}
|
||||
@ -252,7 +252,7 @@ class TestStringEncodings: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, source, errors, writeAssembly = false).assertFailure()
|
||||
compileText(C64Target(), false, source, errors, writeAssembly = false) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "text encoding"
|
||||
}
|
||||
@ -273,6 +273,6 @@ class TestStringEncodings: FunSpec({
|
||||
sub start() {
|
||||
}
|
||||
}"""
|
||||
compileText(Cx16Target(), false, source, writeAssembly = false).assertSuccess()
|
||||
compileText(Cx16Target(), false, source, writeAssembly = false) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -14,8 +14,6 @@ import prog8.ast.expressions.NumericLiteral
|
||||
import prog8.ast.statements.*
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -44,7 +42,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
|
||||
val module = result.program.toplevelModule
|
||||
val mainBlock = module.statements.single() as Block
|
||||
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
|
||||
@ -100,7 +98,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
val module = result.program.toplevelModule
|
||||
val mainBlock = module.statements.single() as Block
|
||||
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
|
||||
@ -162,7 +160,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
|
||||
val module = result.program.toplevelModule
|
||||
val mainBlock = module.statements.single() as Block
|
||||
val asmfunc = mainBlock.statements.filterIsInstance<Subroutine>().single { it.name=="asmfunc"}
|
||||
@ -188,7 +186,7 @@ class TestSubroutines: FunSpec({
|
||||
"""
|
||||
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "pass-by-reference type can't be used"
|
||||
errors.errors[1] shouldContain "pass-by-reference type can't be used"
|
||||
@ -212,7 +210,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
val module = result.program.toplevelModule
|
||||
val block = module.statements.single() as Block
|
||||
val thing = block.statements.filterIsInstance<Subroutine>().single {it.name=="thing"}
|
||||
@ -253,7 +251,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
"""
|
||||
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
val module = result.program.toplevelModule
|
||||
val block = module.statements.single() as Block
|
||||
val thing = block.statements.filterIsInstance<Subroutine>().single {it.name=="thing"}
|
||||
@ -284,7 +282,7 @@ class TestSubroutines: FunSpec({
|
||||
"""
|
||||
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "7:25: invalid number of arguments"
|
||||
errors.errors[1] shouldContain "9:25: invalid number of arguments"
|
||||
@ -305,7 +303,7 @@ class TestSubroutines: FunSpec({
|
||||
"""
|
||||
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "7:25: invalid number of arguments"
|
||||
errors.errors[1] shouldContain "9:25: invalid number of arguments"
|
||||
@ -325,7 +323,7 @@ class TestSubroutines: FunSpec({
|
||||
"""
|
||||
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "cannot use arguments"
|
||||
errors.errors[1] shouldContain "invalid number of arguments"
|
||||
@ -343,7 +341,7 @@ class TestSubroutines: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
val stmts = result.program.entrypoint.statements
|
||||
|
||||
stmts.last() shouldBe instanceOf<Subroutine>()
|
||||
|
@ -2,12 +2,11 @@ package prog8tests
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import io.kotest.matchers.string.shouldContain
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8.compiler.printProgram
|
||||
import prog8tests.helpers.ErrorReporterForTests
|
||||
import prog8tests.helpers.assertFailure
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -32,7 +31,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
result.program.entrypoint.statements.size shouldBe 13
|
||||
}
|
||||
|
||||
@ -54,7 +53,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = true, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = true, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "can't cast"
|
||||
errors.errors[1] shouldContain "can't cast"
|
||||
@ -70,7 +69,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "can't cast"
|
||||
errors.errors[1] shouldContain "can't cast"
|
||||
@ -87,7 +86,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 1
|
||||
errors.errors[0] shouldContain "in-place makes no sense"
|
||||
}
|
||||
@ -103,7 +102,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, errors=errors).assertFailure()
|
||||
compileText(C64Target(), false, text, errors=errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "can't cast"
|
||||
errors.errors[1] shouldContain "can't cast"
|
||||
@ -152,7 +151,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
printProgram(result.program)
|
||||
val statements = result.program.entrypoint.statements
|
||||
statements.size shouldBe 27
|
||||
@ -180,7 +179,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}
|
||||
}"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = true)!!
|
||||
val statements = result.program.entrypoint.statements
|
||||
statements.size shouldBe 14
|
||||
}
|
||||
@ -197,7 +196,7 @@ class TestTypecasts: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("(u)byte extend to word parameters") {
|
||||
@ -226,7 +225,7 @@ class TestTypecasts: FunSpec({
|
||||
}}
|
||||
}
|
||||
}"""
|
||||
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), true, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("lsb msb used as args with word types") {
|
||||
@ -245,6 +244,6 @@ class TestTypecasts: FunSpec({
|
||||
}}
|
||||
}
|
||||
}"""
|
||||
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), true, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -859,7 +859,7 @@ class TestProg8Parser: FunSpec( {
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
|
||||
val start = result.program.entrypoint
|
||||
val string = (start.statements[0] as VarDecl).value as StringLiteral
|
||||
withClue("x-escapes are hacked to range 0x8000-0x80ff") {
|
||||
@ -895,7 +895,7 @@ class TestProg8Parser: FunSpec( {
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
|
||||
val start = result.program.entrypoint
|
||||
val containmentChecks = start.statements.takeLast(4)
|
||||
(containmentChecks[0] as IfElse).condition shouldBe instanceOf<ContainmentCheck>()
|
||||
@ -916,7 +916,7 @@ class TestProg8Parser: FunSpec( {
|
||||
}
|
||||
"""
|
||||
val errors = ErrorReporterForTests()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors).assertFailure()
|
||||
compileText(C64Target(), false, text, writeAssembly = false, errors = errors) shouldBe null
|
||||
errors.errors.size shouldBe 2
|
||||
errors.errors[0] shouldContain "must be an iterable type"
|
||||
errors.errors[1] shouldContain "datatype doesn't match"
|
||||
@ -936,7 +936,7 @@ class TestProg8Parser: FunSpec( {
|
||||
}
|
||||
}
|
||||
"""
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false).assertSuccess()
|
||||
val result = compileText(C64Target(), false, text, writeAssembly = false)!!
|
||||
val stmt = result.program.entrypoint.statements
|
||||
stmt.size shouldBe 12
|
||||
val var1 = stmt[0] as VarDecl
|
||||
|
@ -1,8 +1,8 @@
|
||||
package prog8tests.codegeneration
|
||||
|
||||
import io.kotest.core.spec.style.FunSpec
|
||||
import io.kotest.matchers.shouldNotBe
|
||||
import prog8.codegen.target.C64Target
|
||||
import prog8tests.helpers.assertSuccess
|
||||
import prog8tests.helpers.compileText
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ class TestVariables: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), true, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("array initialization with array literal") {
|
||||
@ -35,7 +35,7 @@ class TestVariables: FunSpec({
|
||||
}
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), true, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), true, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
|
||||
test("array initialization with array var assignment") {
|
||||
@ -48,6 +48,6 @@ class TestVariables: FunSpec({
|
||||
ubyte[] values = [1,2,3]
|
||||
}
|
||||
"""
|
||||
compileText(C64Target(), false, text, writeAssembly = true).assertSuccess()
|
||||
compileText(C64Target(), false, text, writeAssembly = true) shouldNotBe null
|
||||
}
|
||||
})
|
||||
|
@ -1,7 +1,5 @@
|
||||
package prog8tests.helpers
|
||||
|
||||
import io.kotest.assertions.withClue
|
||||
import io.kotest.matchers.shouldBe
|
||||
import prog8.ast.Program
|
||||
import prog8.codegen.cpu6502.AsmGen
|
||||
import prog8.codegen.target.C64Target
|
||||
@ -15,24 +13,6 @@ import java.nio.file.Path
|
||||
import kotlin.io.path.name
|
||||
|
||||
|
||||
internal fun CompilationResult.assertSuccess(description: String = ""): CompilationResult {
|
||||
withClue("expected successful compilation but failed $description") {
|
||||
success shouldBe true
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
internal fun CompilationResult.assertFailure(description: String = ""): CompilationResult {
|
||||
withClue("expected failure to compile but succeeded $description") {
|
||||
success shouldBe false
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CompilationResult.assertSuccess
|
||||
* @see CompilationResult.assertFailure
|
||||
*/
|
||||
internal fun compileFile(
|
||||
platform: ICompilationTarget,
|
||||
optimize: Boolean,
|
||||
@ -42,7 +22,7 @@ internal fun compileFile(
|
||||
errors: IErrorReporter? = null,
|
||||
writeAssembly: Boolean = true,
|
||||
optFloatExpr: Boolean = true
|
||||
) : CompilationResult {
|
||||
) : CompilationResult? {
|
||||
val filepath = fileDir.resolve(fileName)
|
||||
assumeReadableFile(filepath)
|
||||
val args = CompilerArguments(
|
||||
@ -74,7 +54,7 @@ internal fun compileText(
|
||||
errors: IErrorReporter? = null,
|
||||
writeAssembly: Boolean = true,
|
||||
optFloatExpr: Boolean = true
|
||||
) : CompilationResult {
|
||||
) : CompilationResult? {
|
||||
val filePath = outputDir.resolve("on_the_fly_test_" + sourceText.hashCode().toUInt().toString(16) + ".p8")
|
||||
// we don't assumeNotExists(filePath) - should be ok to just overwrite it
|
||||
filePath.toFile().writeText(sourceText)
|
||||
|
Loading…
Reference in New Issue
Block a user