commonMain.com.sunnychung.lib.multiplatform.kotlite.model.PrimitiveIterableInterface.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlite-interpreter-jvm Show documentation
Show all versions of kotlite-interpreter-jvm Show documentation
A Kotlin Multiplatform library to interpret Kotlite code, which is a subset of Kotlin language, in runtime in a safe way.
The newest version!
package com.sunnychung.lib.multiplatform.kotlite.model
import com.sunnychung.lib.multiplatform.kotlite.lexer.BuiltinFilename
fun PrimitiveIterableValue(value: Iterable, typeArgument: DataType, symbolTable: SymbolTable)
= DelegatedValue(value, IterableInterface.clazz, listOf(typeArgument), symbolTable)
object PrimitiveIterableInterface {
val clazz = ProvidedClassDefinition(
fullQualifiedName = "PrimitiveIterable",
isInterface = true,
typeParameters = listOf(TypeParameter(name = "T", typeUpperBound = null)),
isInstanceCreationAllowed = false,
primaryConstructorParameters = emptyList(),
constructInstance = { _, _, _ -> throw UnsupportedOperationException() },
superInterfaceTypeNames = listOf("Iterable"),
position = SourcePosition(BuiltinFilename.BUILTIN, 1, 1),
)
val functions = listOf(
CustomFunctionDefinition(
receiverType = "PrimitiveIterable",
functionName = "iterator",
returnType = "PrimitiveIterator",
parameterTypes = emptyList(),
typeParameters = listOf(
TypeParameter(name = "T", typeUpperBound = null),
),
executable = { interpreter, receiver, args, typeArgs ->
val delegatedValue = (receiver as DelegatedValue<*>).value as Iterable
PrimitiveIteratorValue(delegatedValue.iterator(), typeArgs["T"]!!, interpreter.symbolTable())
},
position = SourcePosition(BuiltinFilename.BUILTIN, 1, 1),
),
)
}