Enable passing arguments to custom functions

This commit is contained in:
2020-03-11 22:16:29 +01:00
parent 7d61756273
commit 53bba579c1
11 changed files with 110 additions and 32 deletions

View File

@@ -15,15 +15,18 @@ object CustomFunction {
override fun define(new: FunctionDefinitionTool) {
val (_, argumentsNode, bodyNode) = node
val signature = FunctionSignatureParser.parseSignature(argumentsNode as FunctionDefinitionArgumentsNode)
val evaluator = BlockEvaluator()
val evaluator = BlockEvaluator(dedicatedScope = false)
new function signature body { env, args ->
val boundArguments = FunctionEnvironmentProvider.provideEnvironment(argumentsNode, args, env)
// TODO push boundArguments to variables scope
try {
env.pushScope(boundArguments.toMutableMap())
evaluator.evaluate(bodyNode, env)
} catch(value: Return) {
return@body value.value
} finally {
env.popScope()
}
Value.void()