Native for all

This commit is contained in:
Alexander Nozik 2020-09-14 20:32:41 +03:00
parent 4ab9751bea
commit bc4456637c
18 changed files with 59 additions and 22 deletions

1
.gitignore vendored
View File

@ -7,4 +7,3 @@ build/
!gradle-wrapper.jar
gradle.properties

View File

@ -47,7 +47,7 @@ public open class Context(
/**
* A [PluginManager] for current context
*/
public val plugins: PluginManager by lazy { PluginManager(this) }
public val plugins: PluginManager = PluginManager(this)
@Deprecated("To be removed in favor of immutable plugins")
private val activators = HashSet<Any>()

View File

@ -5,10 +5,12 @@ import hep.dataforge.names.asName
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob
import kotlin.coroutines.CoroutineContext
import kotlin.native.concurrent.ThreadLocal
/**
* A global root context. Closing [Global] terminates the framework.
*/
@ThreadLocal
public object Global : Context("GLOBAL".asName(), null, Meta.EMPTY) {
override val coroutineContext: CoroutineContext = GlobalScope.coroutineContext + SupervisorJob()
@ -39,6 +41,8 @@ public object Global : Context("GLOBAL".asName(), null, Meta.EMPTY) {
}
public fun context(name: String, parent: Context = this, block: ContextBuilder.() -> Unit = {}): Context =
ContextBuilder(parent, name).apply(block).build()
ContextBuilder(parent, name).apply(block).build().also {
contextRegistry[name] = it
}
}

View File

@ -21,8 +21,11 @@ class ContextTest {
@Test
fun testPluginManager() {
Global.plugins.load(DummyPlugin())
val members = Global.gather<Name>("test")
val context = Global.context("test"){
plugin(DummyPlugin())
}
//Global.plugins.load(DummyPlugin())
val members = context.gather<Name>("test")
assertEquals(3, members.count())
members.forEach {
assertEquals(it.key, it.value.appendLeft("test"))

View File

@ -1,7 +1,7 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.node")
// id("ru.mipt.npm.native")
id("ru.mipt.npm.native")
}
kscience{

View File

@ -28,7 +28,7 @@ public class DataFilter : Scheme() {
/**
* Apply meta-based filter to given data node
*/
fun <T : Any> DataNode<T>.filter(filter: DataFilter): DataNode<T> {
public fun <T : Any> DataNode<T>.filter(filter: DataFilter): DataNode<T> {
val sourceNode = filter.from?.let { get(it.toName()).node } ?: this@filter
val regex = filter.pattern.toRegex()
val targetNode = DataTreeBuilder(type).apply {
@ -46,10 +46,10 @@ fun <T : Any> DataNode<T>.filter(filter: DataFilter): DataNode<T> {
/**
* Filter data using [DataFilter] specification
*/
fun <T : Any> DataNode<T>.filter(filter: Meta): DataNode<T> = filter(DataFilter.wrap(filter))
public fun <T : Any> DataNode<T>.filter(filter: Meta): DataNode<T> = filter(DataFilter.wrap(filter))
/**
* Filter data using [DataFilter] builder
*/
fun <T : Any> DataNode<T>.filter(filterBuilder: DataFilter.() -> Unit): DataNode<T> =
public fun <T : Any> DataNode<T>.filter(filterBuilder: DataFilter.() -> Unit): DataNode<T> =
filter(DataFilter(filterBuilder))

View File

@ -6,11 +6,9 @@ import kotlin.reflect.KClass
* Check that node is compatible with given type meaning that each element could be cast to the type
*/
internal actual fun <R : Any> DataNode<*>.canCast(type: KClass<out R>): Boolean {
//Not supported in js yet
return true
return this.type == type
}
internal actual fun <R : Any> Data<*>.canCast(type: KClass<out R>): Boolean {
//Not supported in js yet
return true
return this.type == type
}

View File

@ -0,0 +1,14 @@
package hep.dataforge.data
import kotlin.reflect.KClass
/**
* Check that node is compatible with given type meaning that each element could be cast to the type
*/
internal actual fun <R : Any> DataNode<*>.canCast(type: KClass<out R>): Boolean {
return this.type == type
}
internal actual fun <R : Any> Data<*>.canCast(type: KClass<out R>): Boolean {
return this.type == type
}

View File

@ -1,7 +1,7 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.node")
// id("ru.mipt.npm.native")
id("ru.mipt.npm.native")
}
description = "IO module"
@ -12,7 +12,7 @@ kscience {
}
}
val ioVersion by rootProject.extra("0.2.0-npm-dev-10")
val ioVersion by rootProject.extra("0.2.0-npm-dev-11")
kotlin {
sourceSets {

View File

@ -48,8 +48,10 @@ class MetaSerializerTest {
assertEquals(name, restored)
}
@OptIn(ExperimentalSerializationApi::class)
@Test
fun testMetaItemDescriptor() {
val descriptor = MetaItem.serializer(MetaSerializer).descriptor.getElementDescriptor(0)
println(descriptor)
}
}

View File

@ -138,8 +138,8 @@ public inline class MetaTransformation(public val transformations: Collection<Tr
}
}
companion object {
fun make(block: MetaTransformationBuilder.() -> Unit): MetaTransformation =
public companion object {
public fun make(block: MetaTransformationBuilder.() -> Unit): MetaTransformation =
MetaTransformationBuilder().apply(block).build()
}
}

View File

@ -1,7 +1,7 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.node")
// id("ru.mipt.npm.native")
id("ru.mipt.npm.native")
}
kotlin {

View File

@ -0,0 +1,6 @@
package hep.dataforge.output
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
public actual val Dispatchers.Output: CoroutineDispatcher get() = Dispatchers.Default

View File

@ -1,5 +1,7 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.node")
id("ru.mipt.npm.native")
}
kotlin {

View File

@ -1,5 +1,7 @@
plugins {
id("ru.mipt.npm.mpp")
id("ru.mipt.npm.node")
id("ru.mipt.npm.native")
}
kotlin {

View File

@ -49,6 +49,6 @@ public interface Task<out R : Any> : Named, Described {
public fun run(workspace: Workspace, model: TaskModel): DataNode<R>
public companion object {
public const val TYPE = "task"
public const val TYPE: String = "task"
}
}

View File

@ -46,7 +46,7 @@ public data class TaskModel(
}
public companion object {
public val MODEL_TARGET_KEY = "@target".asName()
public val MODEL_TARGET_KEY: Name = "@target".asName()
}
}

7
gradle.properties Normal file
View File

@ -0,0 +1,7 @@
kotlin.code.style=official
kotlin.parallel.tasks.in.project=true
kotlin.mpp.enableGranularSourceSetsMetadata=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m
org.gradle.parallel=true
systemProp.org.gradle.internal.publish.checksums.insecure=true