This commit is contained in:
Irmen de Jong 2022-02-21 03:26:17 +01:00
parent 21e9723bb2
commit 064a8e785c
10 changed files with 16 additions and 39 deletions

View File

@ -57,10 +57,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
val fcall = BuiltinFunctionCall(IdentifierReference(listOf(name), Position.DUMMY), argExpressions, Position.DUMMY)
fcall.linkParents(scope)
translateFunctioncall(fcall, func, discardResult = false, resultToStack = false, null)
if(isStatement) {
return DataType.UNDEFINED
return if(isStatement) {
DataType.UNDEFINED
} else {
return builtinFunctionReturnType(func.name, argExpressions, program).getOrElse { throw AssemblyError("unknown dt") }
builtinFunctionReturnType(func.name, argExpressions, program).getOrElse { throw AssemblyError("unknown dt") }
}
}

View File

@ -47,8 +47,8 @@ internal class VariableAllocator(private val vars: IVariablesAndConsts,
val numberOfExplicitNonZpVariables = allVariables.count { it.zp == ZeropageWish.NOT_IN_ZEROPAGE }
require(varsDontCare.size + varsRequiringZp.size + varsPreferringZp.size + numberOfExplicitNonZpVariables == numberOfAllocatableVariables)
var numVariablesAllocatedInZP: Int = 0
var numberOfNonIntegerVariables: Int = 0
var numVariablesAllocatedInZP = 0
var numberOfNonIntegerVariables = 0
varsRequiringZp.forEach { variable ->
val numElements = numArrayElements(variable)

View File

@ -130,7 +130,7 @@ class StatementOptimizer(private val program: Program,
if(functionCallStatement.target.nameInSource !in listOf(listOf("pop"), listOf("popw")) && functionCallStatement.args.size==1) {
val arg = functionCallStatement.args[0]
if(!arg.isSimple && arg !is IFunctionCall) {
val name = program.getTempRegisterName(arg.inferType(program))
val name = getTempRegisterName(arg.inferType(program))
val tempvar = IdentifierReference(name, functionCallStatement.position)
val assignTempvar = Assignment(AssignTarget(tempvar.copy(), null, null, functionCallStatement.position), arg, AssignmentOrigin.OPTIMIZER, functionCallStatement.position)
return listOf(

View File

@ -241,7 +241,7 @@ internal class BeforeAsmAstChanger(val program: Program,
}
if(separateLeftExpr) {
val name = program.getTempRegisterName(leftDt)
val name = getTempRegisterName(leftDt)
leftOperandReplacement = IdentifierReference(name, expr.position)
leftAssignment = Assignment(
AssignTarget(IdentifierReference(name, expr.position), null, null, expr.position),

View File

@ -73,7 +73,7 @@ fun Program.getTempVar(dt: DataType, altNames: Boolean=false): Pair<List<String>
return Pair(tmpvarName, decl)
}
fun Program.getTempRegisterName(dt: InferredTypes.InferredType): List<String> {
fun getTempRegisterName(dt: InferredTypes.InferredType): List<String> {
return when {
// TODO assume (hope) cx16.r9 isn't used for anything else during the use of this temporary variable...
dt istype DataType.UBYTE -> listOf("cx16", "r9L")

View File

@ -1,8 +1,11 @@
package prog8.ast.expressions
import prog8.ast.*
import prog8.ast.IFunctionCall
import prog8.ast.Node
import prog8.ast.Program
import prog8.ast.antlr.escape
import prog8.ast.base.*
import prog8.ast.internedStringsModuleName
import prog8.ast.statements.*
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstVisitor
@ -1103,8 +1106,7 @@ class PipeExpression(val expressions: MutableList<Expression>, override val posi
private fun inferType(program: Program, functionNames: List<Expression>): InferredTypes.InferredType {
val identifier = functionNames.last() as? IdentifierReference
if(identifier!=null) {
val target = identifier.targetStatement(program)
when(target) {
when(val target = identifier.targetStatement(program)) {
is BuiltinFunctionPlaceholder -> {
val typeOfPrev = inferType(program, functionNames.dropLast(1))
return if(typeOfPrev.isKnown) {

View File

@ -614,7 +614,7 @@ class InlineAssembly(val assembly: String, override val position: Position) : St
val everythintBeforeComment = it.substringBefore(';')
wordPattern.findAll(everythintBeforeComment)
}
.flatMap { it.map { it.value } }
.flatMap { it.map { mr -> mr.value } }
.toSet()
}
}

View File

@ -128,11 +128,10 @@ sealed class SourceCode {
/**
* SourceCode for internally generated nodes (usually Modules)
*/
class Generated(name: String) : SourceCode() {
class Generated(override val name: String) : SourceCode() {
override val isFromResources: Boolean = false
override val isFromFilesystem: Boolean = false
override val origin: String = name
override val name: String = name
override val text: String = "<generated code node, no text representation>"
}
}

View File

@ -90,9 +90,6 @@ class FSignature(val name: String,
}
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
private val functionSignatures: List<FSignature> = listOf(
// this set of function have no return value and operate in-place:
FSignature("rol" , false, listOf(FParam("item", arrayOf(DataType.UBYTE, DataType.UWORD))), false,null),
@ -311,7 +308,6 @@ private fun collectionArg(args: List<Expression>, position: Position, program: P
return NumericLiteral.optimalNumeric(function(constElements.mapNotNull { it }), args[0].position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinAbs(args: List<Expression>, position: Position, program: Program): NumericLiteral {
// 1 arg, type = float or int, result type= isSameAs as argument type
if(args.size!=1)
@ -351,7 +347,6 @@ private fun builtinSizeof(args: List<Expression>, position: Position, program: P
}
}
@Suppress("UNUSED_PARAMETER")
private fun builtinLen(args: List<Expression>, position: Position, program: Program): NumericLiteral {
// note: in some cases the length is > 255, and then we have to return a UWORD type instead of a UBYTE.
if(args.size!=1)
@ -385,7 +380,6 @@ private fun builtinLen(args: List<Expression>, position: Position, program: Prog
}
@Suppress("UNUSED_PARAMETER")
private fun builtinMkword(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 2)
throw SyntaxError("mkword requires msb and lsb arguments", position)
@ -395,7 +389,6 @@ private fun builtinMkword(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.UWORD, result.toDouble(), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSin8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sin8 requires one argument", position)
@ -404,7 +397,6 @@ private fun builtinSin8(args: List<Expression>, position: Position, program: Pro
return NumericLiteral(DataType.BYTE, round(127.0 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSin8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sin8u requires one argument", position)
@ -413,7 +405,6 @@ private fun builtinSin8u(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.UBYTE, round(128.0 + 127.5 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSinR8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sinr8 requires one argument", position)
@ -422,7 +413,6 @@ private fun builtinSinR8(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.BYTE, round(127.0 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSinR8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sinr8u requires one argument", position)
@ -431,7 +421,6 @@ private fun builtinSinR8u(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.UBYTE, round(128.0 + 127.5 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCos8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cos8 requires one argument", position)
@ -440,7 +429,6 @@ private fun builtinCos8(args: List<Expression>, position: Position, program: Pro
return NumericLiteral(DataType.BYTE, round(127.0 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCos8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cos8u requires one argument", position)
@ -449,7 +437,6 @@ private fun builtinCos8u(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.UBYTE, round(128.0 + 127.5 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCosR8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cosr8 requires one argument", position)
@ -458,7 +445,6 @@ private fun builtinCosR8(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.BYTE, round(127.0 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCosR8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cosr8u requires one argument", position)
@ -467,7 +453,6 @@ private fun builtinCosR8u(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.UBYTE, round(128.0 + 127.5 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSin16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sin16 requires one argument", position)
@ -476,7 +461,6 @@ private fun builtinSin16(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.WORD, round(32767.0 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSin16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sin16u requires one argument", position)
@ -485,7 +469,6 @@ private fun builtinSin16u(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.UWORD, round(32768.0 + 32767.5 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSinR16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sinr16 requires one argument", position)
@ -494,7 +477,6 @@ private fun builtinSinR16(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.WORD, round(32767.0 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSinR16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sinr16u requires one argument", position)
@ -503,7 +485,6 @@ private fun builtinSinR16u(args: List<Expression>, position: Position, program:
return NumericLiteral(DataType.UWORD, round(32768.0 + 32767.5 * sin(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCos16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cos16 requires one argument", position)
@ -512,7 +493,6 @@ private fun builtinCos16(args: List<Expression>, position: Position, program: Pr
return NumericLiteral(DataType.WORD, round(32767.0 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCos16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cos16u requires one argument", position)
@ -521,7 +501,6 @@ private fun builtinCos16u(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.UWORD, round(32768.0 + 32767.5 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCosR16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cosr16 requires one argument", position)
@ -530,7 +509,6 @@ private fun builtinCosR16(args: List<Expression>, position: Position, program: P
return NumericLiteral(DataType.WORD, round(32767.0 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinCosR16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("cosr16u requires one argument", position)
@ -539,7 +517,6 @@ private fun builtinCosR16u(args: List<Expression>, position: Position, program:
return NumericLiteral(DataType.UWORD, round(32768.0 + 32767.5 * cos(rad)), position)
}
@Suppress("UNUSED_PARAMETER")
private fun builtinSgn(args: List<Expression>, position: Position, program: Program): NumericLiteral {
if (args.size != 1)
throw SyntaxError("sgn requires one argument", position)

View File

@ -37,5 +37,4 @@ class CompilationOptions(val output: OutputType,
var asmListfile: Boolean = false,
var experimentalCodegen: Boolean = false,
var outputDir: Path = Path("")
) {
}
)