improve errorhandling

This commit is contained in:
Irmen de Jong 2021-10-12 01:45:32 +02:00
parent e5a1b37981
commit 33733a4001
4 changed files with 27 additions and 9 deletions

View File

@ -335,12 +335,18 @@ private fun writeAssembly(programAst: Program,
compilerOptions.compTarget.machine.zeropage,
compilerOptions,
outputDir).compileToAssembly()
val assemblerReturnStatus = assembly.assemble(compilerOptions)
return if(assemblerReturnStatus!=0)
Pair(false, "assembler step failed with return code $assemblerReturnStatus")
else {
return if(assembly.valid && errors.noErrors()) {
val assemblerReturnStatus = assembly.assemble(compilerOptions)
if(assemblerReturnStatus!=0)
Pair(false, "assembler step failed with return code $assemblerReturnStatus")
else {
errors.report()
Pair(true, assembly.name)
}
} else {
errors.report()
Pair(true, assembly.name)
Pair(false, "compiler failed with errors")
}
}

View File

@ -11,6 +11,7 @@ internal const val subroutineFloatEvalResultVar1 = "_prog8_float_eval_result1"
internal const val subroutineFloatEvalResultVar2 = "_prog8_float_eval_result2"
internal interface IAssemblyProgram {
val valid: Boolean
val name: String
fun assemble(options: CompilationOptions): Int
}

View File

@ -9,7 +9,12 @@ import java.nio.file.Path
internal const val viceMonListPostfix = "vice-mon-list"
class AssemblyProgram(override val name: String, outputDir: Path, private val compTarget: String) : IAssemblyProgram {
class AssemblyProgram(
override val valid: Boolean,
override val name: String,
outputDir: Path,
private val compTarget: String) : IAssemblyProgram {
private val assemblyFile = outputDir.resolve("$name.asm")
private val prgFile = outputDir.resolve("$name.prg")
private val binFile = outputDir.resolve("$name.bin")

View File

@ -87,7 +87,11 @@ internal class AsmGen(private val program: Program,
}
}
return AssemblyProgram(program.name, outputDir, compTarget.name)
return if(errors.noErrors())
AssemblyProgram(true, program.name, outputDir, compTarget.name)
else {
AssemblyProgram(false, "<error>", outputDir, compTarget.name)
}
}
internal fun isTargetCpu(cpu: CpuType) = compTarget.machine.cpu == cpu
@ -1317,8 +1321,10 @@ $repeatLabel lda $counterVar
// TODO: handle %asminclude with SourceCode
val includedName = stmt.args[0].str!!
val sourcePath = Path(stmt.definingModule.source!!.pathString()) // FIXME: %asminclude inside non-library, non-filesystem module
val sourcecode = loadAsmIncludeFile(includedName, sourcePath).getOrThrow()
assemblyLines.add(sourcecode.trimEnd().trimStart('\n'))
loadAsmIncludeFile(includedName, sourcePath).fold(
onSuccess = { assemblyLines.add(it.trimEnd().trimStart('\n')) },
onFailure = { errors.err(it.toString(), stmt.position) }
)
}
"%asmbinary" -> {
val includedName = stmt.args[0].str!!