Add support for function/methods invocation on Environment + create call stack model

This commit is contained in:
2020-03-10 21:57:21 +01:00
parent 82e86ebc6a
commit d29ef61245
10 changed files with 163 additions and 18 deletions

View File

@@ -2,10 +2,21 @@ package io.smnp.callable.function
import io.smnp.environment.Environment
import io.smnp.error.FunctionInvocationException
import io.smnp.error.RuntimeException
import io.smnp.type.model.Value
import io.smnp.type.module.Module
abstract class Function(val name: String) {
private var definitions: List<FunctionDefinition> = mutableListOf()
private var _module: Module? = null
var module: Module
get() = _module ?: throw RuntimeException("Method has not set module yet")
set(value) {
if (_module != null) {
throw RuntimeException("Module of method is already set to ${module.canonicalName}")
}
_module = value
}
abstract fun define(new: FunctionDefinitionTool)

View File

@@ -2,11 +2,22 @@ package io.smnp.callable.method
import io.smnp.environment.Environment
import io.smnp.error.MethodInvocationException
import io.smnp.error.RuntimeException
import io.smnp.type.matcher.Matcher
import io.smnp.type.model.Value
import io.smnp.type.module.Module
abstract class Method(val typeMatcher: Matcher, val name: String) {
private var definitions: List<MethodDefinition> = mutableListOf()
private var _module: Module? = null
var module: Module
get() = _module ?: throw RuntimeException("Method has not set module yet")
set(value) {
if (_module != null) {
throw RuntimeException("Module of method is already set to ${module.canonicalName}")
}
_module = value
}
abstract fun define(new: MethodDefinitionTool)

View File

@@ -4,6 +4,10 @@ import io.smnp.type.enumeration.DataType
import io.smnp.type.model.Value
object ActualSignatureFormatter {
fun format(value: Value): String {
return format(arrayOf(value), false)
}
fun format(arguments: Array<out Value>, parentheses: Boolean = true): String {
val output = mutableListOf<String>()
for(argument in arguments) {