This commit is contained in:
sergeych committed 2025-08-07 21:46:45 +03:00
1 parent 19f8b6605b
commit 0f54e2f845
6 files changed
+54 -28

No files matched your search

@@ -1,6 +1,7 @@
package net.sergeych.lyng
import kotlinx.coroutines.delay
import kotlinx.coroutines.yield
import net.sergeych.lyng.obj.*
import net.sergeych.lyng.pacman.ImportManager
import net.sergeych.lynon.ObjLynonClass
@@ -187,6 +188,11 @@ class Script(
})
}
addFn("yield") {
yield()
ObjVoid
}
val pi = ObjReal(PI)
addConst("π", pi)
@@ -1,10 +1,7 @@
package net.sergeych.lyng.obj
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.sergeych.lyng.Scope
import net.sergeych.lyng.Statement
open class ObjDeferred(val deferred: Deferred<Obj>): Obj() {
@@ -33,19 +30,3 @@ open class ObjDeferred(val deferred: Deferred<Obj>): Obj() {
}
}
class ObjMutex(val mutex: Mutex): Obj() {
override val objClass = type
companion object {
val type = object: ObjClass("Mutex") {
override suspend fun callOn(scope: Scope): Obj {
return ObjMutex(Mutex())
}
}.apply {
addFn("withLock") {
val f = requiredArg<Statement>(0)
thisAs<ObjMutex>().mutex.withLock { f.execute(this) }
}
}
}
}
@@ -0,0 +1,23 @@
package net.sergeych.lyng.obj
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import net.sergeych.lyng.Scope
import net.sergeych.lyng.Statement
class ObjMutex(val mutex: Mutex): Obj() {
override val objClass = type
companion object {
val type = object: ObjClass("Mutex") {
override suspend fun callOn(scope: Scope): Obj {
return ObjMutex(Mutex())
}
}.apply {
addFn("withLock") {
val f = requiredArg<Statement>(0)
thisAs<ObjMutex>().mutex.withLock { f.execute(this) }
}
}
}
}