Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/vm/TruffleVM.java @ 22104:cf19259edf87
TruffleVM.eval and Source.withMimeType
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 24 Aug 2015 08:46:21 +0200 |
parents | 2a22cec84114 |
children | b5eaddcdf86a |
comparison
equal
deleted
inserted
replaced
22103:7646278cca8a | 22104:cf19259edf87 |
---|---|
342 * | 342 * |
343 * @param location the location of a file to execute | 343 * @param location the location of a file to execute |
344 * @return result of a processing the file, possibly <code>null</code> | 344 * @return result of a processing the file, possibly <code>null</code> |
345 * @throws IOException exception to signal I/O problems or problems with processing the file's | 345 * @throws IOException exception to signal I/O problems or problems with processing the file's |
346 * content | 346 * content |
347 */ | 347 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
348 */ | |
349 @Deprecated | |
348 public Object eval(URI location) throws IOException { | 350 public Object eval(URI location) throws IOException { |
349 checkThread(); | 351 checkThread(); |
350 Source s; | 352 Source s; |
351 String mimeType; | 353 String mimeType; |
352 if (location.getScheme().equals("file")) { | 354 if (location.getScheme().equals("file")) { |
380 * | 382 * |
381 * @param mimeType MIME type of the code snippet - chooses the right language | 383 * @param mimeType MIME type of the code snippet - chooses the right language |
382 * @param reader the source of code snippet to execute | 384 * @param reader the source of code snippet to execute |
383 * @return result of an execution, possibly <code>null</code> | 385 * @return result of an execution, possibly <code>null</code> |
384 * @throws IOException thrown to signal errors while processing the code | 386 * @throws IOException thrown to signal errors while processing the code |
385 */ | 387 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
388 */ | |
389 @Deprecated | |
386 public Object eval(String mimeType, Reader reader) throws IOException { | 390 public Object eval(String mimeType, Reader reader) throws IOException { |
387 checkThread(); | 391 checkThread(); |
388 TruffleLanguage<?> l = getTruffleLang(mimeType); | 392 TruffleLanguage<?> l = getTruffleLang(mimeType); |
389 if (l == null) { | 393 if (l == null) { |
390 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); | 394 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
398 * | 402 * |
399 * @param mimeType MIME type of the code snippet - chooses the right language | 403 * @param mimeType MIME type of the code snippet - chooses the right language |
400 * @param code the code snippet to execute | 404 * @param code the code snippet to execute |
401 * @return result of an execution, possibly <code>null</code> | 405 * @return result of an execution, possibly <code>null</code> |
402 * @throws IOException thrown to signal errors while processing the code | 406 * @throws IOException thrown to signal errors while processing the code |
403 */ | 407 * @deprecated use {@link #eval(com.oracle.truffle.api.source.Source)} |
408 */ | |
409 @Deprecated | |
404 public Object eval(String mimeType, String code) throws IOException { | 410 public Object eval(String mimeType, String code) throws IOException { |
405 checkThread(); | 411 checkThread(); |
406 TruffleLanguage<?> l = getTruffleLang(mimeType); | 412 TruffleLanguage<?> l = getTruffleLang(mimeType); |
407 if (l == null) { | 413 if (l == null) { |
408 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); | 414 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); |
409 } | 415 } |
410 return eval(l, Source.fromText(code, mimeType)); | 416 return eval(l, Source.fromText(code, mimeType)); |
417 } | |
418 | |
419 /** | |
420 * Evaluates provided source. Chooses language registered for a particular | |
421 * {@link Source#getMimeType() MIME type} (throws {@link IOException} if there is none). The | |
422 * language is then allowed to parse and execute the source. | |
423 * | |
424 * @param source code snippet to execute | |
425 * @return result of an execution, possibly <code>null</code> | |
426 * @throws IOException thrown to signal errors while processing the code | |
427 */ | |
428 public Object eval(Source source) throws IOException { | |
429 String mimeType = source.getMimeType(); | |
430 checkThread(); | |
431 TruffleLanguage<?> l = getTruffleLang(mimeType); | |
432 if (l == null) { | |
433 throw new IOException("No language for MIME type " + mimeType + " found. Supported types: " + langs.keySet()); | |
434 } | |
435 return eval(l, source); | |
411 } | 436 } |
412 | 437 |
413 private Object eval(TruffleLanguage<?> l, Source s) throws IOException { | 438 private Object eval(TruffleLanguage<?> l, Source s) throws IOException { |
414 TruffleVM.findDebuggerSupport(l); | 439 TruffleVM.findDebuggerSupport(l); |
415 Debugger[] fillIn = {debugger}; | 440 Debugger[] fillIn = {debugger}; |