diff --git a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt index 18bf60b72..7c70ff319 100644 --- a/compiler/src/prog8/compiler/astprocessing/AstChecker.kt +++ b/compiler/src/prog8/compiler/astprocessing/AstChecker.kt @@ -1350,7 +1350,7 @@ internal class AstChecker(private val program: Program, val array = value.value.map { when (it) { is NumericLiteralValue -> it.number.toInt() - is AddressOf -> it.identifier.heapId(program.namespace) + is AddressOf -> it.identifier.hashCode() and 0xffff is TypecastExpression -> { val constVal = it.expression.constValue(program) val cast = constVal?.cast(it.type) diff --git a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt b/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt index ba7bb0fef..f35d80bdc 100644 --- a/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt +++ b/compiler/src/prog8/compiler/functions/BuiltinFunctions.kt @@ -88,6 +88,7 @@ class FSignature(val name: String, } } +@Suppress("UNUSED_ANONYMOUS_PARAMETER") private val functionSignatures: List = listOf( // this set of function have no return value and operate in-place: FSignature("rol" , false, listOf(FParam("item", setOf(DataType.UBYTE, DataType.UWORD))), null), @@ -271,6 +272,7 @@ private fun collectionArg(args: List, position: Position, program: P return NumericLiteralValue.optimalNumeric(function(constElements.mapNotNull { it }), args[0].position) } +@Suppress("UNUSED_PARAMETER") private fun builtinAbs(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { // 1 arg, type = float or int, result type= isSameAs as argument type if(args.size!=1) @@ -342,6 +344,7 @@ private fun builtinSizeof(args: List, position: Position, program: P } } +@Suppress("UNUSED_PARAMETER") private fun builtinLen(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { // 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) @@ -376,6 +379,7 @@ private fun builtinLen(args: List, position: Position, program: Prog } +@Suppress("UNUSED_PARAMETER") private fun builtinMkword(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 2) throw SyntaxError("mkword requires msb and lsb arguments", position) @@ -385,6 +389,7 @@ private fun builtinMkword(args: List, position: Position, program: P return NumericLiteralValue(DataType.UWORD, result, position) } +@Suppress("UNUSED_PARAMETER") private fun builtinSin8(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("sin8 requires one argument", position) @@ -393,6 +398,7 @@ private fun builtinSin8(args: List, position: Position, program: Pro return NumericLiteralValue(DataType.BYTE, (127.0 * sin(rad)).toInt().toShort(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinSin8u(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("sin8u requires one argument", position) @@ -401,6 +407,7 @@ private fun builtinSin8u(args: List, position: Position, program: Pr return NumericLiteralValue(DataType.UBYTE, (128.0 + 127.5 * sin(rad)).toInt().toShort(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinCos8(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("cos8 requires one argument", position) @@ -409,6 +416,7 @@ private fun builtinCos8(args: List, position: Position, program: Pro return NumericLiteralValue(DataType.BYTE, (127.0 * cos(rad)).toInt().toShort(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinCos8u(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("cos8u requires one argument", position) @@ -417,6 +425,7 @@ private fun builtinCos8u(args: List, position: Position, program: Pr return NumericLiteralValue(DataType.UBYTE, (128.0 + 127.5 * cos(rad)).toInt().toShort(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinSin16(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("sin16 requires one argument", position) @@ -425,6 +434,7 @@ private fun builtinSin16(args: List, position: Position, program: Pr return NumericLiteralValue(DataType.WORD, (32767.0 * sin(rad)).toInt(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinSin16u(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("sin16u requires one argument", position) @@ -433,6 +443,7 @@ private fun builtinSin16u(args: List, position: Position, program: P return NumericLiteralValue(DataType.UWORD, (32768.0 + 32767.5 * sin(rad)).toInt(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinCos16(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("cos16 requires one argument", position) @@ -441,6 +452,7 @@ private fun builtinCos16(args: List, position: Position, program: Pr return NumericLiteralValue(DataType.WORD, (32767.0 * cos(rad)).toInt(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinCos16u(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("cos16u requires one argument", position) @@ -449,6 +461,7 @@ private fun builtinCos16u(args: List, position: Position, program: P return NumericLiteralValue(DataType.UWORD, (32768.0 + 32767.5 * cos(rad)).toInt(), position) } +@Suppress("UNUSED_PARAMETER") private fun builtinSgn(args: List, position: Position, program: Program, memsizer: IMemSizer): NumericLiteralValue { if (args.size != 1) throw SyntaxError("sgn requires one argument", position) diff --git a/compilerAst/src/prog8/ast/AstToplevel.kt b/compilerAst/src/prog8/ast/AstToplevel.kt index febc6fd5b..ccfab468f 100644 --- a/compilerAst/src/prog8/ast/AstToplevel.kt +++ b/compilerAst/src/prog8/ast/AstToplevel.kt @@ -296,7 +296,6 @@ class Program(val name: String, fun internString(string: StringLiteralValue): List { val key = Pair(string.value, string.altEncoding) - string.heapId val existing = internedStrings[key] if(existing!=null) return existing diff --git a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt index 2b897f1e0..fb3568209 100644 --- a/compilerAst/src/prog8/ast/expressions/AstExpressions.kt +++ b/compilerAst/src/prog8/ast/expressions/AstExpressions.kt @@ -480,15 +480,11 @@ class NumericLiteralValue(val type: DataType, // only numerical types allowed } } -private var heapIdSequence = 0 // unique ids for strings and arrays "on the heap" - class StringLiteralValue(val value: String, val altEncoding: Boolean, // such as: screencodes instead of Petscii for the C64 override val position: Position) : Expression() { override lateinit var parent: Node - val heapId = ++heapIdSequence - override fun linkParents(parent: Node) { this.parent = parent } @@ -518,8 +514,6 @@ class ArrayLiteralValue(val type: InferredTypes.InferredType, // inferred be override val position: Position) : Expression() { override lateinit var parent: Node - val heapId = ++heapIdSequence - override fun linkParents(parent: Node) { this.parent = parent value.forEach {it.linkParents(this)} @@ -765,17 +759,6 @@ data class IdentifierReference(val nameInSource: List, override val posi fun memberOfStruct(program: Program) = this.targetVarDecl(program)?.struct - fun heapId(namespace: INameScope): Int { - val node = namespace.lookup(nameInSource, this) ?: throw UndefinedSymbolError(this) - val value = (node as? VarDecl)?.value ?: throw FatalAstException("requires a reference value") - return when (value) { - is IdentifierReference -> value.heapId(namespace) - is StringLiteralValue -> value.heapId - is ArrayLiteralValue -> value.heapId - else -> throw FatalAstException("requires a reference value") - } - } - fun firstStructVarName(program: Program): String? { // take the name of the first struct member of the structvariable instead // if it's just a regular variable, return null. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 773ce25c4..4488b90fb 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,7 +5,6 @@ TODO - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - optimize swap of two memread values with index, using the same pointer expression/variable, like swap(@(ptr+1), @(ptr+2)) - optimize several inner loops in gfx2 (highres 4 color mode) -- use the 65c02 bit clear/set/test instructions for single-bit operations - try to fix the bresenham line routines in graphics and gfx2 (sometimes they're a pixel 'off') - add modes 2 and 3 to gfx2 (lowres 4 color and 16 color) - add a flood fill routine to gfx2?