Skip to content

Commit

Permalink
bit operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhirkevich Alexander Y authored and Zhirkevich Alexander Y committed Oct 16, 2024
1 parent 9844343 commit d60feb2
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ public interface ScriptEngine : ScriptInterpreter {
}
}

public fun ScriptEngine.invoke(script: String) : Any? {
return interpret(script).invoke(runtime)
public fun ScriptEngine.evaluate(script: String) : Any? {
return invoke(interpret(script))
}

public fun ScriptEngine.invoke(script: Script) : Any? {
return script.invoke(runtime)
}

public fun ScriptEngine(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,11 @@ internal class OpAssignByIndex(
current.value[index]
}
is ESObject -> {
val idxNorm = when (idx){
is CharSequence -> idx.toString()
else -> idx
}

if (idxNorm in current && merge != null){
current[idxNorm] = merge.invoke(current[idxNorm], v)

if (idx in current && merge != null){
current[idx] = merge.invoke(current[idx], v)
} else {
current[idxNorm] = v
current[idx] = v
}
}
else -> error("Can't assign '$current' by index ($index)")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ internal fun OpCompare(
)
}

internal fun OpNot(
condition : Expression,
isFalse : (Any?) -> Boolean,
) = Expression {
isFalse(condition(it))
}



internal val OpGreaterComparator : (Comparable<*>, Comparable<*>, ScriptRuntime) -> Boolean = { a, b, _ ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.alexzhirkevich.skriptie.common

import io.github.alexzhirkevich.skriptie.Expression
import io.github.alexzhirkevich.skriptie.invoke

internal fun OpLongInt(
a : Expression,
b : Expression,
op : (Long, Int) -> Long
) = Expression {
val an = it.toNumber(a(it)).toLong()
val bn = it.toNumber(b(it)).toInt()

op(an, bn)
}

internal fun OpLongLong(
a : Expression,
b : Expression,
op: (Long, Long) -> Long
) = Expression{
val an = it.toNumber(a(it)).toLong()
val bn = it.toNumber(b(it)).toLong()

op(an, bn)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface ESAny {

public operator fun get(variable: Any?): Any?

public operator fun contains(variable: Any?): Boolean

public operator fun invoke(
function: String,
context: ScriptRuntime,
Expand Down
Loading

0 comments on commit d60feb2

Please sign in to comment.