mirror of
https://github.com/KarolS/millfork.git
synced 2024-12-24 15:29:23 +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 optimizations removing pointless stores to local variables.
|
||||||
|
|
||||||
|
* Fixed name clashes when passing parameters to functions.
|
||||||
|
|
||||||
* Fixed `#use` not accessing all preprocessor parameters.
|
* Fixed `#use` not accessing all preprocessor parameters.
|
||||||
|
|
||||||
* Fixed `#pragma` not respecting `#if`.
|
* Fixed `#pragma` not respecting `#if`.
|
||||||
|
@ -29,7 +29,7 @@ class AbstractExpressionCompiler[T <: AbstractCode] {
|
|||||||
|
|
||||||
def callingContext(ctx: CompilationContext, callee: String, v: VariableInMemory): CompilationContext = {
|
def callingContext(ctx: CompilationContext, callee: String, v: VariableInMemory): CompilationContext = {
|
||||||
val result = new Environment(Some(ctx.env), "", ctx.options.platform.cpuFamily, ctx.options)
|
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)
|
result.addVariable(ctx.options, localName, v, None)
|
||||||
ctx.copy(env = result)
|
ctx.copy(env = result)
|
||||||
}
|
}
|
||||||
|
@ -1404,7 +1404,7 @@ object MosExpressionCompiler extends AbstractExpressionCompiler[AssemblyLine] {
|
|||||||
params.zip(paramVars).flatMap {
|
params.zip(paramVars).flatMap {
|
||||||
case (paramExpr, paramVar) =>
|
case (paramExpr, paramVar) =>
|
||||||
val callCtx = callingContext(ctx, function.name, 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))
|
} ++ List(AssemblyLine.absoluteOrLongAbsolute(JSR, function, ctx.options))
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
@ -975,11 +975,11 @@ object Z80ExpressionCompiler extends AbstractExpressionCompiler[ZLine] {
|
|||||||
val callCtx = callingContext(ctx, function.name, paramVar)
|
val callCtx = callingContext(ctx, function.name, paramVar)
|
||||||
paramVar.typ.size match {
|
paramVar.typ.size match {
|
||||||
case 1 =>
|
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 =>
|
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 _ =>
|
case _ =>
|
||||||
storeLarge(callCtx, VariableExpression(paramVar.name), paramExpr)
|
storeLarge(callCtx, VariableExpression(paramVar.name + "`aa"), paramExpr)
|
||||||
}
|
}
|
||||||
} ++ List(ZLine(CALL, NoRegisters, function.toAddress))
|
} ++ 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] = {
|
def getReturnedVariables(statements: Seq[Statement]): Set[String] = {
|
||||||
statements.flatMap {
|
statements.flatMap {
|
||||||
case ReturnStatement(Some(VariableExpression(v))) => Set(v)
|
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 = {
|
def addVariable(options: CompilationOptions, localName: String, variable: Variable, position: Option[Position]): Unit = {
|
||||||
variable match {
|
variable match {
|
||||||
case v: StackVariable =>
|
case v: StackVariable =>
|
||||||
addThing(v, position)
|
addThing(localName, v, position)
|
||||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
||||||
addThing(StackVariable(prefix + localName + suffix, t, baseStackOffset + offset), position)
|
addThing(StackVariable(prefix + localName + suffix, t, baseStackOffset + offset), position)
|
||||||
}
|
}
|
||||||
case v: MemoryVariable =>
|
case v: MemoryVariable =>
|
||||||
addThing(v, position)
|
addThing(localName, v, position)
|
||||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
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)
|
val subv = RelativeVariable(prefix + localName + suffix, v.toAddress + offset, t, zeropage = v.zeropage, declaredBank = v.declaredBank, isVolatile = v.isVolatile)
|
||||||
addThing(subv, position)
|
addThing(subv, position)
|
||||||
registerAddressConstant(subv, position, options, Some(t))
|
registerAddressConstant(subv, position, options, Some(t))
|
||||||
}
|
}
|
||||||
case v: VariableInMemory =>
|
case v: VariableInMemory =>
|
||||||
addThing(v, position)
|
addThing(localName, v, position)
|
||||||
addThing(ConstantThing(v.name + "`", v.toAddress, get[Type]("word")), position)
|
addThing(ConstantThing(v.name + "`", v.toAddress, get[Type]("word")), position)
|
||||||
for ((suffix, offset, t) <- getSubvariables(v.typ)) {
|
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)
|
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