comparison graal/com.oracle.truffle.ruby.runtime/src/com/oracle/truffle/ruby/runtime/RubyContext.java @ 14094:3f27e57439ed

Truffle/Instrumentation: significant rearrangement (including moved class) and extension of the Truffle Instrumentation Framework. New interfaces include DebugContext (which can be attached to the ExecutionContext), through which access is provided to possibly language-specific (a) node instrumentation, (b) debug services manager, (c) notification when programs halt, (d) display of language values, and (e) display of variable identifiers.
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Mon, 03 Feb 2014 20:58:23 -0800
parents 64fa70319890
children
comparison
equal deleted inserted replaced
13736:64fa70319890 14094:3f27e57439ed
13 import java.util.concurrent.atomic.*; 13 import java.util.concurrent.atomic.*;
14 14
15 import jnr.posix.*; 15 import jnr.posix.*;
16 16
17 import com.oracle.truffle.api.*; 17 import com.oracle.truffle.api.*;
18 import com.oracle.truffle.api.debug.*;
18 import com.oracle.truffle.api.frame.*; 19 import com.oracle.truffle.api.frame.*;
19 import com.oracle.truffle.api.impl.*;
20 import com.oracle.truffle.api.nodes.*; 20 import com.oracle.truffle.api.nodes.*;
21 import com.oracle.truffle.api.source.*; 21 import com.oracle.truffle.api.source.*;
22 import com.oracle.truffle.ruby.runtime.configuration.*; 22 import com.oracle.truffle.ruby.runtime.configuration.*;
23 import com.oracle.truffle.ruby.runtime.control.*; 23 import com.oracle.truffle.ruby.runtime.control.*;
24 import com.oracle.truffle.ruby.runtime.core.*; 24 import com.oracle.truffle.ruby.runtime.core.*;
38 private final ObjectSpaceManager objectSpaceManager; 38 private final ObjectSpaceManager objectSpaceManager;
39 private final TraceManager traceManager; 39 private final TraceManager traceManager;
40 private final ThreadManager threadManager; 40 private final ThreadManager threadManager;
41 private final FiberManager fiberManager; 41 private final FiberManager fiberManager;
42 private final AtExitManager atExitManager; 42 private final AtExitManager atExitManager;
43 private final DebugManager debugManager;
44 private final SourceManager sourceManager; 43 private final SourceManager sourceManager;
45 private final ASTPrinter astPrinter; 44 private DebugContext debugContext = null;
46 45
47 private AtomicLong nextObjectID = new AtomicLong(0); 46 private AtomicLong nextObjectID = new AtomicLong(0);
48 47
49 private String currentDirectory = System.getProperty("user.dir"); 48 private String currentDirectory = System.getProperty("user.dir");
50 49
51 private POSIX posix = POSIXFactory.getPOSIX(); 50 private POSIX posix = POSIXFactory.getPOSIX();
52 51
53 public RubyContext(RubyParser parser) { 52 public RubyContext(RubyParser parser) {
54 this(new Configuration(new ConfigurationBuilder()), parser, null); 53 this(new Configuration(new ConfigurationBuilder()), parser);
55 } 54 }
56 55
57 public RubyContext(Configuration configuration, RubyParser parser) { 56 public RubyContext(Configuration configuration, RubyParser parser) {
58 this(configuration, parser, null);
59 }
60
61 public RubyContext(Configuration configuration, RubyParser parser, ASTPrinter astPrinter) {
62 assert configuration != null; 57 assert configuration != null;
63 58
64 this.configuration = configuration; 59 this.configuration = configuration;
65 this.parser = parser; 60 this.parser = parser;
66 this.astPrinter = astPrinter;
67
68 objectSpaceManager = new ObjectSpaceManager(this); 61 objectSpaceManager = new ObjectSpaceManager(this);
69 traceManager = new TraceManager(this); 62 traceManager = new TraceManager(this);
70 63
71 // See note in CoreLibrary#initialize to see why we need to break this into two statements 64 // See note in CoreLibrary#initialize to see why we need to break this into two statements
72 coreLibrary = new CoreLibrary(this); 65 coreLibrary = new CoreLibrary(this);
74 67
75 featureManager = new FeatureManager(this); 68 featureManager = new FeatureManager(this);
76 atExitManager = new AtExitManager(); 69 atExitManager = new AtExitManager();
77 sourceManager = new SourceManager(); 70 sourceManager = new SourceManager();
78 71
79 debugManager = new DefaultDebugManager(this);
80
81 // Must initialize threads before fibers 72 // Must initialize threads before fibers
82 73
83 threadManager = new ThreadManager(this); 74 threadManager = new ThreadManager(this);
84 fiberManager = new FiberManager(this); 75 fiberManager = new FiberManager(this);
85 } 76 }
86 77
87 public final String getLanguageShortName() { 78 public final String getLanguageShortName() {
88 return "Ruby " + CoreLibrary.RUBY_VERSION; 79 return "Ruby " + CoreLibrary.RUBY_VERSION;
89 } 80 }
90 81
91 public DebugManager getDebugManager() { 82 public SourceManager getSourceManager() {
92 return debugManager; 83 return sourceManager;
93 } 84 }
94 85
95 public ASTPrinter getASTPrinter() { 86 public DebugContext getDebugContext() {
96 return astPrinter; 87 return debugContext;
88 }
89
90 public void setDebugContext(DebugContext debugContext) {
91 this.debugContext = debugContext;
97 } 92 }
98 93
99 public void implementationMessage(String format, Object... arguments) { 94 public void implementationMessage(String format, Object... arguments) {
100 System.err.println("rubytruffle: " + String.format(format, arguments)); 95 System.err.println("rubytruffle: " + String.format(format, arguments));
101 } 96 }
153 final ShellResult result = evalShell(line, existingLocals); 148 final ShellResult result = evalShell(line, existingLocals);
154 149
155 configuration.getStandardOut().println("=> " + result.getResult()); 150 configuration.getStandardOut().println("=> " + result.getResult());
156 151
157 existingLocals = result.getFrame(); 152 existingLocals = result.getFrame();
158 } catch (BreakShellException e) { 153 } catch (KillException e) {
159 return; 154 return;
160 } catch (Exception e) { 155 } catch (Exception e) {
161 e.printStackTrace(); 156 e.printStackTrace();
162 } 157 }
163 } 158 }
177 return callTarget.call(null, arguments); 172 return callTarget.call(null, arguments);
178 } catch (RaiseException e) { 173 } catch (RaiseException e) {
179 throw e; 174 throw e;
180 } catch (ThrowException e) { 175 } catch (ThrowException e) {
181 throw new RaiseException(context.getCoreLibrary().argumentErrorUncaughtThrow(e.getTag())); 176 throw new RaiseException(context.getCoreLibrary().argumentErrorUncaughtThrow(e.getTag()));
182 } catch (BreakShellException | QuitException e) { 177 } catch (KillException | QuitException e) {
183 throw e; 178 throw e;
184 } catch (Throwable e) { 179 } catch (Throwable e) {
185 throw new RaiseException(ExceptionTranslator.translateException(this, e)); 180 throw new RaiseException(ExceptionTranslator.translateException(this, e));
186 } 181 }
187 } 182 }
294 289
295 public AtExitManager getAtExitManager() { 290 public AtExitManager getAtExitManager() {
296 return atExitManager; 291 return atExitManager;
297 } 292 }
298 293
299 public SourceManager getSourceManager() {
300 return sourceManager;
301 }
302
303 } 294 }