comparison 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
comparison
equal deleted inserted replaced
22067:e206ebd965f2 22068:fec8f8a61f6c
39 * SOFTWARE. 39 * SOFTWARE.
40 */ 40 */
41 package com.oracle.truffle.sl.nodes.expression; 41 package com.oracle.truffle.sl.nodes.expression;
42 42
43 import com.oracle.truffle.api.*; 43 import com.oracle.truffle.api.*;
44 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
44 import com.oracle.truffle.api.frame.*; 45 import com.oracle.truffle.api.frame.*;
45 import com.oracle.truffle.api.nodes.*; 46 import com.oracle.truffle.api.nodes.*;
46 import com.oracle.truffle.api.source.*; 47 import com.oracle.truffle.api.source.*;
47 import com.oracle.truffle.sl.SLLanguage; 48 import com.oracle.truffle.sl.SLLanguage;
48 import com.oracle.truffle.sl.nodes.*; 49 import com.oracle.truffle.sl.nodes.*;
55 * never changes. This is guaranteed by the {@link SLFunctionRegistry}. 56 * never changes. This is guaranteed by the {@link SLFunctionRegistry}.
56 */ 57 */
57 @NodeInfo(shortName = "func") 58 @NodeInfo(shortName = "func")
58 public final class SLFunctionLiteralNode extends SLExpressionNode { 59 public final class SLFunctionLiteralNode extends SLExpressionNode {
59 private final String value; 60 private final String value;
61 private final Node contextNode;
62 @CompilationFinal private SLFunction cachedFunction;
63 @CompilationFinal private SLContext cachedContext;
64
65
60 66
61 public SLFunctionLiteralNode(SourceSection src, String value) { 67 public SLFunctionLiteralNode(SourceSection src, String value) {
62 super(src); 68 super(src);
63 this.value = value; 69 this.value = value;
70 contextNode = SLLanguage.INSTANCE.createFindContextNode0();
71 adoptChildren();
64 } 72 }
65 73
66 @Override 74 @Override
67 public SLFunction executeGeneric(VirtualFrame frame) { 75 public SLFunction executeGeneric(VirtualFrame frame) {
68 return SLLanguage.INSTANCE.getContext().getFunctionRegistry().lookup(value); 76 SLContext context = SLLanguage.INSTANCE.findContext(contextNode, frame);
77 if (context != cachedContext) {
78 CompilerDirectives.transferToInterpreterAndInvalidate();
79 this.cachedContext = context;
80 this.cachedFunction = context.getFunctionRegistry().lookup(value);
81 }
82 return cachedFunction;
69 } 83 }
70 } 84 }