1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-25 19:29:49 +00:00

Disallow calls to main when using software stack

This commit is contained in:
Karol Stasiak 2019-07-26 14:56:44 +02:00
parent 8d4e7b9326
commit 96850d295d
2 changed files with 9 additions and 0 deletions

View File

@ -131,6 +131,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
if (ctx.options.flag(CompilationFlag.SoftwareStack)) {
val stackPointer = ctx.env.get[ThingInMemory]("__sp")
if (m.name == "main") {
// TODO: what about recursive calls to main?
List(
AssemblyLine.immediate(LDX, 0xff - m.stackVariablesSize),
AssemblyLine.absolute(STX, stackPointer)).map(_.position(m.position))
@ -152,6 +153,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
AssemblyLine.immediate(SBX, m.stackVariablesSize),
AssemblyLine.implied(TXS)).map(_.position(m.position)) // this TXS is fine, it won't appear in 65816 code
}
// TODO: be smarter in case of large stack frames:
if (ctx.prologueShouldAvoidA && ctx.options.flag(CompilationFlag.EmitCmosOpcodes)) {
return List.fill(m.stackVariablesSize)(AssemblyLine.implied(PHX)).map(_.position(m.position))
}

View File

@ -1519,6 +1519,13 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
if (nf.interrupt) {
ctx.log.error(s"Calling an interrupt function `${f.functionName}`", expr.position)
}
if (nf.name == "main" && ctx.options.flag(CompilationFlag.SoftwareStack)) {
if (nf.stackVariablesSize != 0 || env.things.values.exists(_.isInstanceOf[StackVariable])) {
ctx.log.error("Calling the main function when using software stack is not allowed", expr.position)
} else {
ctx.log.warn("Calling the main function when using software stack is not allowed", expr.position)
}
}
case _ => ()
}
val result = function.params match {