prog8/compiler/test/helpers/Dummies.kt

77 lines
2.5 KiB
Kotlin
Raw Normal View History

package prog8tests.helpers
import prog8.ast.IBuiltinFunctions
import prog8.ast.expressions.Expression
import prog8.ast.expressions.InferredTypes
2022-02-10 23:21:40 +00:00
import prog8.ast.expressions.NumericLiteral
import prog8.code.core.*
import prog8.code.target.virtual.VirtualMachineDefinition
2022-02-06 21:56:17 +00:00
internal object DummyFunctions : IBuiltinFunctions {
override val names: Set<String> = emptySet()
override val purefunctionNames: Set<String> = emptySet()
override fun constValue(
funcName: String,
args: List<Expression>,
position: Position,
2022-02-10 23:21:40 +00:00
): NumericLiteral? = null
override fun returnType(funcName: String) = InferredTypes.InferredType.unknown()
}
2022-02-06 21:56:17 +00:00
internal object DummyMemsizer : IMemSizer {
override fun memorySize(dt: DataType) = when(dt) {
in ByteDatatypes -> 1
DataType.FLOAT -> 5
else -> 2
}
override fun memorySize(arrayDt: DataType, numElements: Int) = when(arrayDt) {
DataType.ARRAY_UW -> numElements*2
DataType.ARRAY_W -> numElements*2
DataType.ARRAY_F -> numElements*5
else -> numElements
}
}
2021-10-29 22:05:55 +00:00
2022-02-06 21:56:17 +00:00
internal object DummyStringEncoder : IStringEncoding {
override fun encodeString(str: String, encoding: Encoding): List<UByte> {
2021-10-29 22:05:55 +00:00
return emptyList()
}
2023-01-07 14:25:33 +00:00
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
2021-10-29 22:05:55 +00:00
return ""
}
}
2022-02-06 21:56:17 +00:00
internal object AsciiStringEncoder : IStringEncoding {
override fun encodeString(str: String, encoding: Encoding): List<UByte> = str.map { it.code.toUByte() }
2023-01-07 14:25:33 +00:00
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
return bytes.joinToString()
}
}
2022-02-06 21:56:17 +00:00
internal object DummyCompilationTarget : ICompilationTarget {
override val name: String = "dummy"
override val machine: IMachineDefinition = VirtualMachineDefinition() // not really true but I don't want to implement a full dummy machinedef
override val supportedEncodings = setOf(Encoding.PETSCII, Encoding.SCREENCODES, Encoding.ISO)
override val defaultEncoding = Encoding.PETSCII
override fun encodeString(str: String, encoding: Encoding): List<UByte> {
throw NotImplementedError("dummy")
}
2023-01-07 14:25:33 +00:00
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
throw NotImplementedError("dummy")
}
override fun memorySize(dt: DataType): Int {
throw NotImplementedError("dummy")
}
2022-03-19 00:20:01 +00:00
override fun memorySize(arrayDt: DataType, numElements: Int): Int {
throw NotImplementedError("dummy")
}
2022-02-06 21:56:17 +00:00
}