Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/InitializationTest.java @ 22109:b5eaddcdf86a
Calling Env.importSymbol from TruffleLanguage.createContext should be possible
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 26 Aug 2015 14:13:43 +0200 |
parents | truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/instrument/InstrumentationTest.java@9c8c0937da41 |
children | c2cb9f1c8688 |
comparison
equal
deleted
inserted
replaced
22108:f84a7663966d | 22109:b5eaddcdf86a |
---|---|
1 /* | |
2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.truffle.api.test.vm; | |
24 | |
25 import static org.junit.Assert.*; | |
26 | |
27 import org.junit.*; | |
28 | |
29 import com.oracle.truffle.api.*; | |
30 import com.oracle.truffle.api.TruffleLanguage.Env; | |
31 import com.oracle.truffle.api.debug.Breakpoint; | |
32 import com.oracle.truffle.api.debug.DebugSupportException; | |
33 import com.oracle.truffle.api.debug.DebugSupportProvider; | |
34 import com.oracle.truffle.api.debug.Debugger; | |
35 import com.oracle.truffle.api.debug.ExecutionEvent; | |
36 import com.oracle.truffle.api.frame.*; | |
37 import com.oracle.truffle.api.instrument.*; | |
38 import com.oracle.truffle.api.nodes.*; | |
39 import com.oracle.truffle.api.source.Source; | |
40 import com.oracle.truffle.api.vm.EventConsumer; | |
41 import com.oracle.truffle.api.vm.TruffleVM; | |
42 import java.io.IOException; | |
43 | |
44 /** | |
45 * Bug report validating test. | |
46 * <p> | |
47 * It has been reported that calling {@link Env#importSymbol(java.lang.String)} in | |
48 * {@link TruffleLanguage TruffleLanguage.createContext(env)} yields a {@link NullPointerException}. | |
49 * <p> | |
50 */ | |
51 public class InitializationTest { | |
52 @Test | |
53 public void accessProbeForAbstractLanguage() throws IOException { | |
54 final Debugger[] arr = {null}; | |
55 TruffleVM vm = TruffleVM.newVM().onEvent(new EventConsumer<ExecutionEvent>(ExecutionEvent.class) { | |
56 @Override | |
57 protected void on(ExecutionEvent event) { | |
58 arr[0] = event.getDebugger(); | |
59 } | |
60 }).build(); | |
61 | |
62 Source source = Source.fromText("any text", "any text").withMimeType("application/x-abstrlang"); | |
63 | |
64 vm.eval(source); | |
65 | |
66 assertNotNull("Debugger found", arr[0]); | |
67 | |
68 Debugger d = arr[0]; | |
69 Breakpoint b = d.setLineBreakpoint(0, source.createLineLocation(1), true); | |
70 b.setCondition("true"); | |
71 | |
72 vm.eval(source); | |
73 } | |
74 | |
75 private static final class MMRootNode extends RootNode { | |
76 @Child ANode node; | |
77 | |
78 MMRootNode() { | |
79 super(AbstractLanguage.class, null, null); | |
80 node = new ANode(42); | |
81 } | |
82 | |
83 @Override | |
84 public Object execute(VirtualFrame frame) { | |
85 return node.constant(); | |
86 } | |
87 } | |
88 | |
89 private static final class ANode extends Node { | |
90 private final int constant; | |
91 | |
92 public ANode(int constant) { | |
93 this.constant = constant; | |
94 } | |
95 | |
96 Object constant() { | |
97 return constant; | |
98 } | |
99 | |
100 } | |
101 | |
102 private abstract static class AbstractLanguage extends TruffleLanguage<Object> { | |
103 } | |
104 | |
105 @TruffleLanguage.Registration(mimeType = "application/x-abstrlang", name = "AbstrLang", version = "0.1") | |
106 public static final class TestLanguage extends AbstractLanguage implements DebugSupportProvider { | |
107 public static final TestLanguage INSTANCE = new TestLanguage(); | |
108 | |
109 @Override | |
110 protected Object createContext(Env env) { | |
111 assertNull("Not defined symbol", env.importSymbol("unknown")); | |
112 return env; | |
113 } | |
114 | |
115 @Override | |
116 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { | |
117 return Truffle.getRuntime().createCallTarget(new MMRootNode()); | |
118 } | |
119 | |
120 @Override | |
121 protected Object findExportedSymbol(Object context, String globalName, boolean onlyExplicit) { | |
122 return null; | |
123 } | |
124 | |
125 @Override | |
126 protected Object getLanguageGlobal(Object context) { | |
127 throw new UnsupportedOperationException(); | |
128 } | |
129 | |
130 @Override | |
131 protected boolean isObjectOfLanguage(Object object) { | |
132 throw new UnsupportedOperationException(); | |
133 } | |
134 | |
135 @Override | |
136 protected ToolSupportProvider getToolSupport() { | |
137 throw new UnsupportedOperationException(); | |
138 } | |
139 | |
140 @Override | |
141 protected DebugSupportProvider getDebugSupport() { | |
142 return this; | |
143 } | |
144 | |
145 @Override | |
146 public Object evalInContext(Source source, Node node, MaterializedFrame mFrame) throws DebugSupportException { | |
147 throw new UnsupportedOperationException(); | |
148 } | |
149 | |
150 @Override | |
151 public AdvancedInstrumentRootFactory createAdvancedInstrumentRootFactory(String expr, AdvancedInstrumentResultListener resultListener) throws DebugSupportException { | |
152 throw new UnsupportedOperationException(); | |
153 } | |
154 | |
155 @Override | |
156 public Visualizer getVisualizer() { | |
157 throw new UnsupportedOperationException(); | |
158 } | |
159 | |
160 @Override | |
161 public void enableASTProbing(ASTProber astProber) { | |
162 throw new UnsupportedOperationException(); | |
163 } | |
164 } | |
165 } |