All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.sunnychung.lib.multiplatform.kotlite.model.PrimitiveIterableInterface.kt Maven / Gradle / Ivy

Go to download

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),
        ),
    )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy