Mercurial > hg > truffle
diff truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java @ 22068:fec8f8a61f6c
Introducing FindContextNode
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 06 Aug 2015 17:22:35 +0200 |
parents | 78c3d3d8d86e |
children | d683f82dac22 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java Thu Aug 06 08:33:18 2015 +0200 +++ b/truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/expression/SLFunctionLiteralNode.java Thu Aug 06 17:22:35 2015 +0200 @@ -41,6 +41,7 @@ package com.oracle.truffle.sl.nodes.expression; import com.oracle.truffle.api.*; +import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; import com.oracle.truffle.api.frame.*; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.*; @@ -57,14 +58,27 @@ @NodeInfo(shortName = "func") public final class SLFunctionLiteralNode extends SLExpressionNode { private final String value; + private final Node contextNode; + @CompilationFinal private SLFunction cachedFunction; + @CompilationFinal private SLContext cachedContext; + + public SLFunctionLiteralNode(SourceSection src, String value) { super(src); this.value = value; + contextNode = SLLanguage.INSTANCE.createFindContextNode0(); + adoptChildren(); } @Override public SLFunction executeGeneric(VirtualFrame frame) { - return SLLanguage.INSTANCE.getContext().getFunctionRegistry().lookup(value); + SLContext context = SLLanguage.INSTANCE.findContext(contextNode, frame); + if (context != cachedContext) { + CompilerDirectives.transferToInterpreterAndInvalidate(); + this.cachedContext = context; + this.cachedFunction = context.getFunctionRegistry().lookup(value); + } + return cachedFunction; } }