mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
evaluator: inherit fast cache for calls to functions in a function definition
This commit is contained in:
@ -4,7 +4,6 @@ import gay.pizza.pork.ast.*
|
||||
|
||||
class EvaluationVisitor(root: Scope) : NodeVisitor<Any> {
|
||||
private var currentScope: Scope = root
|
||||
private var insideFastCachePreservation = false
|
||||
|
||||
override fun visitIntLiteral(node: IntLiteral): Any = node.value
|
||||
override fun visitStringLiteral(node: StringLiteral): Any = node.text
|
||||
@ -29,7 +28,7 @@ class EvaluationVisitor(root: Scope) : NodeVisitor<Any> {
|
||||
|
||||
override fun visitLambda(node: Lambda): CallableFunction {
|
||||
return CallableFunction { arguments ->
|
||||
currentScope = currentScope.fork(inheritFastCache = insideFastCachePreservation)
|
||||
currentScope = currentScope.fork()
|
||||
for ((index, argumentSymbol) in node.arguments.withIndex()) {
|
||||
currentScope.define(argumentSymbol.id, arguments.values[index])
|
||||
}
|
||||
@ -105,7 +104,7 @@ class EvaluationVisitor(root: Scope) : NodeVisitor<Any> {
|
||||
override fun visitFunctionDefinition(node: FunctionDefinition): Any {
|
||||
val blockFunction = visitBlock(node.block) as BlockFunction
|
||||
val function = CallableFunction { arguments ->
|
||||
currentScope = currentScope.fork(inheritFastCache = insideFastCachePreservation)
|
||||
currentScope = currentScope.fork(inheritFastCache = true)
|
||||
currentScope.fastVariableCache.put(node.symbol.id, currentScope.value(node.symbol.id))
|
||||
for ((index, argumentSymbol) in node.arguments.withIndex()) {
|
||||
currentScope.define(argumentSymbol.id, arguments.values[index])
|
||||
|
Reference in New Issue
Block a user