Add base support for invoking custom functions (arguments' evaluating is still not supported)
This commit is contained in:
@@ -3,6 +3,8 @@ package io.smnp.callable.function
|
||||
import io.smnp.dsl.ast.model.node.FunctionDefinitionArgumentsNode
|
||||
import io.smnp.dsl.ast.model.node.FunctionDefinitionNode
|
||||
import io.smnp.dsl.ast.model.node.IdentifierNode
|
||||
import io.smnp.evaluation.evaluator.BlockEvaluator
|
||||
import io.smnp.evaluation.model.exception.Return
|
||||
import io.smnp.type.model.Value
|
||||
|
||||
object CustomFunction {
|
||||
@@ -13,10 +15,17 @@ object CustomFunction {
|
||||
override fun define(new: FunctionDefinitionTool) {
|
||||
val (_, argumentsNode, bodyNode) = node
|
||||
val signature = FunctionSignatureParser.parseSignature(argumentsNode as FunctionDefinitionArgumentsNode)
|
||||
val evaluator = BlockEvaluator()
|
||||
|
||||
new function signature define { env, args ->
|
||||
new function signature body { env, args ->
|
||||
val boundArguments = FunctionEnvironmentProvider.provideEnvironment(argumentsNode, args, env)
|
||||
// TODO(Implement bodyNode evaluation)
|
||||
// TODO push boundArguments to variables scope
|
||||
try {
|
||||
evaluator.evaluate(bodyNode, env)
|
||||
} catch(value: Return) {
|
||||
return@body value.value
|
||||
}
|
||||
|
||||
Value.void()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user