comparison truffle/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLLanguage.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
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39 * SOFTWARE. 39 * SOFTWARE.
40 */ 40 */
41 package com.oracle.truffle.sl; 41 package com.oracle.truffle.sl;
42 42
43 import java.io.BufferedReader;
44 import java.io.IOException;
45 import java.io.InputStreamReader;
46 import java.io.PrintWriter;
47 import java.math.BigInteger;
48 import java.nio.file.Path;
49 import java.util.Collections;
50 import java.util.List;
51
43 import com.oracle.truffle.api.CallTarget; 52 import com.oracle.truffle.api.CallTarget;
44 import com.oracle.truffle.api.RootCallTarget; 53 import com.oracle.truffle.api.RootCallTarget;
45 import com.oracle.truffle.api.Truffle; 54 import com.oracle.truffle.api.Truffle;
46 import com.oracle.truffle.api.TruffleLanguage; 55 import com.oracle.truffle.api.TruffleLanguage;
47 import com.oracle.truffle.api.debug.DebugSupportException;
48 import com.oracle.truffle.api.debug.DebugSupportProvider; 56 import com.oracle.truffle.api.debug.DebugSupportProvider;
49 import com.oracle.truffle.api.dsl.NodeFactory; 57 import com.oracle.truffle.api.dsl.NodeFactory;
50 import com.oracle.truffle.api.dsl.UnsupportedSpecializationException; 58 import com.oracle.truffle.api.dsl.UnsupportedSpecializationException;
51 import com.oracle.truffle.api.frame.MaterializedFrame; 59 import com.oracle.truffle.api.frame.MaterializedFrame;
52 import com.oracle.truffle.api.instrument.ASTProber; 60 import com.oracle.truffle.api.instrument.ASTProber;
53 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener; 61 import com.oracle.truffle.api.instrument.AdvancedInstrumentResultListener;
54 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory; 62 import com.oracle.truffle.api.instrument.AdvancedInstrumentRootFactory;
55 import com.oracle.truffle.api.instrument.Probe;
56 import com.oracle.truffle.api.instrument.ToolSupportProvider; 63 import com.oracle.truffle.api.instrument.ToolSupportProvider;
57 import com.oracle.truffle.api.instrument.Visualizer; 64 import com.oracle.truffle.api.instrument.Visualizer;
58 import com.oracle.truffle.api.nodes.GraphPrintVisitor; 65 import com.oracle.truffle.api.nodes.GraphPrintVisitor;
59 import com.oracle.truffle.api.nodes.Node; 66 import com.oracle.truffle.api.nodes.Node;
60 import com.oracle.truffle.api.nodes.NodeInfo; 67 import com.oracle.truffle.api.nodes.NodeInfo;
100 import com.oracle.truffle.sl.parser.Scanner; 107 import com.oracle.truffle.sl.parser.Scanner;
101 import com.oracle.truffle.sl.runtime.SLContext; 108 import com.oracle.truffle.sl.runtime.SLContext;
102 import com.oracle.truffle.sl.runtime.SLFunction; 109 import com.oracle.truffle.sl.runtime.SLFunction;
103 import com.oracle.truffle.sl.runtime.SLFunctionRegistry; 110 import com.oracle.truffle.sl.runtime.SLFunctionRegistry;
104 import com.oracle.truffle.sl.runtime.SLNull; 111 import com.oracle.truffle.sl.runtime.SLNull;
105 import java.io.BufferedReader;
106 import java.io.IOException;
107 import java.io.InputStreamReader;
108 import java.io.PrintWriter;
109 import java.math.BigInteger;
110 import java.nio.file.Path;
111 import java.util.Collections;
112 import java.util.List;
113 112
114 /** 113 /**
115 * SL is a simple language to demonstrate and showcase features of Truffle. The implementation is as 114 * SL is a simple language to demonstrate and showcase features of Truffle. The implementation is as
116 * simple and clean as possible in order to help understanding the ideas and concepts of Truffle. 115 * simple and clean as possible in order to help understanding the ideas and concepts of Truffle.
117 * The language has first class functions, but no object model. 116 * The language has first class functions, but no object model.
184 * with the new version. 183 * with the new version.
185 * </ul> 184 * </ul>
186 */ 185 */
187 186
188 /* 187 /*
189 * 188 *
190 * <p> <b>Tools:</b><br> The use of some of Truffle's support for developer tools (based on the 189 * <p> <b>Tools:</b><br> The use of some of Truffle's support for developer tools (based on the
191 * Truffle Instrumentation Framework) are demonstrated in this file, for example: <ul> <li>a 190 * Truffle Instrumentation Framework) are demonstrated in this file, for example: <ul> <li>a
192 * {@linkplain NodeExecCounter counter for node executions}, tabulated by node type; and</li> <li>a 191 * {@linkplain NodeExecCounter counter for node executions}, tabulated by node type; and</li> <li>a
193 * simple {@linkplain CoverageTracker code coverage engine}.</li> </ul> In each case, the tool is 192 * simple {@linkplain CoverageTracker code coverage engine}.</li> </ul> In each case, the tool is
194 * enabled if a corresponding local boolean variable in this file is set to {@code true}. Results 193 * enabled if a corresponding local boolean variable in this file is set to {@code true}. Results
196 */ 195 */
197 @TruffleLanguage.Registration(name = "SL", version = "0.5", mimeType = "application/x-sl") 196 @TruffleLanguage.Registration(name = "SL", version = "0.5", mimeType = "application/x-sl")
198 public final class SLLanguage extends TruffleLanguage<SLContext> { 197 public final class SLLanguage extends TruffleLanguage<SLContext> {
199 private static List<NodeFactory<? extends SLBuiltinNode>> builtins = Collections.emptyList(); 198 private static List<NodeFactory<? extends SLBuiltinNode>> builtins = Collections.emptyList();
200 private static Visualizer visualizer = new SLDefaultVisualizer(); 199 private static Visualizer visualizer = new SLDefaultVisualizer();
201 private static ASTProber registeredASTProber; // non-null if prober already registered 200 private ASTProber astProber = new SLStandardASTProber();
202 private DebugSupportProvider debugSupport;
203 201
204 private SLLanguage() { 202 private SLLanguage() {
205 } 203 }
206 204
207 public static final SLLanguage INSTANCE = new SLLanguage(); 205 public static final SLLanguage INSTANCE = new SLLanguage();
252 } 250 }
253 251
254 /** 252 /**
255 * Temporary method during API evolution, supports debugger integration. 253 * Temporary method during API evolution, supports debugger integration.
256 */ 254 */
255 @Deprecated
257 public static void run(Source source) throws IOException { 256 public static void run(Source source) throws IOException {
258 TruffleVM vm = TruffleVM.newVM().build(); 257 TruffleVM vm = TruffleVM.newVM().build();
259 assert vm.getLanguages().containsKey("application/x-sl"); 258 assert vm.getLanguages().containsKey("application/x-sl");
260 vm.eval(source); 259 vm.eval(source);
261 Symbol main = vm.findGlobalSymbol("main"); 260 Symbol main = vm.findGlobalSymbol("main");
474 protected boolean isObjectOfLanguage(Object object) { 473 protected boolean isObjectOfLanguage(Object object) {
475 return object instanceof SLFunction; 474 return object instanceof SLFunction;
476 } 475 }
477 476
478 @Override 477 @Override
478 protected Visualizer getVisualizer() {
479 if (visualizer == null) {
480 visualizer = new SLDefaultVisualizer();
481 }
482 return visualizer;
483 }
484
485 @Override
486 protected ASTProber getDefaultASTProber() {
487 return astProber;
488 }
489
490 @SuppressWarnings("deprecation")
491 @Override
492 protected void enableASTProbing(ASTProber prober) {
493 throw new UnsupportedOperationException();
494 }
495
496 @Override
497 protected Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws IOException {
498 throw new IllegalStateException("evalInContext not supported in this language");
499 }
500
501 @Override
502 protected AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws IOException {
503 throw new IllegalStateException("createAdvancedInstrumentRootFactory not supported in this language");
504 }
505
506 @SuppressWarnings("deprecation")
507 @Override
479 protected ToolSupportProvider getToolSupport() { 508 protected ToolSupportProvider getToolSupport() {
480 return getDebugSupport(); 509 return null;
481 } 510 }
482 511
512 @SuppressWarnings("deprecation")
483 @Override 513 @Override
484 protected DebugSupportProvider getDebugSupport() { 514 protected DebugSupportProvider getDebugSupport() {
485 if (debugSupport == null) { 515 return null;
486 debugSupport = new SLDebugProvider(); 516 }
487 } 517
488 return debugSupport; 518 public Node createFindContextNode0() {
519 return createFindContextNode();
520 }
521
522 public SLContext findContext0(Node contextNode) {
523 return findContext(contextNode);
489 } 524 }
490 525
491 // TODO (mlvdv) remove the static hack when we no longer have the static demo variables 526 // TODO (mlvdv) remove the static hack when we no longer have the static demo variables
492 private static void setupToolDemos() { 527 private static void setupToolDemos() {
493 // if (statementCounts || coverage) {
494 // if (registeredASTProber == null) {
495 // final ASTProber newProber = new SLStandardASTProber();
496 // // This should be registered on the TruffleVM
497 // Probe.registerASTProber(newProber);
498 // registeredASTProber = newProber;
499 // }
500 // }
501 // if (nodeExecCounts) { 528 // if (nodeExecCounts) {
502 // nodeExecCounter = new NodeExecCounter(); 529 // nodeExecCounter = new NodeExecCounter();
503 // nodeExecCounter.install(); 530 // nodeExecCounter.install();
504 // } 531 // }
505 // 532 //
527 // coverageTracker.print(System.out); 554 // coverageTracker.print(System.out);
528 // coverageTracker.dispose(); 555 // coverageTracker.dispose();
529 // } 556 // }
530 } 557 }
531 558
532 public Node createFindContextNode0() {
533 return createFindContextNode();
534 }
535
536 public SLContext findContext0(Node contextNode) {
537 return findContext(contextNode);
538 }
539
540 private final class SLDebugProvider implements DebugSupportProvider {
541
542 public SLDebugProvider() {
543 if (registeredASTProber == null) {
544 registeredASTProber = new SLStandardASTProber();
545 // This should be registered on the TruffleVM
546 Probe.registerASTProber(registeredASTProber);
547 }
548 }
549
550 public Visualizer getVisualizer() {
551 if (visualizer == null) {
552 visualizer = new SLDefaultVisualizer();
553 }
554 return visualizer;
555 }
556
557 public void enableASTProbing(ASTProber prober) {
558 if (prober != null) {
559 // This should be registered on the TruffleVM
560 Probe.registerASTProber(prober);
561 }
562 }
563
564 public Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws DebugSupportException {
565 throw new DebugSupportException("evalInContext not supported in this language");
566 }
567
568 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException {
569 throw new DebugSupportException("createAdvancedInstrumentRootFactory not supported in this language");
570 }
571
572 }
573
574 } 559 }