| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
| 4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * This is the entrypoint for a version of the frog compiler that | 7 * This is the entrypoint for a version of the frog compiler that |
| 8 * can run in the browser. | 8 * can run in the browser. |
| 9 * Because this is running in the browser, frog cannot access | 9 * Because this is running in the browser, frog cannot access |
| 10 * the file system. Instead, we assume the all necessary files | 10 * the file system. Instead, we assume the all necessary files |
| 11 * have been placed in inert <script> elements somewhere on the page. | 11 * have been placed in inert <script> elements somewhere on the page. |
| 12 * (See frogpad.py for more details on how the html page is constructed.) | 12 * (See frogpad.py for more details on how the html page is constructed.) |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 #import("dart:html", prefix:"html"); | 15 #import("dart:html", prefix:"html"); |
| 16 #import("../../../frog/lang.dart"); | 16 #import("../../../frog/lang.dart"); |
| 17 #import("../../../frog/file_system.dart"); | 17 #import("../../../frog/file_system.dart"); |
| 18 | 18 |
| 19 // id of script element containing name of the main dart file | 19 // id of script element containing name of the main dart file |
| 20 // to compile. | 20 // to compile. |
| 21 final String MAIN_ID = "main_id"; | 21 final String MAIN_ID = "main_id"; |
| 22 | 22 |
| 23 // id of script element containing name of the frog directory |
| 24 final String FROGDIR_ID = "frogdir_id"; |
| 25 |
| 23 void main() { | 26 void main() { |
| 24 String warnings = ""; | 27 String warnings = ""; |
| 25 HtmlFileSystem fs = new HtmlFileSystem(); | 28 HtmlFileSystem fs = new HtmlFileSystem(); |
| 26 String mainFile = getText(MAIN_ID); | 29 String frogDir = getText(FROGDIR_ID); |
| 30 String mainFile = getText(MAIN_ID); |
| 27 setText("input", fs.readAll(mainFile)); | 31 setText("input", fs.readAll(mainFile)); |
| 28 | 32 |
| 29 int time1 = new Date.now().value; | 33 int time1 = new Date.now().value; |
| 30 List<String> args = [ | 34 List<String> args = [ |
| 31 "dummy_arg1", | 35 "dummy_arg1", |
| 32 "dummy_arg2", | 36 "dummy_arg2", |
| 33 "--enable_type_checks", | 37 "--enable_type_checks", |
| 34 "--enable_asserts", | 38 "--enable_asserts", |
| 35 mainFile]; | 39 mainFile]; |
| 36 parseOptions("dummy_home_dir", args, fs); | 40 parseOptions(frogDir, args, fs); |
| 37 | 41 |
| 38 options.useColors = false; | 42 options.useColors = false; |
| 39 | 43 |
| 40 initializeWorld(fs); | 44 initializeWorld(fs); |
| 41 world.messageHandler = void _( | 45 world.messageHandler = void _( |
| 42 String prefix, String message, SourceSpan span) { | 46 String prefix, String message, SourceSpan span) { |
| 43 String location = ""; | 47 String location = ""; |
| 44 if (span !== null) { | 48 if (span !== null) { |
| 45 location = span.locationText; | 49 location = span.locationText; |
| 46 } | 50 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 92 |
| 89 String readAll(String filename) { | 93 String readAll(String filename) { |
| 90 String text = getText(idOfFilename(filename)); | 94 String text = getText(idOfFilename(filename)); |
| 91 print("read $filename (${text.length} bytes)"); | 95 print("read $filename (${text.length} bytes)"); |
| 92 return text; | 96 return text; |
| 93 } | 97 } |
| 94 | 98 |
| 95 /** | 99 /** |
| 96 * Returns the id of the <script> element that contains | 100 * Returns the id of the <script> element that contains |
| 97 * the contents of this file. | 101 * the contents of this file. |
| 98 * The id is constructed by taking the last directory | 102 * The id is constructed by taking the filename and replacing |
| 99 * of the path, plus the file name, and using _ as a | 103 * all slashes and dots with underscores. For example, the file name: |
| 100 * separator. So, for example, the file name: | |
| 101 * | 104 * |
| 102 * "/usr/local/src/dart/frog/lang.dart" | 105 * "/usr/local/src/dart/frog/lang.dart" |
| 103 * | 106 * |
| 104 * becomes: | 107 * becomes: |
| 105 * | 108 * |
| 106 * "frog_lang_dart" | 109 * "_usr_local_src_dart_frog_lang_dart" |
| 107 * | 110 * |
| 108 * And, so this file's contents will be found in a <script> | 111 * And, so this file's contents will be found in a <script> |
| 109 * element that looks like this: | 112 * element that looks like this: |
| 110 * | 113 * |
| 111 * <script type=application/inert id="frog_lang_dart"> | 114 * <script type=application/inert id="_usr_local_src_dart_frog_lang_dart"> |
| 112 * ... contents of file lang.dart placed here ... | 115 * ... contents of file lang.dart placed here ... |
| 113 * etc. | 116 * etc. |
| 114 */ | 117 */ |
| 115 String idOfFilename(String filename) { | 118 String idOfFilename(String filename) { |
| 116 List<String> components = filename.split("/"); | 119 return filename.replaceAll("/", "_").replaceAll(".", "_"); |
| 117 if (components.isEmpty()) { | |
| 118 throw new Exception("bad filename"); | |
| 119 } | |
| 120 // Grab the last two components (the directory name and file name). | |
| 121 int startIndex = Math.max(0, components.length - 2); | |
| 122 int length = components.length - startIndex;; | |
| 123 components = components.getRange(startIndex, length); | |
| 124 | |
| 125 // Join components with underscore, and replace dots with underscore. | |
| 126 return Strings.join(components, "_").replaceAll(".", "_"); | |
| 127 } | 120 } |
| 128 | 121 |
| 129 void writeString(String outfile, String text) { | 122 void writeString(String outfile, String text) { |
| 130 throw new UnsupportedOperationException(""); | 123 throw new UnsupportedOperationException(""); |
| 131 } | 124 } |
| 132 | 125 |
| 133 bool fileExists(String filename) { | 126 bool fileExists(String filename) { |
| 134 // frog calls this to check if files exist before reading them. We return | 127 // frog calls this to check if files exist before reading them. We return |
| 135 // true here for all files, and let it fail later if frog attempts to read | 128 // true here for all files, and let it fail later if frog attempts to read |
| 136 // the contents of a non-existent file. | 129 // the contents of a non-existent file. |
| 137 return true; | 130 return true; |
| 138 } | 131 } |
| 139 | 132 |
| 140 void createDirectory(String path, [bool recursive]) { | 133 void createDirectory(String path, [bool recursive]) { |
| 141 throw new UnsupportedOperationException(""); | 134 throw new UnsupportedOperationException(""); |
| 142 } | 135 } |
| 143 | 136 |
| 144 void removeDirectory(String path, [bool recursive]) { | 137 void removeDirectory(String path, [bool recursive]) { |
| 145 throw new UnsupportedOperationException(""); | 138 throw new UnsupportedOperationException(""); |
| 146 } | 139 } |
| 147 } | 140 } |
| OLD | NEW |