2021-10-29 16:20:53 +02:00
|
|
|
package prog8tests.helpers
|
2021-07-30 17:39:43 +02:00
|
|
|
|
|
|
|
import prog8.ast.IBuiltinFunctions
|
|
|
|
import prog8.ast.expressions.Expression
|
|
|
|
import prog8.ast.expressions.InferredTypes
|
2022-02-11 00:21:40 +01:00
|
|
|
import prog8.ast.expressions.NumericLiteral
|
2022-03-10 22:38:16 +01:00
|
|
|
import prog8.code.core.*
|
2023-01-30 23:13:36 +01:00
|
|
|
import prog8.code.target.virtual.VirtualMachineDefinition
|
2022-03-10 22:38:16 +01:00
|
|
|
|
2021-07-30 17:39:43 +02:00
|
|
|
|
2022-02-06 22:56:17 +01:00
|
|
|
internal object DummyFunctions : IBuiltinFunctions {
|
2021-07-30 17:39:43 +02:00
|
|
|
override val names: Set<String> = emptySet()
|
|
|
|
override val purefunctionNames: Set<String> = emptySet()
|
|
|
|
override fun constValue(
|
2022-04-13 23:23:59 +02:00
|
|
|
funcName: String,
|
2021-07-30 17:39:43 +02:00
|
|
|
args: List<Expression>,
|
|
|
|
position: Position,
|
2022-02-11 00:21:40 +01:00
|
|
|
): NumericLiteral? = null
|
2021-07-30 17:39:43 +02:00
|
|
|
|
2022-04-13 23:23:59 +02:00
|
|
|
override fun returnType(funcName: String) = InferredTypes.InferredType.unknown()
|
2021-10-29 02:42:10 +02:00
|
|
|
}
|
2021-10-29 16:20:53 +02:00
|
|
|
|
2022-02-06 22:56:17 +01:00
|
|
|
internal object DummyMemsizer : IMemSizer {
|
2023-02-15 22:50:35 +01:00
|
|
|
override fun memorySize(dt: DataType) = when(dt) {
|
2024-02-04 23:41:01 +01:00
|
|
|
in ByteDatatypesWithBoolean -> 1
|
2023-02-15 22:50:35 +01:00
|
|
|
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 16:20:53 +02:00
|
|
|
}
|
2021-10-30 00:05:55 +02:00
|
|
|
|
2022-02-06 22:56:17 +01:00
|
|
|
internal object DummyStringEncoder : IStringEncoding {
|
2023-12-06 23:41:19 +01:00
|
|
|
override val defaultEncoding: Encoding = Encoding.ISO
|
|
|
|
|
2022-01-18 21:21:49 +01:00
|
|
|
override fun encodeString(str: String, encoding: Encoding): List<UByte> {
|
2021-10-30 00:05:55 +02:00
|
|
|
return emptyList()
|
|
|
|
}
|
|
|
|
|
2023-01-07 15:25:33 +01:00
|
|
|
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
|
2021-10-30 00:05:55 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
2021-12-04 18:20:22 +01:00
|
|
|
|
2022-02-06 22:56:17 +01:00
|
|
|
internal object AsciiStringEncoder : IStringEncoding {
|
2023-12-06 23:41:19 +01:00
|
|
|
override val defaultEncoding: Encoding = Encoding.ISO
|
|
|
|
|
2022-01-18 21:21:49 +01:00
|
|
|
override fun encodeString(str: String, encoding: Encoding): List<UByte> = str.map { it.code.toUByte() }
|
2021-12-04 18:20:22 +01:00
|
|
|
|
2023-01-07 15:25:33 +01:00
|
|
|
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
|
2021-12-04 18:20:22 +01:00
|
|
|
return bytes.joinToString()
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 21:21:49 +01:00
|
|
|
|
2022-02-06 22:56:17 +01:00
|
|
|
internal object DummyCompilationTarget : ICompilationTarget {
|
2022-01-18 21:21:49 +01:00
|
|
|
override val name: String = "dummy"
|
2023-01-30 23:13:36 +01:00
|
|
|
override val machine: IMachineDefinition = VirtualMachineDefinition() // not really true but I don't want to implement a full dummy machinedef
|
2022-02-21 23:38:53 +01:00
|
|
|
override val defaultEncoding = Encoding.PETSCII
|
2022-01-18 21:21:49 +01:00
|
|
|
|
|
|
|
override fun encodeString(str: String, encoding: Encoding): List<UByte> {
|
|
|
|
throw NotImplementedError("dummy")
|
|
|
|
}
|
|
|
|
|
2023-01-07 15:25:33 +01:00
|
|
|
override fun decodeString(bytes: Iterable<UByte>, encoding: Encoding): String {
|
2022-01-18 21:21:49 +01:00
|
|
|
throw NotImplementedError("dummy")
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun memorySize(dt: DataType): Int {
|
|
|
|
throw NotImplementedError("dummy")
|
|
|
|
}
|
2022-03-19 01:20:01 +01:00
|
|
|
|
|
|
|
override fun memorySize(arrayDt: DataType, numElements: Int): Int {
|
|
|
|
throw NotImplementedError("dummy")
|
|
|
|
}
|
2022-02-06 22:56:17 +01:00
|
|
|
}
|