Mercurial > hg > truffle
diff 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 |
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Thu Jul 30 17:16:59 2015 +0200 +++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/impl/Accessor.java Thu Jul 30 17:36:34 2015 +0200 @@ -45,15 +45,11 @@ private static Accessor NODES; private static Accessor INSTRUMENT; private static Accessor DEBUG; + private static final ThreadLocal<TruffleVM> CURRENT_VM = new ThreadLocal<>(); static { TruffleLanguage lng = new TruffleLanguage(null) { @Override - protected Object eval(Source code) throws IOException { - return null; - } - - @Override protected Object findExportedSymbol(String globalName, boolean onlyExplicit) { return null; } @@ -77,6 +73,11 @@ protected DebugSupportProvider getDebugSupport() { return null; } + + @Override + protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { + throw new IOException(); + } }; lng.hashCode(); new Node(null) { @@ -162,11 +163,27 @@ } protected TruffleLanguage findLanguage(TruffleVM vm, Class<? extends TruffleLanguage> languageClass) { + if (vm == null) { + vm = CURRENT_VM.get(); + if (vm == null) { + throw new IllegalStateException(); + } + } return SPI.findLanguage(vm, languageClass); } protected Closeable executionStart(TruffleVM vm, Debugger[] fillIn, Source s) { - return DEBUG.executionStart(vm, fillIn, s); + final Closeable debugClose = DEBUG.executionStart(vm, fillIn, s); + final TruffleVM prev = CURRENT_VM.get(); + CURRENT_VM.set(vm); + class ContextCloseable implements Closeable { + @Override + public void close() throws IOException { + CURRENT_VM.set(prev); + debugClose.close(); + } + } + return new ContextCloseable(); } protected void dispatchEvent(TruffleVM vm, Object event) {