comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java @ 22046:e7c2d36daf72

TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 30 Jul 2015 17:36:34 +0200
parents 09531c471176
children 6dd4ab4d76d3
comparison
equal deleted inserted replaced
22045:ffbc7f472438 22046:e7c2d36daf72
43 private static Accessor API; 43 private static Accessor API;
44 private static Accessor SPI; 44 private static Accessor SPI;
45 private static Accessor NODES; 45 private static Accessor NODES;
46 private static Accessor INSTRUMENT; 46 private static Accessor INSTRUMENT;
47 private static Accessor DEBUG; 47 private static Accessor DEBUG;
48 private static final ThreadLocal<TruffleVM> CURRENT_VM = new ThreadLocal<>();
48 49
49 static { 50 static {
50 TruffleLanguage lng = new TruffleLanguage(null) { 51 TruffleLanguage lng = new TruffleLanguage(null) {
51 @Override 52 @Override
52 protected Object eval(Source code) throws IOException {
53 return null;
54 }
55
56 @Override
57 protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { 53 protected Object findExportedSymbol(String globalName, boolean onlyExplicit) {
58 return null; 54 return null;
59 } 55 }
60 56
61 @Override 57 @Override
74 } 70 }
75 71
76 @Override 72 @Override
77 protected DebugSupportProvider getDebugSupport() { 73 protected DebugSupportProvider getDebugSupport() {
78 return null; 74 return null;
75 }
76
77 @Override
78 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException {
79 throw new IOException();
79 } 80 }
80 }; 81 };
81 lng.hashCode(); 82 lng.hashCode();
82 new Node(null) { 83 new Node(null) {
83 }.getRootNode(); 84 }.getRootNode();
160 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) { 161 protected Class<? extends TruffleLanguage> findLanguage(Probe probe) {
161 return INSTRUMENT.findLanguage(probe); 162 return INSTRUMENT.findLanguage(probe);
162 } 163 }
163 164
164 protected TruffleLanguage findLanguage(TruffleVM vm, Class<? extends TruffleLanguage> languageClass) { 165 protected TruffleLanguage findLanguage(TruffleVM vm, Class<? extends TruffleLanguage> languageClass) {
166 if (vm == null) {
167 vm = CURRENT_VM.get();
168 if (vm == null) {
169 throw new IllegalStateException();
170 }
171 }
165 return SPI.findLanguage(vm, languageClass); 172 return SPI.findLanguage(vm, languageClass);
166 } 173 }
167 174
168 protected Closeable executionStart(TruffleVM vm, Debugger[] fillIn, Source s) { 175 protected Closeable executionStart(TruffleVM vm, Debugger[] fillIn, Source s) {
169 return DEBUG.executionStart(vm, fillIn, s); 176 final Closeable debugClose = DEBUG.executionStart(vm, fillIn, s);
177 final TruffleVM prev = CURRENT_VM.get();
178 CURRENT_VM.set(vm);
179 class ContextCloseable implements Closeable {
180 @Override
181 public void close() throws IOException {
182 CURRENT_VM.set(prev);
183 debugClose.close();
184 }
185 }
186 return new ContextCloseable();
170 } 187 }
171 188
172 protected void dispatchEvent(TruffleVM vm, Object event) { 189 protected void dispatchEvent(TruffleVM vm, Object event) {
173 SPI.dispatchEvent(vm, event); 190 SPI.dispatchEvent(vm, event);
174 } 191 }