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

kotlin.script.experimental.jvmhost.BasicJvmScriptingHost.kt Maven / Gradle / Ivy

There is a newer version: 2.1.0-RC
Show newest version
/*
 * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

@file:Suppress("unused")

package kotlin.script.experimental.jvmhost

import kotlin.script.experimental.api.*
import kotlin.script.experimental.host.*
import kotlin.script.experimental.jvm.BasicJvmScriptEvaluator
import kotlin.script.experimental.jvm.defaultJvmScriptingHostConfiguration

open class BasicJvmScriptingHost(
    val baseHostConfiguration: ScriptingHostConfiguration? = null,
    compiler: JvmScriptCompiler = JvmScriptCompiler(baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration)),
    evaluator: ScriptEvaluator = BasicJvmScriptEvaluator()
) : BasicScriptingHost(compiler, evaluator) {

    inline fun  evalWithTemplate(
        script: SourceCode,
        noinline compilation: ScriptCompilationConfiguration.Builder.() -> Unit = {},
        noinline evaluation: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
    ): ResultWithDiagnostics {
        val definition =
            createJvmScriptDefinitionFromTemplate(baseHostConfiguration, compilation, evaluation)
        return eval(script, definition.compilationConfiguration, definition.evaluationConfiguration)
    }
}


inline fun  createJvmCompilationConfigurationFromTemplate(
    baseHostConfiguration: ScriptingHostConfiguration? = null,
    noinline body: ScriptCompilationConfiguration.Builder.() -> Unit = {}
): ScriptCompilationConfiguration = createCompilationConfigurationFromTemplate(
    KotlinType(T::class),
    baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
    ScriptCompilationConfiguration::class,
    body
)

inline fun  createJvmEvaluationConfigurationFromTemplate(
    baseHostConfiguration: ScriptingHostConfiguration? = null,
    noinline body: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
): ScriptEvaluationConfiguration = createEvaluationConfigurationFromTemplate(
    KotlinType(T::class),
    baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
    ScriptEvaluationConfiguration::class,
    body
)

inline fun  createJvmScriptDefinitionFromTemplate(
    baseHostConfiguration: ScriptingHostConfiguration? = null,
    noinline compilation: ScriptCompilationConfiguration.Builder.() -> Unit = {},
    noinline evaluation: ScriptEvaluationConfiguration.Builder.() -> Unit = {}
): ScriptDefinition = createScriptDefinitionFromTemplate(
    KotlinType(T::class),
    baseHostConfiguration.withDefaultsFrom(defaultJvmScriptingHostConfiguration),
    ScriptCompilationConfiguration::class,
    compilation,
    evaluation
)





© 2015 - 2024 Weber Informatics LLC | Privacy Policy