Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: pkg/dartino_compiler/lib/vm_session.dart

Issue 1659163007: Rename fletch -> dartino (Closed) Base URL: https://github.com/dartino/sdk.git@master
Patch Set: address comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE.md file. 3 // BSD-style license that can be found in the LICENSE.md file.
4 4
5 library fletch.vm_session; 5 library dartino.vm_session;
6 6
7 import 'dart:core'; 7 import 'dart:core';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:convert'; 9 import 'dart:convert';
10 import 'dart:io' hide exit; 10 import 'dart:io' hide exit;
11 11
12 import 'dart:typed_data' show 12 import 'dart:typed_data' show
13 ByteData, 13 ByteData,
14 Uint8List; 14 Uint8List;
15 15
16 import 'vm_commands.dart'; 16 import 'vm_commands.dart';
17 import 'fletch_system.dart'; 17 import 'dartino_system.dart';
18 18
19 import 'incremental/fletchc_incremental.dart' 19 import 'incremental/dartino_compiler_incremental.dart'
20 show IncrementalCompiler; 20 show IncrementalCompiler;
21 21
22 import 'src/codegen_visitor.dart'; 22 import 'src/codegen_visitor.dart';
23 import 'src/debug_info.dart'; 23 import 'src/debug_info.dart';
24 24
25 // TODO(ahe): Get rid of this import. 25 // TODO(ahe): Get rid of this import.
26 import 'src/fletch_backend.dart' show FletchBackend; 26 import 'src/dartino_backend.dart' show DartinoBackend;
27 27
28 import 'src/fletch_selector.dart' show 28 import 'src/dartino_selector.dart' show
29 FletchSelector, 29 DartinoSelector,
30 SelectorKind; 30 SelectorKind;
31 31
32 import 'debug_state.dart'; 32 import 'debug_state.dart';
33 33
34 import 'src/shared_command_infrastructure.dart' show 34 import 'src/shared_command_infrastructure.dart' show
35 CommandTransformerBuilder, 35 CommandTransformerBuilder,
36 toUint8ListView; 36 toUint8ListView;
37 37
38 import 'src/hub/session_manager.dart' show 38 import 'src/hub/session_manager.dart' show
39 SessionState; 39 SessionState;
40 40
41 part 'vm_command_reader.dart'; 41 part 'vm_command_reader.dart';
42 part 'input_handler.dart'; 42 part 'input_handler.dart';
43 43
44 /// Encapsulates a TCP connection to a running fletch-vm and provides a 44 /// Encapsulates a TCP connection to a running dartino-vm and provides a
45 /// [VmCommand] based view on top of it. 45 /// [VmCommand] based view on top of it.
46 class FletchVmSession { 46 class DartinoVmSession {
47 /// The outgoing connection to the fletch-vm. 47 /// The outgoing connection to the dartino-vm.
48 final StreamSink<List<int>> _outgoingSink; 48 final StreamSink<List<int>> _outgoingSink;
49 49
50 final Sink<List<int>> stdoutSink; 50 final Sink<List<int>> stdoutSink;
51 final Sink<List<int>> stderrSink; 51 final Sink<List<int>> stderrSink;
52 52
53 /// The VM command reader reads data from the vm, converts the data 53 /// The VM command reader reads data from the vm, converts the data
54 /// into a [VmCommand], and provides a stream iterator iterating over 54 /// into a [VmCommand], and provides a stream iterator iterating over
55 /// these commands. 55 /// these commands.
56 /// If the [VmCommand] is for stdout or stderr the reader automatically 56 /// If the [VmCommand] is for stdout or stderr the reader automatically
57 /// forwards them to the stdout/stderr sinks and does not add them to the 57 /// forwards them to the stdout/stderr sinks and does not add them to the
(...skipping 14 matching lines...) Expand all
72 /// golden files. 72 /// golden files.
73 bool hideRawIds = false; 73 bool hideRawIds = false;
74 74
75 /// When true, don't use colors to highlight focus when printing code. 75 /// When true, don't use colors to highlight focus when printing code.
76 /// This is currently only true when running tests to avoid having to deal 76 /// This is currently only true when running tests to avoid having to deal
77 /// with color control characters in the expected files. 77 /// with color control characters in the expected files.
78 bool colorsDisabled = false; 78 bool colorsDisabled = false;
79 79
80 VmCommand connectionError = new ConnectionError("Connection is closed", null); 80 VmCommand connectionError = new ConnectionError("Connection is closed", null);
81 81
82 FletchVmSession(Socket vmSocket, 82 DartinoVmSession(Socket vmSocket,
83 Sink<List<int>> stdoutSink, 83 Sink<List<int>> stdoutSink,
84 Sink<List<int>> stderrSink) 84 Sink<List<int>> stderrSink)
85 : _outgoingSink = vmSocket, 85 : _outgoingSink = vmSocket,
86 this.stdoutSink = stdoutSink, 86 this.stdoutSink = stdoutSink,
87 this.stderrSink = stderrSink, 87 this.stderrSink = stderrSink,
88 _done = vmSocket.done, 88 _done = vmSocket.done,
89 _commandReader = new VmCommandReader(vmSocket, stdoutSink, stderrSink) { 89 _commandReader = new VmCommandReader(vmSocket, stdoutSink, stderrSink) {
90 _done.catchError((_, __) {}).then((_) { 90 _done.catchError((_, __) {}).then((_) {
91 _connectionIsDead = true; 91 _connectionIsDead = true;
92 }); 92 });
93 } 93 }
94 94
95 void writeStdout(String s) { 95 void writeStdout(String s) {
96 if (!silent && stdoutSink != null) stdoutSink.add(UTF8.encode(s)); 96 if (!silent && stdoutSink != null) stdoutSink.add(UTF8.encode(s));
97 } 97 }
98 98
99 void writeStdoutLine(String s) => writeStdout("$s\n"); 99 void writeStdoutLine(String s) => writeStdout("$s\n");
100 100
101 /// Convenience around [runCommands] for running just a single command. 101 /// Convenience around [runCommands] for running just a single command.
102 Future<VmCommand> runCommand(VmCommand command) { 102 Future<VmCommand> runCommand(VmCommand command) {
103 return runCommands([command]); 103 return runCommands([command]);
104 } 104 }
105 105
106 /// Sends the given commands to a fletch-vm and reads response commands 106 /// Sends the given commands to a dartino-vm and reads response commands
107 /// (if necessary). 107 /// (if necessary).
108 /// 108 ///
109 /// If all commands have been successfully applied and responses been awaited, 109 /// If all commands have been successfully applied and responses been awaited,
110 /// this function will complete with the last received [VmCommand] from the 110 /// this function will complete with the last received [VmCommand] from the
111 /// remote peer (or `null` if there was none). 111 /// remote peer (or `null` if there was none).
112 Future<VmCommand> runCommands(List<VmCommand> commands) async { 112 Future<VmCommand> runCommands(List<VmCommand> commands) async {
113 if (commands.any((VmCommand c) => c.numberOfResponsesExpected == null)) { 113 if (commands.any((VmCommand c) => c.numberOfResponsesExpected == null)) {
114 throw new ArgumentError( 114 throw new ArgumentError(
115 'The runComands() method will read response commands and therefore ' 115 'The runComands() method will read response commands and therefore '
116 'needs to know how many to read. One of the given commands does' 116 'needs to know how many to read. One of the given commands does'
117 'not specify how many commands the response will have.'); 117 'not specify how many commands the response will have.');
118 } 118 }
119 119
120 VmCommand lastResponse; 120 VmCommand lastResponse;
121 for (VmCommand command in commands) { 121 for (VmCommand command in commands) {
122 await sendCommand(command); 122 await sendCommand(command);
123 for (int i = 0; i < command.numberOfResponsesExpected; i++) { 123 for (int i = 0; i < command.numberOfResponsesExpected; i++) {
124 lastResponse = await readNextCommand(); 124 lastResponse = await readNextCommand();
125 } 125 }
126 } 126 }
127 return lastResponse; 127 return lastResponse;
128 } 128 }
129 129
130 /// Sends all given [VmCommand]s to a fletch-vm. 130 /// Sends all given [VmCommand]s to a dartino-vm.
131 Future sendCommands(List<VmCommand> commands) async { 131 Future sendCommands(List<VmCommand> commands) async {
132 for (var command in commands) { 132 for (var command in commands) {
133 await sendCommand(command); 133 await sendCommand(command);
134 } 134 }
135 } 135 }
136 136
137 /// Sends a [VmCommand] to a fletch-vm. 137 /// Sends a [VmCommand] to a dartino-vm.
138 Future sendCommand(VmCommand command) async { 138 Future sendCommand(VmCommand command) async {
139 if (_connectionIsDead) { 139 if (_connectionIsDead) {
140 throw new StateError( 140 throw new StateError(
141 'Trying to send command ${command} to fletch-vm, but ' 141 'Trying to send command ${command} to dartino-vm, but '
142 'the connection is already closed.'); 142 'the connection is already closed.');
143 } 143 }
144 command.addTo(_outgoingSink); 144 command.addTo(_outgoingSink);
145 } 145 }
146 146
147 /// Will read the next [VmCommand] the fletch-vm sends to us. 147 /// Will read the next [VmCommand] the dartino-vm sends to us.
148 Future<VmCommand> readNextCommand({bool force: true}) async { 148 Future<VmCommand> readNextCommand({bool force: true}) async {
149 if (_drainedIncomingCommands) { 149 if (_drainedIncomingCommands) {
150 return connectionError; 150 return connectionError;
151 } 151 }
152 152
153 _drainedIncomingCommands = !await _commandReader.iterator.moveNext() 153 _drainedIncomingCommands = !await _commandReader.iterator.moveNext()
154 .catchError((error, StackTrace trace) { 154 .catchError((error, StackTrace trace) {
155 connectionError = new ConnectionError(error, trace); 155 connectionError = new ConnectionError(error, trace);
156 return false; 156 return false;
157 }); 157 });
158 158
159 if (_drainedIncomingCommands && force) { 159 if (_drainedIncomingCommands && force) {
160 return connectionError; 160 return connectionError;
161 } 161 }
162 162
163 return _commandReader.iterator.current; 163 return _commandReader.iterator.current;
164 } 164 }
165 165
166 /// Closes the connection to the fletch-vm and drains the remaining response 166 /// Closes the connection to the dartino-vm and drains the remaining response
167 /// commands. 167 /// commands.
168 /// 168 ///
169 /// If [ignoreExtraCommands] is `false` it will throw a StateError if the 169 /// If [ignoreExtraCommands] is `false` it will throw a StateError if the
170 /// fletch-vm sent any commands. 170 /// dartino-vm sent any commands.
171 Future shutdown({bool ignoreExtraCommands: false}) async { 171 Future shutdown({bool ignoreExtraCommands: false}) async {
172 await _outgoingSink.close().catchError((_) {}); 172 await _outgoingSink.close().catchError((_) {});
173 173
174 while (!_drainedIncomingCommands) { 174 while (!_drainedIncomingCommands) {
175 VmCommand response = await readNextCommand(force: false); 175 VmCommand response = await readNextCommand(force: false);
176 if (!ignoreExtraCommands && response != null) { 176 if (!ignoreExtraCommands && response != null) {
177 await kill(); 177 await kill();
178 throw new StateError( 178 throw new StateError(
179 "Got unexpected command from fletch-vm during shutdown " 179 "Got unexpected command from dartino-vm during shutdown "
180 "($response)"); 180 "($response)");
181 } 181 }
182 } 182 }
183 183
184 return _done; 184 return _done;
185 } 185 }
186 186
187 Future interrupt() { 187 Future interrupt() {
188 return sendCommand(const ProcessDebugInterrupt()); 188 return sendCommand(const ProcessDebugInterrupt());
189 } 189 }
190 190
191 /// Closes the connection to the fletch-vm. It does not wait until it shuts 191 /// Closes the connection to the dartino-vm. It does not wait until it shuts
192 /// down. 192 /// down.
193 /// 193 ///
194 /// This method will never complete with an exception. 194 /// This method will never complete with an exception.
195 Future kill() async { 195 Future kill() async {
196 _connectionIsDead = true; 196 _connectionIsDead = true;
197 _drainedIncomingCommands = true; 197 _drainedIncomingCommands = true;
198 198
199 await _outgoingSink.close().catchError((_) {}); 199 await _outgoingSink.close().catchError((_) {});
200 var value = _commandReader.iterator.cancel(); 200 var value = _commandReader.iterator.cancel();
201 if (value != null) { 201 if (value != null) {
202 await value.catchError((_) {}); 202 await value.catchError((_) {});
203 } 203 }
204 _drainedIncomingCommands = true; 204 _drainedIncomingCommands = true;
205 } 205 }
206 } 206 }
207 207
208 /// Extends a bare [FletchVmSession] with debugging functionality. 208 /// Extends a bare [DartinoVmSession] with debugging functionality.
209 class Session extends FletchVmSession { 209 class Session extends DartinoVmSession {
210 final IncrementalCompiler compiler; 210 final IncrementalCompiler compiler;
211 final Future processExitCodeFuture; 211 final Future processExitCodeFuture;
212 212
213 DebugState debugState; 213 DebugState debugState;
214 FletchSystem fletchSystem; 214 DartinoSystem dartinoSystem;
215 bool loaded = false; 215 bool loaded = false;
216 bool running = false; 216 bool running = false;
217 bool terminated = false; 217 bool terminated = false;
218 218
219 Session(Socket fletchVmSocket, 219 Session(Socket dartinoVmSocket,
220 this.compiler, 220 this.compiler,
221 Sink<List<int>> stdoutSink, 221 Sink<List<int>> stdoutSink,
222 Sink<List<int>> stderrSink, 222 Sink<List<int>> stderrSink,
223 [this.processExitCodeFuture]) 223 [this.processExitCodeFuture])
224 : super(fletchVmSocket, stdoutSink, stderrSink) { 224 : super(dartinoVmSocket, stdoutSink, stderrSink) {
225 // We send many small packages, so use no-delay. 225 // We send many small packages, so use no-delay.
226 fletchVmSocket.setOption(SocketOption.TCP_NODELAY, true); 226 dartinoVmSocket.setOption(SocketOption.TCP_NODELAY, true);
227 // TODO(ajohnsen): Should only be initialized on debug()/testDebugger(). 227 // TODO(ajohnsen): Should only be initialized on debug()/testDebugger().
228 debugState = new DebugState(this); 228 debugState = new DebugState(this);
229 } 229 }
230 230
231 Future applyDelta(FletchDelta delta) async { 231 Future applyDelta(DartinoDelta delta) async {
232 VmCommand response = await runCommands(delta.commands); 232 VmCommand response = await runCommands(delta.commands);
233 fletchSystem = delta.system; 233 dartinoSystem = delta.system;
234 return response; 234 return response;
235 } 235 }
236 236
237 Future<HandShakeResult> handShake(String version) async { 237 Future<HandShakeResult> handShake(String version) async {
238 VmCommand command = await runCommand(new HandShake(version)); 238 VmCommand command = await runCommand(new HandShake(version));
239 if (command != null && command is HandShakeResult) return command; 239 if (command != null && command is HandShakeResult) return command;
240 return null; 240 return null;
241 } 241 }
242 242
243 Future disableVMStandardOutput() async { 243 Future disableVMStandardOutput() async {
(...skipping 14 matching lines...) Expand all
258 Future spawnProcess() async { 258 Future spawnProcess() async {
259 await runCommand(const ProcessSpawnForMain()); 259 await runCommand(const ProcessSpawnForMain());
260 } 260 }
261 261
262 Future run() async { 262 Future run() async {
263 await spawnProcess(); 263 await spawnProcess();
264 loaded = true; 264 loaded = true;
265 await runCommand(const ProcessRun()); 265 await runCommand(const ProcessRun());
266 // NOTE: The [ProcessRun] command normally results in a 266 // NOTE: The [ProcessRun] command normally results in a
267 // [ProcessTerminated] command. But if the compiler emitted a compile time 267 // [ProcessTerminated] command. But if the compiler emitted a compile time
268 // error, the fletch-vm will just halt()/exit() and we therefore get no 268 // error, the dartino-vm will just halt()/exit() and we therefore get no
269 // response. 269 // response.
270 var command = await readNextCommand(force: false); 270 var command = await readNextCommand(force: false);
271 if (command != null && command is! ProcessTerminated) { 271 if (command != null && command is! ProcessTerminated) {
272 throw new Exception('Expected process to finish complete with ' 272 throw new Exception('Expected process to finish complete with '
273 '[ProcessTerminated] but got [$command]'); 273 '[ProcessTerminated] but got [$command]');
274 } 274 }
275 await shutdown(); 275 await shutdown();
276 } 276 }
277 277
278 Future<int> debug( 278 Future<int> debug(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 case VmCommandCode.ConnectionError: 313 case VmCommandCode.ConnectionError:
314 running = false; 314 running = false;
315 loaded = false; 315 loaded = false;
316 await shutdown(); 316 await shutdown();
317 terminated = true; 317 terminated = true;
318 break; 318 break;
319 319
320 case VmCommandCode.ProcessBreakpoint: 320 case VmCommandCode.ProcessBreakpoint:
321 ProcessBreakpoint command = response; 321 ProcessBreakpoint command = response;
322 var function = fletchSystem.lookupFunctionById(command.functionId); 322 var function = dartinoSystem.lookupFunctionById(command.functionId);
323 debugState.topFrame = new BackTraceFrame( 323 debugState.topFrame = new BackTraceFrame(
324 function, command.bytecodeIndex, compiler, debugState); 324 function, command.bytecodeIndex, compiler, debugState);
325 running = true; 325 running = true;
326 break; 326 break;
327 327
328 default: 328 default:
329 throw new StateError( 329 throw new StateError(
330 "Unhandled response from Fletch VM connection: ${response.code}"); 330 "Unhandled response from Dartino VM connection: ${response.code}");
331 331
332 } 332 }
333 return response; 333 return response;
334 } 334 }
335 335
336 Future<VmCommand> debugRun() async { 336 Future<VmCommand> debugRun() async {
337 assert(!loaded); 337 assert(!loaded);
338 assert(!running); 338 assert(!running);
339 loaded = true; 339 loaded = true;
340 running = true; 340 running = true;
341 await sendCommand(const ProcessRun()); 341 await sendCommand(const ProcessRun());
342 return handleProcessStop(await readNextCommand()); 342 return handleProcessStop(await readNextCommand());
343 } 343 }
344 344
345 Future setBreakpointHelper(String name, 345 Future setBreakpointHelper(String name,
346 FletchFunction function, 346 DartinoFunction function,
347 int bytecodeIndex) async { 347 int bytecodeIndex) async {
348 ProcessSetBreakpoint response = await runCommands([ 348 ProcessSetBreakpoint response = await runCommands([
349 new PushFromMap(MapId.methods, function.functionId), 349 new PushFromMap(MapId.methods, function.functionId),
350 new ProcessSetBreakpoint(bytecodeIndex), 350 new ProcessSetBreakpoint(bytecodeIndex),
351 ]); 351 ]);
352 int breakpointId = response.value; 352 int breakpointId = response.value;
353 var breakpoint = new Breakpoint(name, bytecodeIndex, breakpointId); 353 var breakpoint = new Breakpoint(name, bytecodeIndex, breakpointId);
354 debugState.breakpoints[breakpointId] = breakpoint; 354 debugState.breakpoints[breakpointId] = breakpoint;
355 return breakpoint; 355 return breakpoint;
356 } 356 }
357 357
358 // TODO(ager): Let setBreakpoint return a stream instead and deal with 358 // TODO(ager): Let setBreakpoint return a stream instead and deal with
359 // error situations such as bytecode indices that are out of bounds for 359 // error situations such as bytecode indices that are out of bounds for
360 // some of the methods with the given name. 360 // some of the methods with the given name.
361 Future setBreakpoint({String methodName, int bytecodeIndex}) async { 361 Future setBreakpoint({String methodName, int bytecodeIndex}) async {
362 Iterable<FletchFunction> functions = 362 Iterable<DartinoFunction> functions =
363 fletchSystem.functionsWhere((f) => f.name == methodName); 363 dartinoSystem.functionsWhere((f) => f.name == methodName);
364 List<Breakpoint> breakpoints = []; 364 List<Breakpoint> breakpoints = [];
365 for (FletchFunction function in functions) { 365 for (DartinoFunction function in functions) {
366 breakpoints.add( 366 breakpoints.add(
367 await setBreakpointHelper(methodName, function, bytecodeIndex)); 367 await setBreakpointHelper(methodName, function, bytecodeIndex));
368 } 368 }
369 return breakpoints; 369 return breakpoints;
370 } 370 }
371 371
372 Future setFileBreakpointFromPosition(String name, 372 Future setFileBreakpointFromPosition(String name,
373 Uri file, 373 Uri file,
374 int position) async { 374 int position) async {
375 if (position == null) { 375 if (position == null) {
376 return null; 376 return null;
377 } 377 }
378 DebugInfo debugInfo = compiler.debugInfoForPosition( 378 DebugInfo debugInfo = compiler.debugInfoForPosition(
379 file, 379 file,
380 position, 380 position,
381 fletchSystem); 381 dartinoSystem);
382 if (debugInfo == null) { 382 if (debugInfo == null) {
383 return null; 383 return null;
384 } 384 }
385 SourceLocation location = debugInfo.locationForPosition(position); 385 SourceLocation location = debugInfo.locationForPosition(position);
386 if (location == null) { 386 if (location == null) {
387 return null; 387 return null;
388 } 388 }
389 FletchFunction function = debugInfo.function; 389 DartinoFunction function = debugInfo.function;
390 int bytecodeIndex = location.bytecodeIndex; 390 int bytecodeIndex = location.bytecodeIndex;
391 return setBreakpointHelper(function.name, function, bytecodeIndex); 391 return setBreakpointHelper(function.name, function, bytecodeIndex);
392 } 392 }
393 393
394 Future setFileBreakpointFromPattern(Uri file, 394 Future setFileBreakpointFromPattern(Uri file,
395 int line, 395 int line,
396 String pattern) async { 396 String pattern) async {
397 assert(line > 0); 397 assert(line > 0);
398 int position = compiler.positionInFileFromPattern(file, line - 1, pattern); 398 int position = compiler.positionInFileFromPattern(file, line - 1, pattern);
399 return setFileBreakpointFromPosition( 399 return setFileBreakpointFromPosition(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 debugState.currentFrame = frame; 547 debugState.currentFrame = frame;
548 return true; 548 return true;
549 } 549 }
550 550
551 BackTrace stackTraceFromBacktraceResponse( 551 BackTrace stackTraceFromBacktraceResponse(
552 ProcessBacktrace backtraceResponse) { 552 ProcessBacktrace backtraceResponse) {
553 int frames = backtraceResponse.frames; 553 int frames = backtraceResponse.frames;
554 BackTrace stackTrace = new BackTrace(frames, debugState); 554 BackTrace stackTrace = new BackTrace(frames, debugState);
555 for (int i = 0; i < frames; ++i) { 555 for (int i = 0; i < frames; ++i) {
556 int functionId = backtraceResponse.functionIds[i]; 556 int functionId = backtraceResponse.functionIds[i];
557 FletchFunction function = fletchSystem.lookupFunctionById(functionId); 557 DartinoFunction function = dartinoSystem.lookupFunctionById(functionId);
558 if (function == null) { 558 if (function == null) {
559 function = const FletchFunction.missing(); 559 function = const DartinoFunction.missing();
560 } 560 }
561 stackTrace.addFrame( 561 stackTrace.addFrame(
562 compiler, 562 compiler,
563 new BackTraceFrame(function, 563 new BackTraceFrame(function,
564 backtraceResponse.bytecodeIndices[i], 564 backtraceResponse.bytecodeIndices[i],
565 compiler, 565 compiler,
566 debugState)); 566 debugState));
567 } 567 }
568 return stackTrace; 568 return stackTrace;
569 } 569 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 Future<BackTrace> processStack(int processId) async { 627 Future<BackTrace> processStack(int processId) async {
628 assert(running); 628 assert(running);
629 ProcessBacktrace backtraceResponse = 629 ProcessBacktrace backtraceResponse =
630 await runCommand(new ProcessBacktraceRequest(processId)); 630 await runCommand(new ProcessBacktraceRequest(processId));
631 return stackTraceFromBacktraceResponse(backtraceResponse); 631 return stackTraceFromBacktraceResponse(backtraceResponse);
632 } 632 }
633 633
634 String dartValueToString(DartValue value) { 634 String dartValueToString(DartValue value) {
635 if (value is Instance) { 635 if (value is Instance) {
636 Instance i = value; 636 Instance i = value;
637 String className = fletchSystem.lookupClassById(i.classId).name; 637 String className = dartinoSystem.lookupClassById(i.classId).name;
638 return "Instance of '$className'"; 638 return "Instance of '$className'";
639 } else { 639 } else {
640 return value.dartToString(); 640 return value.dartToString();
641 } 641 }
642 } 642 }
643 643
644 String instanceStructureToString(InstanceStructure structure, 644 String instanceStructureToString(InstanceStructure structure,
645 List<DartValue> fields) { 645 List<DartValue> fields) {
646 int classId = structure.classId; 646 int classId = structure.classId;
647 FletchClass klass = fletchSystem.lookupClassById(classId); 647 DartinoClass klass = dartinoSystem.lookupClassById(classId);
648 648
649 // TODO(fletchc-team): This should be more strict and a compiler bug 649 // TODO(dartino_compiler-team): This should be more strict and a compiler bu g
650 // should be reported to the user in order for us to get a bugreport. 650 // should be reported to the user in order for us to get a bugreport.
651 if (klass == null) { 651 if (klass == null) {
652 return 'Unknown (Fletch compiler was unable to find exception class)'; 652 return 'Unknown (Dartino compiler was unable to find exception class)';
653 } 653 }
654 654
655 StringBuffer sb = new StringBuffer(); 655 StringBuffer sb = new StringBuffer();
656 sb.writeln("Instance of '${klass.name}' {"); 656 sb.writeln("Instance of '${klass.name}' {");
657 for (int i = 0; i < structure.fields; i++) { 657 for (int i = 0; i < structure.fields; i++) {
658 DartValue value = fields[i]; 658 DartValue value = fields[i];
659 String fieldName = debugState.lookupFieldName(klass, i); 659 String fieldName = debugState.lookupFieldName(klass, i);
660 if (fieldName == null) { 660 if (fieldName == null) {
661 fieldName = '<unnamed>'; 661 fieldName = '<unnamed>';
662 } 662 }
663 sb.writeln(' $fieldName: ${dartValueToString(value)}'); 663 sb.writeln(' $fieldName: ${dartValueToString(value)}');
664 } 664 }
665 sb.write('}'); 665 sb.write('}');
666 return '$sb'; 666 return '$sb';
667 } 667 }
668 668
669 String noSuchMethodErrorToString(List<DartValue> nsmFields) { 669 String noSuchMethodErrorToString(List<DartValue> nsmFields) {
670 assert(nsmFields.length == 3); 670 assert(nsmFields.length == 3);
671 DartValue receiver = nsmFields[0]; 671 DartValue receiver = nsmFields[0];
672 ClassValue receiverClass = nsmFields[1]; 672 ClassValue receiverClass = nsmFields[1];
673 Integer receiverSelector = nsmFields[2]; 673 Integer receiverSelector = nsmFields[2];
674 FletchSelector selector = new FletchSelector(receiverSelector.value); 674 DartinoSelector selector = new DartinoSelector(receiverSelector.value);
675 675
676 String method = 676 String method =
677 fletchSystem.lookupSymbolBySelector(selector.encodedSelector); 677 dartinoSystem.lookupSymbolBySelector(selector.encodedSelector);
678 FletchClass klass = fletchSystem.lookupClassById(receiverClass.classId); 678 DartinoClass klass = dartinoSystem.lookupClassById(receiverClass.classId);
679 // TODO(ahe): If FletchClass is a synthetic closure class, improve the 679 // TODO(ahe): If DartinoClass is a synthetic closure class, improve the
680 // message. For example, "(local) function `foo` takes 3 arguments, but 680 // message. For example, "(local) function `foo` takes 3 arguments, but
681 // called with 4" instead of "Class '<internal>' has no method named 'call' 681 // called with 4" instead of "Class '<internal>' has no method named 'call'
682 // that takes 4 arguments". 682 // that takes 4 arguments".
683 String name = klass.name; 683 String name = klass.name;
684 String raw = hideRawIds 684 String raw = hideRawIds
685 ? "" : " (${receiverClass.classId}::${selector.encodedSelector})"; 685 ? "" : " (${receiverClass.classId}::${selector.encodedSelector})";
686 // TODO(ahe): Lookup the name in the receiverClass and include that as a 686 // TODO(ahe): Lookup the name in the receiverClass and include that as a
687 // suggestion in the error mesage. 687 // suggestion in the error mesage.
688 switch (selector.kind) { 688 switch (selector.kind) {
689 case SelectorKind.Method: 689 case SelectorKind.Method:
(...skipping 19 matching lines...) Expand all
709 return fields; 709 return fields;
710 } 710 }
711 711
712 String exceptionToString(RemoteObject exception) { 712 String exceptionToString(RemoteObject exception) {
713 String message; 713 String message;
714 if (exception is RemoteValue) { 714 if (exception is RemoteValue) {
715 message = dartValueToString(exception.value); 715 message = dartValueToString(exception.value);
716 } else if (exception is RemoteInstance) { 716 } else if (exception is RemoteInstance) {
717 InstanceStructure structure = exception.instance; 717 InstanceStructure structure = exception.instance;
718 int classId = structure.classId; 718 int classId = structure.classId;
719 FletchClass klass = fletchSystem.lookupClassById(classId); 719 DartinoClass klass = dartinoSystem.lookupClassById(classId);
720 720
721 FletchBackend backend = compiler.compiler.backend; 721 DartinoBackend backend = compiler.compiler.backend;
722 var fletchNoSuchMethodErrorClass = fletchSystem.lookupClassByElement( 722 var dartinoNoSuchMethodErrorClass = dartinoSystem.lookupClassByElement(
723 backend.fletchNoSuchMethodErrorClass); 723 backend.dartinoNoSuchMethodErrorClass);
724 724
725 if (klass == fletchNoSuchMethodErrorClass) { 725 if (klass == dartinoNoSuchMethodErrorClass) {
726 message = noSuchMethodErrorToString(exception.fields); 726 message = noSuchMethodErrorToString(exception.fields);
727 } else { 727 } else {
728 message = instanceStructureToString( 728 message = instanceStructureToString(
729 exception.instance, exception.fields); 729 exception.instance, exception.fields);
730 } 730 }
731 } else { 731 } else {
732 throw new UnimplementedError(); 732 throw new UnimplementedError();
733 } 733 }
734 return 'Uncaught exception: $message'; 734 return 'Uncaught exception: $message';
735 } 735 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 return ''; 859 return '';
860 } else if (response is ProcessTerminated) { 860 } else if (response is ProcessTerminated) {
861 return '### process terminated\n'; 861 return '### process terminated\n';
862 862
863 } else if (response is ConnectionError) { 863 } else if (response is ConnectionError) {
864 return '### lost connection to the virtual machine\n'; 864 return '### lost connection to the virtual machine\n';
865 } 865 }
866 return ''; 866 return '';
867 } 867 }
868 } 868 }
OLDNEW
« no previous file with comments | « pkg/dartino_compiler/lib/vm_commands.dart ('k') | pkg/dartino_compiler/samples/dartino_compiler_driver/target.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698