mirror of
https://github.com/KarolS/millfork.git
synced 2025-01-10 20:29:35 +00:00
Disallow calls to main when using software stack
This commit is contained in:
parent
8d4e7b9326
commit
96850d295d
@ -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))
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user