mirror of
https://github.com/KarolS/millfork.git
synced 2024-12-23 23:30:22 +00:00
Fix name clashes when passing parameters to functions
This commit is contained in:
parent
1862fed70f
commit
4eba80b735
@ -38,6 +38,8 @@
|
||||
|
||||
* Fixed optimizations removing pointless stores to local variables.
|
||||
|
||||
* Fixed name clashes when passing parameters to functions.
|
||||
|
||||
* Fixed `#use` not accessing all preprocessor parameters.
|
||||
|
||||
* Fixed `#pragma` not respecting `#if`.
|
||||
|
@ -29,7 +29,7 @@ class AbstractExpressionCompiler[T <: AbstractCode] {
|
||||
|
||||
def callingContext(ctx: CompilationContext, callee: String, v: VariableInMemory): CompilationContext = {
|
||||
val result = new Environment(Some(ctx.env), "", ctx.options.platform.cpuFamily, ctx.options)
|
||||
val localName = v.name.stripPrefix(callee + '$')
|
||||
val localName = v.name + "`aa"
|
||||
result.addVariable(ctx.options, localName, v, None)
|
||||
ctx.copy(env = result)
|
||||
}
|
||||
|
@ -1404,7 +1404,7 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
||||
params.zip(paramVars).flatMap {
|
||||
case (paramExpr, paramVar) =>
|
||||
val callCtx = callingContext(ctx, function.name, paramVar)
|
||||
compileAssignment(callCtx, paramExpr, VariableExpression(paramVar.name))
|
||||
compileAssignment(callCtx, paramExpr, VariableExpression(paramVar.name + "`aa"))
|
||||
} ++ List(AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options))
|
||||
}
|
||||
result
|
||||
|
@ -975,11 +975,11 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] {
|
||||
val callCtx = callingContext(ctx, function.name, paramVar)
|
||||
paramVar.typ.size match {
|
||||
case 1 =>
|
||||
compileToA(ctx, paramExpr) ++ storeA(callCtx, VariableExpression(paramVar.name), paramVar.typ.isSigned)
|
||||
compileToA(ctx, paramExpr) ++ storeA(callCtx, VariableExpression(paramVar.name + "`aa"), paramVar.typ.isSigned)
|
||||
case 2 =>
|
||||
compileToHL(ctx, paramExpr) ++ storeHL(callCtx, VariableExpression(paramVar.name), paramVar.typ.isSigned)
|
||||
compileToHL(ctx, paramExpr) ++ storeHL(callCtx, VariableExpression(paramVar.name + "`aa"), paramVar.typ.isSigned)
|
||||
case _ =>
|
||||
storeLarge(callCtx, VariableExpression(paramVar.name), paramExpr)
|
||||
storeLarge(callCtx, VariableExpression(paramVar.name + "`aa"), paramExpr)
|
||||
}
|
||||
} ++ List(ZLine(CALL, NoRegisters, function.toAddress))
|
||||
}
|
||||
|
12
src/main/scala/millfork/env/Environment.scala
vendored
12
src/main/scala/millfork/env/Environment.scala
vendored
@ -214,6 +214,12 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
||||
}
|
||||
}
|
||||
|
||||
private def addThing(localName: String, t: Thing, position: Option[Position]): Unit = {
|
||||
if (assertNotDefined(t.name, position)) {
|
||||
things(localName) = t
|
||||
}
|
||||
}
|
||||
|
||||
def getReturnedVariables(statements: Seq[Statement]): Set[String] = {
|
||||
statements.flatMap {
|
||||
case ReturnStatement(Some(VariableExpression(v))) => Set(v)
|
||||
@ -1499,19 +1505,19 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
||||
def addVariable(options: CompilationOptions, localName: String, variable: Variable, position: Option[Position]): Unit = {
|
||||
variable match {
|
||||
case v: StackVariable =>
|
||||
addThing(v, position)
|
||||
addThing(localName, v, position)
|
||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
||||
addThing(StackVariable(prefix + localName + suffix, t, baseStackOffset + offset), position)
|
||||
}
|
||||
case v: MemoryVariable =>
|
||||
addThing(v, position)
|
||||
addThing(localName, v, position)
|
||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
||||
val subv = RelativeVariable(prefix + localName + suffix, v.toAddress + offset, t, zeropage = v.zeropage, declaredBank = v.declaredBank, isVolatile = v.isVolatile)
|
||||
addThing(subv, position)
|
||||
registerAddressConstant(subv, position, options, Some(t))
|
||||
}
|
||||
case v: VariableInMemory =>
|
||||
addThing(v, position)
|
||||
addThing(localName, v, position)
|
||||
addThing(ConstantThing(v.name + "`", v.toAddress, get[Type]("word")), position)
|
||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
||||
val subv = RelativeVariable(prefix + localName + suffix, v.toAddress + offset, t, zeropage = v.zeropage, declaredBank = v.declaredBank, isVolatile = v.isVolatile)
|
||||
|
Loading…
Reference in New Issue
Block a user