comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleLanguage.java @ 21716:2f9e4d984d16

Give languages a chance to do implicit exports. Prefer explicit exports over implicit ones.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 04 Jun 2015 08:08:05 +0200
parents 1c76a5662753
children 45083be8a812
comparison
equal deleted inserted replaced
21715:67e28e817d32 21716:2f9e4d984d16
94 * Called when some other language is seeking for a global symbol. This method is supposed to do 94 * Called when some other language is seeking for a global symbol. This method is supposed to do
95 * lazy binding, e.g. there is no need to export symbols in advance, it is fine to wait until 95 * lazy binding, e.g. there is no need to export symbols in advance, it is fine to wait until
96 * somebody asks for it (by calling this method). 96 * somebody asks for it (by calling this method).
97 * <p> 97 * <p>
98 * The exported object can either be <code>TruffleObject</code> (e.g. a native object from the 98 * The exported object can either be <code>TruffleObject</code> (e.g. a native object from the
99 * other language) to support interoperability between languages or one of Java primitive 99 * other language) to support inter-operability between languages, {@link String} or one of Java
100 * wrappers ( {@link Integer}, {@link Double}, {@link Short}, etc.). 100 * primitive wrappers ( {@link Integer}, {@link Double}, {@link Short}, {@link Boolean}, etc.).
101 * <p>
102 * The way a symbol becomes <em>exported</em> is language dependant. In general it is preferred
103 * to make the export explicit - e.g. call some function or method to register an object under
104 * specific name. Some languages may however decide to support implicit export of symbols (for
105 * example from global scope, if they have one). However explicit exports should always be
106 * preferred. Implicitly exported object of some name should only be used when there is no
107 * explicit export under such <code>globalName</code>. To ensure so the infrastructure first
108 * asks all known languages for <code>onlyExplicit</code> symbols and only when none is found,
109 * it does one more round with <code>onlyExplicit</code> set to <code>false</code>.
101 * 110 *
102 * @param globalName the name of the global symbol to find 111 * @param globalName the name of the global symbol to find
112 * @param onlyExplicit should the language seek for implicitly exported object or only consider
113 * the explicitly exported ones?
103 * @return an exported object or <code>null</code>, if the symbol does not represent anything 114 * @return an exported object or <code>null</code>, if the symbol does not represent anything
104 * meaningful in this language 115 * meaningful in this language
105 */ 116 */
106 protected abstract Object findExportedSymbol(String globalName); 117 protected abstract Object findExportedSymbol(String globalName, boolean onlyExplicit);
107 118
108 /** 119 /**
109 * Returns global object for the language. 120 * Returns global object for the language.
110 * <p> 121 * <p>
111 * The object is expected to be <code>TruffleObject</code> (e.g. a native object from the other 122 * The object is expected to be <code>TruffleObject</code> (e.g. a native object from the other
208 protected Object eval(TruffleLanguage l, Source s) throws IOException { 219 protected Object eval(TruffleLanguage l, Source s) throws IOException {
209 return l.eval(s); 220 return l.eval(s);
210 } 221 }
211 222
212 @Override 223 @Override
213 protected Object findExportedSymbol(TruffleLanguage l, String globalName) { 224 protected Object findExportedSymbol(TruffleLanguage l, String globalName, boolean onlyExplicit) {
214 return l.findExportedSymbol(globalName); 225 return l.findExportedSymbol(globalName, onlyExplicit);
215 } 226 }
216 227
217 @Override 228 @Override
218 protected Object languageGlobal(TruffleLanguage l) { 229 protected Object languageGlobal(TruffleLanguage l) {
219 return l.getLanguageGlobal(); 230 return l.getLanguageGlobal();