Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 242 lines (220 sloc) 9.834 kb
94da44f Kill deprecated comments and keywords in compiler. Boot for macros renam...
nazgul authored
1 /*
c447d39 Update copyright notices.
malekith authored
2 * Copyright (c) 2003, 2004 The University of Wroclaw.
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the University may not be used to endorse or promote
14 * products derived from this software without specific prior
15 * written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE UNIVERSITY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
94da44f Kill deprecated comments and keywords in compiler. Boot for macros renam...
nazgul authored
27 */
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
28
94da44f Kill deprecated comments and keywords in compiler. Boot for macros renam...
nazgul authored
29 /*
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
30 * This is the main compiler file. But all it does it running parser
31 * (parser.n) and transferring control to Passes.run function (from
32 * passes.n).
33 *
34 * Main file also catches some exceptions.
94da44f Kill deprecated comments and keywords in compiler. Boot for macros renam...
nazgul authored
35 */
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
36
94da44f Kill deprecated comments and keywords in compiler. Boot for macros renam...
nazgul authored
37 using Nemerle.Collections;
38 using Nemerle.Utility;
4f7f58c Fixes in sources and bootstrap compiler for macros in namespaces.
malekith authored
39 using Nemerle.IO;
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
40
41 namespace Nemerle.Compiler
42 {
43 module MainClass
44 {
45 public Main () : void
46 {
5de3860 Implement new try...with syntax with braces.
malekith authored
47 try
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
48 do_main ()
b1d9fe9 Use new syntax (mostly with -> catch) everywhere.
malekith authored
49 catch {
5de3860 Implement new try...with syntax with braces.
malekith authored
50 | e : System.IO.FileNotFoundException =>
51 Message.error (e.Message)
52 | e : Recovery =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
53 bomb (e, "got Recovery exception")
7fb053f Some work on removing redundant exception names
nazgul authored
54 | e : System.ArgumentException =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
55 bomb (e, "got ArgumentException (" + e.Message + ")")
9a57ad6 Finalize removal of obsolated exception names
nazgul authored
56 | e : MatchFailureException =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
57 bomb (e, "got MatchFailureException exception")
5de3860 Implement new try...with syntax with braces.
malekith authored
58 | e : ICE =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
59 bomb (e, e.msg)
9a57ad6 Finalize removal of obsolated exception names
nazgul authored
60 | e : AssertionException =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
61 bomb (e, e.Message)
107cf54 Rebuild test system and return codes of compiler to ignore test failing ...
nazgul authored
62 | e : AssemblyFindException =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
63 Message.error (e.Message);
64 System.Environment.Exit (3);
9e96c9b Print ,,confused'' message in case of any exception. Inform about assert...
malekith authored
65 | e : System.Exception =>
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
66 bomb (e, "got some unknown exception " + e.ToString ())
5de3860 Implement new try...with syntax with braces.
malekith authored
67 };
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
68
69 Message.maybe_bailout();
70 }
71
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
72 bomb (e : System.Exception, msg : string) : void
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
73 {
19bfcea Print newline before print error messages (to kill progress bar).
malekith authored
74 Passes.KillProgressBar ();
f64860d Make compiler print messages about other internal problems beside ICE.
malekith authored
75 Message.maybe_bailout (true);
76 Message.error (sprintf ("internal compiler error: %s\n%s\n", msg, e.StackTrace));
77 System.Environment.Exit (2);
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
78 }
79
80 do_main () : void {
81 mutable files <- [];
19dabb9 Automatic loading of macro files. Lots of makefile hackery to workaround...
malekith authored
82 mutable no_macros <- false;
bccf459 Automagically load Nemerle.dll, unless -no-stdlib is given.
malekith authored
83 mutable no_stdlib <- false;
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
84
81b9915 Add -version flag to compiler.
malekith authored
85 def print_version () {
9aed29f Bump version to 0.1.3.
malekith authored
86 System.Console.Error.Write ("Nemerle Compiler (ncc) version 0.1.3 (SVN)\n"
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
87 "(c) 2003, 2004 University of Wroclaw,"
88 " All rights reserved.\n");
81b9915 Add -version flag to compiler.
malekith authored
89 System.Environment.Exit (0);
90 };
91
341ca91 Add -pkg-config option to compiler arguments.
nazgul authored
92 def execute_pkgconfig (opt : string) {
93 def pkg = System.Diagnostics.Process ();
94 pkg.StartInfo.FileName <- "pkg-config";
95 pkg.StartInfo.Arguments <- ("--libs " + opt);
96 pkg.StartInfo.RedirectStandardOutput <- true;
085a0f5 Support case where execution of pkg-config fails.
nazgul authored
97 pkg.StartInfo.RedirectStandardError <- true;
341ca91 Add -pkg-config option to compiler arguments.
nazgul authored
98 pkg.StartInfo.UseShellExecute <- false;
99 mutable result <- "";
100 try
101 {
102 ignore (pkg.Start ());
103 result <- pkg.StandardOutput.ReadLine ();
104 pkg.WaitForExit ();
105 }
106 catch {
107 | _ : System.Exception =>
108 Message.warning ("pkg-config execution failed")
109 };
1cc20b9 Use -r if pkgconfig execution desn't do anything.
nazgul authored
110 match (
111 if (result != null) {
112 def split = NString.Split (array [' '], result);
113 def split = List.Map (split, fun (x : string) {
114 x.TrimStart (array [' ']).TrimEnd (array [' '])
115 });
116 List.Filter (split, fun (x) { x != "" })
117 }
118 else
119 []
120 ) {
121 | [] => ["-r", opt]
122 | x => x
085a0f5 Support case where execution of pkg-config fails.
nazgul authored
123 }
341ca91 Add -pkg-config option to compiler arguments.
nazgul authored
124 };
125
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
126 def opts = [
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
127 Getopt.Flag (name = "-xml",
128 aliases = ["-x"],
129 help = "Output XML representation of AST (for documentation)",
130 handler = fun () { Flags.just_dump_xml <- true; }),
131 Getopt.Flag (name = "-target-exe",
132 aliases = ["-texe"],
133 help = "Build an executable file",
134 handler = fun () { Flags.target_is_library <- false; }),
135 Getopt.Flag (name = "-target-library",
136 aliases = ["-tdll"],
137 help = "Build a library",
138 handler = fun () { Flags.target_is_library <- true; }),
139 Getopt.String (name = "-out",
140 aliases = ["-o"],
141 help = "Output file name",
142 handler = fun (s) { Flags.output_file_name <- s }),
143 Getopt.String (name = "-reference",
144 aliases = ["-r", "-ref"],
145 help = "Link specified assembly",
146 handler = fun (s) { Flags.referenced_libraries <-
147 s :: Flags.referenced_libraries
148 }),
149 Getopt.String (name = "-library-path",
150 aliases = ["-lib", "-L"],
151 help = "Add specified directory to library search path",
152 handler = LibraryReferenceManager.AddSearchDirectory),
341ca91 Add -pkg-config option to compiler arguments.
nazgul authored
153
154 Getopt.SubstitutionString (name = "-pkg-config",
155 aliases = ["-pkg", "-p"],
156 help = "Link to assemblies listed by pkg-config run on"
157 " given string",
158 substitute = execute_pkgconfig),
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
159
160 Getopt.Flag (name = "-no-stdmacros",
161 help = "Do not load standard macros",
162 handler = fun () { no_macros <- true }),
163 Getopt.Flag (name = "-no-stdlib",
164 help = "Do not load Nemerle.dll",
165 handler = fun () { no_stdlib <- true }),
8db7b81 Make compiler load aliases.n by default.
malekith authored
166
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
167 Getopt.Flag (name = "-ignore-confusion",
168 help = "Output stack trace even when seen errors",
169 handler = fun () { Flags.ignore_confusion <- true }),
170 Getopt.Flag (name = "-general-tail-call-opt",
171 aliases = ["-Ot"],
172 help = "Enable general tail call optimization",
173 handler = fun () { Flags.general_tail_call_opt <- true }),
b06d271 Added matching over System.Char literals. Fixed some
olszta authored
174
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
175 Getopt.Flag (name = "-boolean-constant-matching-opt",
176 aliases = ["-Obcm"],
177 help = "Enable boolean constant matching optimization",
178 handler = fun () {
179 Flags.constant_boolean_matching_opt <- true
180 }),
181 Getopt.Flag (name = "-ordinal-constant-matching-opt",
182 aliases = ["-Oocm"],
183 help = "Enable ordinal constant matching optimization",
184 handler = fun () {
185 Flags.constant_ordinal_matching_opt <- true
186 }),
187 Getopt.Flag (name = "-string-constant-matching-opt",
188 aliases = ["-Oscm"],
189 help = "Enable string constant matching optimization",
190 handler = fun () {
191 Flags.constant_string_matching_opt <- true
192 }),
b06d271 Added matching over System.Char literals. Fixed some
olszta authored
193
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
194 Getopt.Flag (name = "-no-color",
195 help = "Disable ANSI coloring of error/warning/hint messages",
196 handler = fun () { Flags.color_messages <- false }),
197 Getopt.Flag (name = "-pedantic-lexer",
198 help = "Enable some pedantic checks for illegal characters"
199 " in input stream",
200 handler = fun () { Flags.pedantic_lexer <- true }),
201 Getopt.Flag (name = "-version",
202 aliases = ["-V"],
203 help = "Output version information and exit",
204 handler = print_version),
205 Getopt.Flag (name = "-no-progress-bar",
206 aliases = ["-q"],
207 help = "Disable progress bar",
208 handler = fun () { Flags.progress_bar <- false; }),
9112266 Add compiler flags framework. Add general tail call opt emission -- it w...
malekith authored
209 Getopt.NonOption (name = "",
210 help = "Specify file to compile",
29454d2 Fix parse errors after new syntax changes
nazgul authored
211 handler = fun (s) { files <- s :: files })
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
212 ];
213
214 Getopt.Parse (opts);
215
216 match (files) {
217 | [] =>
218 Getopt.Error ("need at least one file to compile\n" + Getopt.Usage (opts))
219 | _ =>
19dabb9 Automatic loading of macro files. Lots of makefile hackery to workaround...
malekith authored
220 unless (no_macros)
a08abf7 Change stdmacros.dll to Nemerle.Macros.dll.
nazgul authored
221 LibraryReferenceManager.LoadMacrosFrom ("Nemerle.Macros");
19dabb9 Automatic loading of macro files. Lots of makefile hackery to workaround...
malekith authored
222
24a8391 Core libraries shouldn't be loaded when -no-stdlib is passed. And any li...
malekith authored
223 unless (no_stdlib) {
224 LibraryReferenceManager.AddLibrary ("mscorlib");
225 LibraryReferenceManager.AddLibrary ("System");
51b0c6e Add proper library search paths. Load System.dll by default.
malekith authored
226 LibraryReferenceManager.AddLibrary ("Nemerle");
24a8391 Core libraries shouldn't be loaded when -no-stdlib is passed. And any li...
malekith authored
227 };
bccf459 Automagically load Nemerle.dll, unless -no-stdlib is given.
malekith authored
228
a72a918 Next chunk of changes of stdlib syntax. Now complex backward merge is pe...
nazgul authored
229 List.Iter (List.Rev (Flags.referenced_libraries),
230 LibraryReferenceManager.AddLibrary);
8db7b81 Make compiler load aliases.n by default.
malekith authored
231
751cec2 Syntax extensions are now loaded only when using keyword is used on righ...
nazgul authored
232 MacroRegistry.LoadSyntaxExtensions ("Nemerle.Core");
233
a72a918 Next chunk of changes of stdlib syntax. Now complex backward merge is pe...
nazgul authored
234 def trees = List.Map (List.Rev (files),
235 fun (f) { Parser.parse (Lexer (f)) });
73e4373 The most stupid thing I have done so far.
malekith authored
236
9112266 Add compiler flags framework. Add general tail call opt emission -- it w...
malekith authored
237 Passes.run (trees)
6ef51d6 Kill C# files altogether. Use new Getopt module.
malekith authored
238 }
239 }
240 }
241 }
Something went wrong with that request. Please try again.