mirror of
https://github.com/KarolS/millfork.git
synced 2025-08-08 18:25:03 +00:00
Disallow calls to main when using software stack
This commit is contained in:
@@ -131,6 +131,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
|
|||||||
if (ctx.options.flag(CompilationFlag.SoftwareStack)) {
|
if (ctx.options.flag(CompilationFlag.SoftwareStack)) {
|
||||||
val stackPointer = ctx.env.get[ThingInMemory]("__sp")
|
val stackPointer = ctx.env.get[ThingInMemory]("__sp")
|
||||||
if (m.name == "main") {
|
if (m.name == "main") {
|
||||||
|
// TODO: what about recursive calls to main?
|
||||||
List(
|
List(
|
||||||
AssemblyLine.immediate(LDX, 0xff - m.stackVariablesSize),
|
AssemblyLine.immediate(LDX, 0xff - m.stackVariablesSize),
|
||||||
AssemblyLine.absolute(STX, stackPointer)).map(_.position(m.position))
|
AssemblyLine.absolute(STX, stackPointer)).map(_.position(m.position))
|
||||||
@@ -152,6 +153,7 @@ object MosCompiler extends AbstractCompiler[AssemblyLine] {
|
|||||||
AssemblyLine.immediate(SBX, m.stackVariablesSize),
|
AssemblyLine.immediate(SBX, m.stackVariablesSize),
|
||||||
AssemblyLine.implied(TXS)).map(_.position(m.position)) // this TXS is fine, it won't appear in 65816 code
|
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)) {
|
if (ctx.prologueShouldAvoidA && ctx.options.flag(CompilationFlag.EmitCmosOpcodes)) {
|
||||||
return List.fill(m.stackVariablesSize)(AssemblyLine.implied(PHX)).map(_.position(m.position))
|
return List.fill(m.stackVariablesSize)(AssemblyLine.implied(PHX)).map(_.position(m.position))
|
||||||
}
|
}
|
||||||
|
@@ -1519,6 +1519,13 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
|||||||
if (nf.interrupt) {
|
if (nf.interrupt) {
|
||||||
ctx.log.error(s"Calling an interrupt function `${f.functionName}`", expr.position)
|
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 _ => ()
|
case _ => ()
|
||||||
}
|
}
|
||||||
val result = function.params match {
|
val result = function.params match {
|
||||||
|
Reference in New Issue
Block a user