Create scaffolding for custom functions
This commit is contained in:
@@ -30,7 +30,7 @@ abstract class Function(val name: String) {
|
||||
.firstOrNull { (_, args) -> args.signatureMatched }
|
||||
?: throw FunctionInvocationException(this, arguments)
|
||||
|
||||
return definition.body(environment, arguments.toList())
|
||||
return definition.body(environment, args.arguments)
|
||||
}
|
||||
|
||||
val signature: String
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.smnp.data.entity
|
||||
|
||||
import io.smnp.data.enumeration.Pitch
|
||||
|
||||
class Note private constructor(val pitch: Pitch, val octave: Int, val duration: Int, val dot: Boolean) {
|
||||
data class Note (val pitch: Pitch, val octave: Int, val duration: Int, val dot: Boolean) {
|
||||
data class Builder(var pitch: Pitch = Pitch.A, var octave: Int = 4, var duration: Int = 4, var dot: Boolean = false) {
|
||||
fun pitch(pitch: Pitch) = apply { this.pitch = pitch }
|
||||
fun octave(octave: Int) = apply { this.octave = octave }
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.smnp.environment
|
||||
|
||||
import io.smnp.callable.function.Function
|
||||
import io.smnp.callable.method.Method
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
interface Environment {
|
||||
@@ -8,4 +10,6 @@ interface Environment {
|
||||
fun invokeFunction(name: String, arguments: List<Value>): Value
|
||||
fun invokeMethod(obj: Value, name: String, arguments: List<Value>): Value
|
||||
fun printCallStack()
|
||||
fun defineFunction(function: Function)
|
||||
fun defineMethod(method: Method)
|
||||
}
|
||||
@@ -32,8 +32,14 @@ class Module(
|
||||
}
|
||||
}
|
||||
|
||||
fun attachTo(module: Module) {
|
||||
module.addSubmodule(this)
|
||||
fun addFunction(function: Function) {
|
||||
function.module = this
|
||||
functions.add(function)
|
||||
}
|
||||
|
||||
fun addMethod(method: Method) {
|
||||
method.module = this
|
||||
methods.add(method)
|
||||
}
|
||||
|
||||
val canonicalName: String
|
||||
|
||||
Reference in New Issue
Block a user