comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 22219:1c0f490984d5

Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 16 Sep 2015 15:36:22 -0700
parents dc83cc1f94f2 d3bdaa91bc82
children 20380d1d41f2
comparison
equal deleted inserted replaced
22160:0599e2df6a9f 22219:1c0f490984d5
22 * or visit www.oracle.com if you need additional information or have any 22 * or visit www.oracle.com if you need additional information or have any
23 * questions. 23 * questions.
24 */ 24 */
25 package com.oracle.truffle.api; 25 package com.oracle.truffle.api;
26 26
27 import com.oracle.truffle.api.debug.DebugSupportProvider;
28 import com.oracle.truffle.api.impl.Accessor;
29 import com.oracle.truffle.api.impl.FindContextNode;
30 import com.oracle.truffle.api.instrument.ToolSupportProvider;
31 import com.oracle.truffle.api.nodes.Node;
32 import com.oracle.truffle.api.source.Source;
33 import java.io.IOException; 27 import java.io.IOException;
34 import java.io.Reader; 28 import java.io.Reader;
35 import java.io.Writer; 29 import java.io.Writer;
36 import java.lang.annotation.ElementType; 30 import java.lang.annotation.ElementType;
37 import java.lang.annotation.Retention; 31 import java.lang.annotation.Retention;
38 import java.lang.annotation.RetentionPolicy; 32 import java.lang.annotation.RetentionPolicy;
39 import java.lang.annotation.Target; 33 import java.lang.annotation.Target;
40 import java.util.Collections; 34 import java.util.Collections;
41 import java.util.Map; 35 import java.util.Map;
42 import java.util.WeakHashMap; 36 import java.util.WeakHashMap;
37
38 import com.oracle.truffle.api.debug.DebugSupportProvider;
39 import com.oracle.truffle.api.frame.MaterializedFrame;
40 import com.oracle.truffle.api.impl.Accessor;
41 import com.oracle.truffle.api.impl.FindContextNode;
42 import com.oracle.truffle.api.instrument.ASTProber;
43 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener;
44 import com.oracle.truffle.api.instrument.AdvancedInstrumentRoot;
45 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory;
46 import com.oracle.truffle.api.instrument.Instrument;
47 import com.oracle.truffle.api.instrument.ToolSupportProvider;
48 import com.oracle.truffle.api.instrument.Visualizer;
49 import com.oracle.truffle.api.nodes.Node;
50 import com.oracle.truffle.api.source.Source;
43 51
44 /** 52 /**
45 * An entry point for everyone who wants to implement a Truffle based language. By providing an 53 * An entry point for everyone who wants to implement a Truffle based language. By providing an
46 * implementation of this type and registering it using {@link Registration} annotation, your 54 * implementation of this type and registering it using {@link Registration} annotation, your
47 * language becomes accessible to users of the {@link com.oracle.truffle.api.vm.TruffleVM Truffle 55 * language becomes accessible to users of the {@link com.oracle.truffle.api.vm.TruffleVM Truffle
177 * @param object the object to check 185 * @param object the object to check
178 * @return <code>true</code> if this language can deal with such object in native way 186 * @return <code>true</code> if this language can deal with such object in native way
179 */ 187 */
180 protected abstract boolean isObjectOfLanguage(Object object); 188 protected abstract boolean isObjectOfLanguage(Object object);
181 189
190 @Deprecated
182 protected abstract ToolSupportProvider getToolSupport(); 191 protected abstract ToolSupportProvider getToolSupport();
183 192
193 @Deprecated
184 protected abstract DebugSupportProvider getDebugSupport(); 194 protected abstract DebugSupportProvider getDebugSupport();
195
196 /**
197 * Gets visualization services for language-specific information.
198 */
199 protected abstract Visualizer getVisualizer();
200
201 /**
202 * Enables AST probing on all subsequently created ASTs (sources parsed).
203 *
204 * @param astProber optional AST prober to enable; the default for the language used if
205 * {@code null}
206 */
207 @Deprecated
208 protected abstract void enableASTProbing(ASTProber astProber);
209
210 /**
211 * Gets the current specification for AST instrumentation for the language.
212 */
213 protected abstract ASTProber getDefaultASTProber();
214
215 /**
216 * Runs source code in a halted execution context, or at top level.
217 *
218 * @param source the code to run
219 * @param node node where execution halted, {@code null} if no execution context
220 * @param mFrame frame where execution halted, {@code null} if no execution context
221 * @return result of running the code in the context, or at top level if no execution context.
222 * @throws IOException if the evaluation cannot be performed
223 */
224 protected abstract Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException;
225
226 /**
227 * Creates a language-specific factory to produce instances of {@link AdvancedInstrumentRoot}
228 * that, when executed, computes the result of a textual expression in the language; used to
229 * create an
230 * {@linkplain Instrument#create(AdvancedInstrumentResultListener, AdvancedInstrumentRootFactory, Class, String)
231 * Advanced Instrument}.
232 *
233 * @param expr a guest language expression
234 * @param resultListener optional listener for the result of each evaluation.
235 * @return a new factory
236 * @throws IOException if the factory cannot be created, for example if the expression is badly
237 * formed.
238 */
239 protected abstract AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws IOException;
185 240
186 /** 241 /**
187 * Allows a language implementor to create a node that can effectively lookup up the context 242 * Allows a language implementor to create a node that can effectively lookup up the context
188 * associated with current execution. The context is created by 243 * associated with current execution. The context is created by
189 * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method. 244 * {@link #createContext(com.oracle.truffle.api.TruffleLanguage.Env)} method.
336 throw new IOException(ex); 391 throw new IOException(ex);
337 } 392 }
338 } 393 }
339 394
340 @Override 395 @Override
396 protected AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(Object vm, Class<? extends TruffleLanguage> languageClass, String expr,
397 AdvancedInstrumentResultListener resultListener) throws IOException {
398
399 final TruffleLanguage language = findLanguageImpl(vm, languageClass);
400 return language.createAdvancedInstrumentRootFactory(expr, resultListener);
401 }
402
403 @Override
341 protected Object findExportedSymbol(TruffleLanguage.Env env, String globalName, boolean onlyExplicit) { 404 protected Object findExportedSymbol(TruffleLanguage.Env env, String globalName, boolean onlyExplicit) {
342 return env.langCtx.findExportedSymbol(globalName, onlyExplicit); 405 return env.langCtx.findExportedSymbol(globalName, onlyExplicit);
343 } 406 }
344 407
345 @Override 408 @Override
361 protected Object findContext(Env env) { 424 protected Object findContext(Env env) {
362 return env.langCtx.ctx; 425 return env.langCtx.ctx;
363 } 426 }
364 427
365 @Override 428 @Override
429 protected ASTProber getDefaultASTProber(TruffleLanguage language) {
430 return language.getDefaultASTProber();
431 }
432
433 @SuppressWarnings("deprecation")
434 @Override
366 protected ToolSupportProvider getToolSupport(TruffleLanguage<?> l) { 435 protected ToolSupportProvider getToolSupport(TruffleLanguage<?> l) {
367 return l.getToolSupport(); 436 return l.getToolSupport();
368 } 437 }
369 438
439 @SuppressWarnings("deprecation")
370 @Override 440 @Override
371 protected DebugSupportProvider getDebugSupport(TruffleLanguage<?> l) { 441 protected DebugSupportProvider getDebugSupport(TruffleLanguage<?> l) {
372 return l.getDebugSupport(); 442 return l.getDebugSupport();
373 } 443 }
374 } 444 }