Skip to content

Commit

Permalink
evaluator: inherit fast cache for calls to functions in a function de…
Browse files Browse the repository at this point in the history
…finition
  • Loading branch information
azenla committed Sep 5, 2023
1 parent 65f61fc commit 2631b67
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
}
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 2631b67

Please sign in to comment.