Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e11519608 | ||
|
|
fba44622e5 | ||
|
|
2737aaa14e | ||
|
|
bce88ced43 |
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Tests in 'lyng.lynglib.jvmTest'" type="GradleRunConfiguration" factoryName="Gradle">
|
||||||
|
<ExternalSystemSettings>
|
||||||
|
<option name="executionName" />
|
||||||
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="externalSystemIdString" value="GRADLE" />
|
||||||
|
<option name="scriptParameters" value="" />
|
||||||
|
<option name="taskDescriptions">
|
||||||
|
<list />
|
||||||
|
</option>
|
||||||
|
<option name="taskNames">
|
||||||
|
<list>
|
||||||
|
<option value=":lynglib:cleanJvmTest" />
|
||||||
|
<option value=":lynglib:jvmTest" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="vmOptions" />
|
||||||
|
</ExternalSystemSettings>
|
||||||
|
<ExternalSystemDebugServerProcess>false</ExternalSystemDebugServerProcess>
|
||||||
|
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
|
||||||
|
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
|
||||||
|
<DebugAllEnabled>false</DebugAllEnabled>
|
||||||
|
<RunAsTest>true</RunAsTest>
|
||||||
|
<GradleProfilingDisabled>false</GradleProfilingDisabled>
|
||||||
|
<GradleCoverageDisabled>false</GradleCoverageDisabled>
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
@@ -68,6 +68,20 @@ These, again, does the thing:
|
|||||||
|
|
||||||
>>> void
|
>>> void
|
||||||
|
|
||||||
|
## map and mapNotNull
|
||||||
|
|
||||||
|
Used to transform either the whole iterable stream or also skipping som elements from it:
|
||||||
|
|
||||||
|
val source = [1,2,3,4]
|
||||||
|
// transform every element to string or null:
|
||||||
|
assertEquals(["n1", "n2", null, "n4"], source.map { if( it == 3 ) null else "n"+it } )
|
||||||
|
|
||||||
|
// transform every element to stirng, skipping 3:
|
||||||
|
assertEquals(["n1", "n2", "n4"], source.mapNotNull { if( it == 3 ) null else "n"+it } )
|
||||||
|
|
||||||
|
>>> void
|
||||||
|
|
||||||
|
|
||||||
## Instance methods:
|
## Instance methods:
|
||||||
|
|
||||||
| fun/method | description |
|
| fun/method | description |
|
||||||
|
|||||||
@@ -173,31 +173,44 @@ class Script(
|
|||||||
val a = requiredArg<Obj>(0)
|
val a = requiredArg<Obj>(0)
|
||||||
val b = requiredArg<Obj>(1)
|
val b = requiredArg<Obj>(1)
|
||||||
if (a.compareTo(this, b) != 0)
|
if (a.compareTo(this, b) != 0)
|
||||||
raiseError(ObjAssertionFailedException(this,"Assertion failed: ${a.inspect(this)} == ${b.inspect(this)}"))
|
raiseError(
|
||||||
|
ObjAssertionFailedException(
|
||||||
|
this,
|
||||||
|
"Assertion failed: ${a.inspect(this)} == ${b.inspect(this)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
// alias used in tests
|
// alias used in tests
|
||||||
addVoidFn("assertEqual") {
|
addVoidFn("assertEqual") {
|
||||||
val a = requiredArg<Obj>(0)
|
val a = requiredArg<Obj>(0)
|
||||||
val b = requiredArg<Obj>(1)
|
val b = requiredArg<Obj>(1)
|
||||||
if (a.compareTo(this, b) != 0)
|
if (a.compareTo(this, b) != 0)
|
||||||
raiseError(ObjAssertionFailedException(this,"Assertion failed: ${a.inspect(this)} == ${b.inspect(this)}"))
|
raiseError(
|
||||||
|
ObjAssertionFailedException(
|
||||||
|
this,
|
||||||
|
"Assertion failed: ${a.inspect(this)} == ${b.inspect(this)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
addVoidFn("assertNotEquals") {
|
addVoidFn("assertNotEquals") {
|
||||||
val a = requiredArg<Obj>(0)
|
val a = requiredArg<Obj>(0)
|
||||||
val b = requiredArg<Obj>(1)
|
val b = requiredArg<Obj>(1)
|
||||||
if (a.compareTo(this, b) == 0)
|
if (a.compareTo(this, b) == 0)
|
||||||
raiseError(ObjAssertionFailedException(this,"Assertion failed: ${a.inspect(this)} != ${b.inspect(this)}"))
|
raiseError(
|
||||||
|
ObjAssertionFailedException(
|
||||||
|
this,
|
||||||
|
"Assertion failed: ${a.inspect(this)} != ${b.inspect(this)}"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
addFn("assertThrows") {
|
addFn("assertThrows") {
|
||||||
val code = requireOnlyArg<Statement>()
|
val code = requireOnlyArg<Statement>()
|
||||||
val result = try {
|
val result = try {
|
||||||
code.execute(this)
|
code.execute(this)
|
||||||
null
|
null
|
||||||
}
|
} catch (e: ExecutionError) {
|
||||||
catch( e: ExecutionError ) {
|
|
||||||
e.errorObject
|
e.errorObject
|
||||||
}
|
} catch (_: ScriptError) {
|
||||||
catch (_: ScriptError) {
|
|
||||||
ObjNull
|
ObjNull
|
||||||
}
|
}
|
||||||
result ?: raiseError(ObjAssertionFailedException(this, "Expected exception but nothing was thrown"))
|
result ?: raiseError(ObjAssertionFailedException(this, "Expected exception but nothing was thrown"))
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ object CompletionEngineLight {
|
|||||||
}
|
}
|
||||||
is MiniClassDecl -> add(CompletionItem(d.name, Kind.Class_))
|
is MiniClassDecl -> add(CompletionItem(d.name, Kind.Class_))
|
||||||
is MiniValDecl -> add(CompletionItem(d.name, Kind.Value, typeText = typeOf(d.type)))
|
is MiniValDecl -> add(CompletionItem(d.name, Kind.Value, typeText = typeOf(d.type)))
|
||||||
else -> add(CompletionItem(d.name, Kind.Value))
|
// else -> add(CompletionItem(d.name, Kind.Value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -197,9 +197,20 @@ class ObjInstance(override val objClass: ObjClass) : Obj() {
|
|||||||
!it.key.contains("::") && it.value.visibility.isPublic && it.value.type.serializable
|
!it.key.contains("::") && it.value.visibility.isPublic && it.value.type.serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override suspend fun toString(scope: Scope, calledFromLyng: Boolean): ObjString {
|
||||||
val fields = publicFields.map { "${it.key}=${it.value.value}" }.joinToString(",")
|
return ObjString(buildString {
|
||||||
return "${objClass.className}($fields)"
|
append("${objClass.className}(")
|
||||||
|
var first = true
|
||||||
|
for ((name, value) in publicFields) {
|
||||||
|
if (first) first = false else append(",")
|
||||||
|
append("$name=${value.value.toString(scope)}")
|
||||||
|
}
|
||||||
|
append(")")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun inspect(scope: Scope): String {
|
||||||
|
return toString(scope).value
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun serialize(scope: Scope, encoder: LynonEncoder, lynonType: LynonType?) {
|
override suspend fun serialize(scope: Scope, encoder: LynonEncoder, lynonType: LynonType?) {
|
||||||
|
|||||||
@@ -158,6 +158,23 @@ val ObjIterable by lazy {
|
|||||||
ObjList(result)
|
ObjList(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addFnDoc(
|
||||||
|
name = "mapNotNull",
|
||||||
|
doc = "Transform elements by applying the given lambda unless it returns null.",
|
||||||
|
params = listOf(ParamDoc("transform")),
|
||||||
|
returns = type("lyng.List"),
|
||||||
|
isOpen = true,
|
||||||
|
moduleName = "lyng.stdlib"
|
||||||
|
) {
|
||||||
|
val fn = requiredArg<Statement>(0)
|
||||||
|
val result = mutableListOf<Obj>()
|
||||||
|
thisObj.toFlow(this).collect {
|
||||||
|
val transformed = fn.call(this, it)
|
||||||
|
if( transformed != ObjNull) result += transformed
|
||||||
|
}
|
||||||
|
ObjList(result)
|
||||||
|
}
|
||||||
|
|
||||||
addFnDoc(
|
addFnDoc(
|
||||||
name = "take",
|
name = "take",
|
||||||
doc = "Take the first N elements and return them as a list.",
|
doc = "Take the first N elements and return them as a list.",
|
||||||
|
|||||||
@@ -198,6 +198,18 @@ class ObjList(val list: MutableList<Obj> = mutableListOf()) : Obj() {
|
|||||||
return JsonArray(list.map { it.toJson(scope) })
|
return JsonArray(list.map { it.toJson(scope) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun toString(scope: Scope, calledFromLyng: Boolean): ObjString {
|
||||||
|
return ObjString(buildString {
|
||||||
|
append("[")
|
||||||
|
var first = true
|
||||||
|
for (v in list) {
|
||||||
|
if (first) first = false else append(",")
|
||||||
|
append(v.toString(scope).value)
|
||||||
|
}
|
||||||
|
append("]")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val type = object : ObjClass("List", ObjArray) {
|
val type = object : ObjClass("List", ObjArray) {
|
||||||
override suspend fun deserialize(scope: Scope, decoder: LynonDecoder, lynonType: LynonType?): Obj {
|
override suspend fun deserialize(scope: Scope, decoder: LynonDecoder, lynonType: LynonType?): Obj {
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class ObjMapEntry(val key: Obj, val value: Obj) : Obj() {
|
|||||||
else -> scope.raiseIndexOutOfBounds()
|
else -> scope.raiseIndexOutOfBounds()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override suspend fun toString(scope: Scope, calledFromLyng: Boolean): ObjString {
|
||||||
return "$key=>$value"
|
return ObjString("(${key.toString(scope).value} => ${value.toString(scope).value})")
|
||||||
}
|
}
|
||||||
|
|
||||||
override val objClass = type
|
override val objClass = type
|
||||||
|
|||||||
@@ -1625,7 +1625,7 @@ class ListLiteralRef(private val entries: List<ListEntry>) : ObjRef {
|
|||||||
when (elements) {
|
when (elements) {
|
||||||
is ObjList -> {
|
is ObjList -> {
|
||||||
// Grow underlying array once when possible
|
// Grow underlying array once when possible
|
||||||
if (list is ArrayList) list.ensureCapacity(list.size + elements.list.size)
|
list.ensureCapacity(list.size + elements.list.size)
|
||||||
list.addAll(elements.list)
|
list.addAll(elements.list)
|
||||||
}
|
}
|
||||||
else -> scope.raiseError("Spread element must be list")
|
else -> scope.raiseError("Spread element must be list")
|
||||||
|
|||||||
@@ -82,7 +82,14 @@ open class LynonDecoder(val bin: BitInput, val settings: LynonSettings = LynonSe
|
|||||||
if (it !is ObjClass)
|
if (it !is ObjClass)
|
||||||
scope.raiseClassCastError("Expected obj class but got ${it::class.simpleName}")
|
scope.raiseClassCastError("Expected obj class but got ${it::class.simpleName}")
|
||||||
it
|
it
|
||||||
} ?: scope.raiseSymbolNotFound("can't deserialize: not found type $className")
|
} ?: run {
|
||||||
|
val fallback = runCatching { scope.eval(className.value) }.getOrNull()
|
||||||
|
if (fallback != null) {
|
||||||
|
println("Fallback to eval successful")
|
||||||
|
fallback as ObjClass
|
||||||
|
}
|
||||||
|
else scope.raiseSymbolNotFound("can't deserialize: not found type $className")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun decodeAnyList(scope: Scope, fixedSize: Int? = null): MutableList<Obj> {
|
suspend fun decodeAnyList(scope: Scope, fixedSize: Int? = null): MutableList<Obj> {
|
||||||
|
|||||||
Reference in new issue
Block a user