| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | |
| 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 file. | |
| 4 | |
| 5 /** Embeds the frog compiler as a worker isolate. */ | |
| 6 #library('compiler'); | |
| 7 | |
| 8 #import('dart:isolate', prefix: 'isolate'); | |
| 9 #import("../../frog/file_system_dom.dart"); | |
| 10 #import("../../frog/lang.dart", prefix: 'frog'); | |
| 11 | |
| 12 main() { | |
| 13 final fileSystem = new DomFileSystem(); | |
| 14 isolate.port.receive((input, replyTo) { | |
| 15 final watch = new Stopwatch.start(); | |
| 16 // Each message is a compilation request. | |
| 17 fileSystem.writeString("user.dart", input['code']); | |
| 18 frog.parseOptions('../../frog', ['dummyArg1', 'dummyArg2', 'user.dart'], | |
| 19 fileSystem); | |
| 20 frog.options.useColors = false; | |
| 21 frog.options.warningsAsErrors = input['warningsAsErrors']; | |
| 22 frog.initializeWorld(fileSystem); | |
| 23 | |
| 24 // Collect compilation messages | |
| 25 final warnings = []; | |
| 26 frog.world.messageHandler = (prefix, msg, span) { | |
| 27 final warning = { 'prefix': prefix, 'msg': msg}; | |
| 28 | |
| 29 if (span != null) { | |
| 30 warning['filename'] = span.file.filename; | |
| 31 warning['line'] = span.line; | |
| 32 warning['column'] = span.column; | |
| 33 warning['endLine'] = span.endLine; | |
| 34 warning['endColumn'] = span.endColumn; | |
| 35 warning['locationText'] = span.locationText; | |
| 36 } | |
| 37 warnings.add(warning); | |
| 38 }; | |
| 39 | |
| 40 bool success = frog.world.compile(); | |
| 41 watch.stop(); | |
| 42 | |
| 43 // Send results back to the requester isolate. | |
| 44 String output = success ? frog.world.getGeneratedCode() : null; | |
| 45 replyTo.send({ | |
| 46 'success': success, | |
| 47 'code': output, | |
| 48 'warnings': warnings, | |
| 49 'time': watch.elapsedInMs()}); | |
| 50 }); | |
| 51 } | |
| OLD | NEW |