Create smnp.lang package with basic get() methods for map and list

This commit is contained in:
2020-03-09 21:41:52 +01:00
parent 8ca966b376
commit 3c25833122
10 changed files with 82 additions and 24 deletions

View File

@@ -19,7 +19,7 @@ abstract class Function(val name: String) {
.firstOrNull { (_, args) -> args.signatureMatched }
?: throw FunctionInvocationException(this, arguments)
return definition.body(environment, args.arguments)
return definition.body(environment, arguments.toList())
}
val signature: String

View File

@@ -1,5 +1,6 @@
package io.smnp.environment
import io.smnp.ext.ModuleRegistry
import io.smnp.type.module.Module
class Environment {
@@ -7,7 +8,10 @@ class Environment {
private val loadedModules = mutableListOf<String>()
fun loadModule(path: String) {
ModuleRegistry.requestModulesForPath(path).forEach {
rootModule.addSubmodule(it)
loadedModules.add(path)
}
}
fun printModules(printContent: Boolean) {

View File

@@ -0,0 +1,3 @@
package io.smnp.error
class RuntimeException(message: String?) : Exception(message)

View File

@@ -0,0 +1,21 @@
package io.smnp.ext
import io.smnp.type.module.Module
import org.pf4j.DefaultPluginManager
object ModuleRegistry {
private val modules = mutableListOf<Pair<String, Module>>()
init {
val pluginManager = DefaultPluginManager()
pluginManager.loadPlugins()
pluginManager.startPlugins()
pluginManager.getExtensions(ModuleDefinition::class.java).forEach {
modules.add(Pair(it.modulePath(), Module.create(it.modulePath(), it.functions(), it.methods())))
}
}
fun requestModulesForPath(path: String): List<Module> {
return modules.filter { it.first == path }.map { it.second }
}
}

View File

@@ -4,7 +4,7 @@ import io.smnp.data.entity.Note
import io.smnp.error.ShouldNeverReachThisLineException
import io.smnp.type.enumeration.DataType
class Value private constructor(val type: DataType, val value: Any?, val properties: Map<String, Value> = emptyMap()) {
data class Value(val type: DataType, val value: Any?, val properties: Map<String, Value> = emptyMap()) {
init {
if(!type.isInstance(value)) {
throw RuntimeException("'$value' is not of type $type")