mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +00:00
improve errorhandling
This commit is contained in:
parent
e5a1b37981
commit
33733a4001
@ -335,12 +335,18 @@ private fun writeAssembly(programAst: Program,
|
|||||||
compilerOptions.compTarget.machine.zeropage,
|
compilerOptions.compTarget.machine.zeropage,
|
||||||
compilerOptions,
|
compilerOptions,
|
||||||
outputDir).compileToAssembly()
|
outputDir).compileToAssembly()
|
||||||
val assemblerReturnStatus = assembly.assemble(compilerOptions)
|
|
||||||
return if(assemblerReturnStatus!=0)
|
return if(assembly.valid && errors.noErrors()) {
|
||||||
Pair(false, "assembler step failed with return code $assemblerReturnStatus")
|
val assemblerReturnStatus = assembly.assemble(compilerOptions)
|
||||||
else {
|
if(assemblerReturnStatus!=0)
|
||||||
|
Pair(false, "assembler step failed with return code $assemblerReturnStatus")
|
||||||
|
else {
|
||||||
|
errors.report()
|
||||||
|
Pair(true, assembly.name)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
errors.report()
|
errors.report()
|
||||||
Pair(true, assembly.name)
|
Pair(false, "compiler failed with errors")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ internal const val subroutineFloatEvalResultVar1 = "_prog8_float_eval_result1"
|
|||||||
internal const val subroutineFloatEvalResultVar2 = "_prog8_float_eval_result2"
|
internal const val subroutineFloatEvalResultVar2 = "_prog8_float_eval_result2"
|
||||||
|
|
||||||
internal interface IAssemblyProgram {
|
internal interface IAssemblyProgram {
|
||||||
|
val valid: Boolean
|
||||||
val name: String
|
val name: String
|
||||||
fun assemble(options: CompilationOptions): Int
|
fun assemble(options: CompilationOptions): Int
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,12 @@ import java.nio.file.Path
|
|||||||
|
|
||||||
internal const val viceMonListPostfix = "vice-mon-list"
|
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 assemblyFile = outputDir.resolve("$name.asm")
|
||||||
private val prgFile = outputDir.resolve("$name.prg")
|
private val prgFile = outputDir.resolve("$name.prg")
|
||||||
private val binFile = outputDir.resolve("$name.bin")
|
private val binFile = outputDir.resolve("$name.bin")
|
||||||
|
@ -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
|
internal fun isTargetCpu(cpu: CpuType) = compTarget.machine.cpu == cpu
|
||||||
@ -1317,8 +1321,10 @@ $repeatLabel lda $counterVar
|
|||||||
// TODO: handle %asminclude with SourceCode
|
// TODO: handle %asminclude with SourceCode
|
||||||
val includedName = stmt.args[0].str!!
|
val includedName = stmt.args[0].str!!
|
||||||
val sourcePath = Path(stmt.definingModule.source!!.pathString()) // FIXME: %asminclude inside non-library, non-filesystem module
|
val sourcePath = Path(stmt.definingModule.source!!.pathString()) // FIXME: %asminclude inside non-library, non-filesystem module
|
||||||
val sourcecode = loadAsmIncludeFile(includedName, sourcePath).getOrThrow()
|
loadAsmIncludeFile(includedName, sourcePath).fold(
|
||||||
assemblyLines.add(sourcecode.trimEnd().trimStart('\n'))
|
onSuccess = { assemblyLines.add(it.trimEnd().trimStart('\n')) },
|
||||||
|
onFailure = { errors.err(it.toString(), stmt.position) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
"%asmbinary" -> {
|
"%asmbinary" -> {
|
||||||
val includedName = stmt.args[0].str!!
|
val includedName = stmt.args[0].str!!
|
||||||
|
Loading…
Reference in New Issue
Block a user