Create some new standard library modules
This commit is contained in:
0
modules/collection/build.gradle
Normal file
0
modules/collection/build.gradle
Normal file
7
modules/collection/gradle.properties
Normal file
7
modules/collection/gradle.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
version=0.0.1
|
||||
|
||||
pluginVersion=0.1
|
||||
pluginId=smnp.collection
|
||||
pluginClass=
|
||||
pluginProvider=Bartłomiej Pluta
|
||||
pluginDependencies=
|
||||
@@ -0,0 +1,9 @@
|
||||
package io.smnp.ext
|
||||
|
||||
import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class CollectionModule : LanguageModuleProvider("smnp.collection") {
|
||||
override fun files() = listOf("list.mus")
|
||||
override fun dependencies() = listOf("smnp.lang")
|
||||
}
|
||||
15
modules/collection/src/main/resources/list.mus
Normal file
15
modules/collection/src/main/resources/list.mus
Normal file
@@ -0,0 +1,15 @@
|
||||
function flatten(...lists: list) {
|
||||
return _flatten(lists as list ^ _flatten(list, []), []);
|
||||
}
|
||||
|
||||
function _flatten(list: list, output: list) {
|
||||
list as element ^ {
|
||||
if (typeOf(element) == "list") {
|
||||
output = _flatten(element, output);
|
||||
} else {
|
||||
output = output + [element];
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
0
modules/debug/build.gradle
Normal file
0
modules/debug/build.gradle
Normal file
7
modules/debug/gradle.properties
Normal file
7
modules/debug/gradle.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
version=0.0.1
|
||||
|
||||
pluginVersion=0.1
|
||||
pluginId=smnp.lang.debug
|
||||
pluginClass=
|
||||
pluginProvider=Bartłomiej Pluta
|
||||
pluginDependencies=
|
||||
9
modules/debug/src/main/kotlin/io/smnp/ext/DebugModule.kt
Normal file
9
modules/debug/src/main/kotlin/io/smnp/ext/DebugModule.kt
Normal file
@@ -0,0 +1,9 @@
|
||||
package io.smnp.ext
|
||||
|
||||
import io.smnp.ext.function.CallStackFunction
|
||||
import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class DebugModule : NativeModuleProvider("smnp.lang.debug") {
|
||||
override fun functions() = listOf(CallStackFunction())
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.smnp.ext.function
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class CallStackFunction : Function("callstack") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function Signature.simple() body { env, _ ->
|
||||
env.printCallStack()
|
||||
Value.void()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package io.smnp.ext.lang
|
||||
|
||||
import io.smnp.ext.NativeModuleProvider
|
||||
import io.smnp.ext.lang.function.DebugFunction
|
||||
import io.smnp.ext.lang.function.TypeOfFunction
|
||||
import io.smnp.ext.lang.method.ListAccessMethod
|
||||
import io.smnp.ext.lang.method.MapAccessMethod
|
||||
import org.pf4j.Extension
|
||||
|
||||
@Extension
|
||||
class LangModule : NativeModuleProvider("smnp.lang") {
|
||||
override fun functions() = listOf(DebugFunction())
|
||||
override fun functions() = listOf(TypeOfFunction())
|
||||
override fun methods() = listOf(ListAccessMethod(), MapAccessMethod())
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package io.smnp.ext.lang.function
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class DebugFunction : Function("debug") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple() body { env, _ ->
|
||||
env.printCallStack()
|
||||
Value.void()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package io.smnp.ext.lang.function
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.function.FunctionDefinitionTool
|
||||
import io.smnp.callable.signature.Signature.Companion.simple
|
||||
import io.smnp.type.matcher.Matcher.Companion.allTypes
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
class TypeOfFunction : Function("typeOf") {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
new function simple(allTypes()) body { _, (obj) ->
|
||||
Value.string(obj.type.toString()) // TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,4 +4,6 @@ include 'app'
|
||||
include 'modules'
|
||||
|
||||
include 'modules:lang'
|
||||
include 'modules:io'
|
||||
include 'modules:debug'
|
||||
include 'modules:io'
|
||||
include 'modules:collection'
|
||||
Reference in New Issue
Block a user