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

commonMain.dsl.Symbol.kt Maven / Gradle / Ivy

package org.openrndr.orsl.shadergenerator.dsl


interface Symbol {
    val name: String
    val type: String
}

interface IfSymbol: Symbol

/**
 * Allow for else_ expressions on doIf
 */
interface DoIfSymbol: Symbol


fun  symbol(name: String, type: String) = object : Symbol {
    override val name = name
    override val type = type
}

inline fun  symbol(name: String) = object : Symbol {
    override val name = name
    override val type = staticType()
}

inline fun  ifSymbol(name: String) = object : IfSymbol {
    override val name = name
    override val type = staticType()
}


interface ArraySymbol {
    val name: String
    val length: Int
    val type: String
}

fun  arraySymbol(name: String, length: Int, type: String) = object : ArraySymbol {
    override val name = name
    override val length = length
    override val type = type
}

inline fun  arraySymbol(name: String, length: Int) = object : ArraySymbol {
    override val name = name
    override val length = length
    override val type = staticType()
}

data class Function0Symbol(
    val function: String,
    override val type: String
) : Symbol {
    override val name: String
        get() {
            return function
        }
}


data class FunctionSymbol1(
    val v0: T0? = null,
    val p0: Symbol? = null,
    val function: String,
    override val type: String
) : Symbol {
    override val name: String
        get() {
            val x0 = p0?.name ?: glsl(v0) ?: error("no v")
            return function.replace("$0", x0)
        }
}

inline fun  functionSymbol(v0: T0, function: String): Symbol =
    FunctionSymbol1(v0 = v0, function = function, type = staticType())

inline fun  functionSymbol(p0: Symbol, function: String): Symbol =
    FunctionSymbol1(p0 = p0, function = function, type = staticType())


data class Function2Symbol(
    val v0: T0? = null,
    val p0: Symbol? = null,
    val v1: T1? = null,
    val p1: Symbol? = null,
    val function: String,
    override val type: String

) : Symbol {

    override val name: String
        get() {
            val x0 = p0?.name ?: glsl(v0) ?: error("no v")
            val x1 = p1?.name ?: glsl(v1) ?: error("no v")
            return function.replace("$0", x0).replace("$1", x1)
        }
}

inline fun  functionSymbol(
    p0: Symbol,
    p1: Symbol,
    function: String
): Symbol =
    Function2Symbol(p0 = p0, p1 = p1, function = function, type = staticType())

inline fun  functionSymbol(p0: Symbol, v1: T1, function: String): Symbol =
    Function2Symbol(p0 = p0, v1 = v1, function = function, type = staticType())

inline fun  functionSymbol(v0: T0, p1: Symbol, function: String): Symbol =
    Function2Symbol(v0 = v0, p1 = p1, function = function, type = staticType())


data class Function3Symbol(
    val v0: T0? = null,
    val p0: Symbol? = null,
    val v1: T1? = null,
    val p1: Symbol? = null,
    val v2: T2? = null,
    val p2: Symbol? = null,
    val function: String,
    override val type: String
) : Symbol {
    override val name: String
        get() {
            val x0 = p0?.name ?: glsl(v0) ?: error("no v")
            val x1 = p1?.name ?: glsl(v1) ?: error("no v")
            val x2 = p2?.name ?: glsl(v2) ?: error("no v")
            return function.replace("$0", x0).replace("$1", x1).replace("$2", x2)
        }
}

inline fun  Generator.functionCall(
    p0: Symbol,
    p1: Symbol,
    p2: Symbol,
    function: String
) {
    val b = Function3Symbol(p0 = p0, p1 = p1, p2 = p2, function = function, type = "")
    emit("${b.name};")
}


inline fun  functionSymbol(
    p0: Symbol,
    p1: Symbol,
    p2: Symbol,
    function: String
): Symbol =
    Function3Symbol(p0 = p0, p1 = p1, p2 = p2, function = function, type = staticType())



inline fun  functionSymbol(
    v0: T0,
    v1: T1,
    p2: Symbol,
    function: String
): Symbol =
    Function3Symbol(v0 = v0, v1 = v1, p2 = p2, function = function, type = staticType())

inline fun  functionSymbolSSV(
    p0: Symbol,
    p1: Symbol,
    v2: T2,
    function: String
): Symbol =
    Function3Symbol(p0 = p0, p1 = p1, v2 = v2, function = function, type = staticType())


inline fun  functionSymbolSVV(
    p0: Symbol,
    v1: T1,
    v2: T2,
    function: String
): Symbol =
    Function3Symbol(p0 = p0, v1 = v1, v2 = v2, function = function, type = staticType())


data class Function4Symbol(
    val v0: T0? = null,
    val p0: Symbol? = null,
    val v1: T1? = null,
    val p1: Symbol? = null,
    val v2: T2? = null,
    val p2: Symbol? = null,
    val v3: T3? = null,
    val p3: Symbol? = null,
    val function: String,
    override val type: String
) : Symbol {
    override val name: String
        get() {
            val x0 = p0?.name ?: glsl(v0) ?: error("no x0")
            val x1 = p1?.name ?: glsl(v1) ?: error("no x1")
            val x2 = p2?.name ?: glsl(v2) ?: error("no x2")
            val x3 = p3?.name ?: glsl(v3) ?: error("no x3")
            return function.replace("$0", x0).replace("$1", x1).replace("$2", x2).replace("$3", x3)
        }
}

inline fun  functionSymbol(
    p0: Symbol,
    p1: Symbol,
    p2: Symbol,
    p3: Symbol,
    function: String
): Symbol =
    Function4Symbol(p0 = p0, p1 = p1, p2 = p2, p3 = p3, function = function, type = staticType())

inline fun  functionSymbol(
    p0: Symbol,
    p1: Symbol,
    p2: Symbol,
    v3: T3,
    function: String
): Symbol =
    Function4Symbol(p0 = p0, p1 = p1, p2 = p2, v3 = v3, function = function, type = staticType())

inline fun  functionSymbol(
    p0: Symbol,
    p1: Symbol,
    v2: T2,
    v3: T3,
    function: String
): Symbol =
    Function4Symbol(p0 = p0, p1 = p1, v2 = v2, v3 = v3, function = function, type = staticType())




© 2015 - 2024 Weber Informatics LLC | Privacy Policy