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