2 // driver.cs: Guides the compilation process through the different phases.
5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) 2003, Cesar Lopez Nataren
8 // (C) 2005, Novell Inc. (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using Microsoft.JScript;
36 using Microsoft.JScript.Vsa;
39 public static void Main (string [] args) {
41 if (args.Length < 1) {
42 Console.WriteLine ("Usage: mjs filename.js");
46 VsaEngine engine = new VsaEngine ();
47 engine.InitVsaEngine ("mjs:com.mono-project", new MonoEngineSite ());
49 foreach (string fn in args) {
50 IVsaCodeItem item = (IVsaCodeItem) engine.Items.CreateItem (fn, VsaItemType.Code, VsaItemFlag.None);
51 item.SourceText = GetCodeFromFile (fn);
56 static string GetCodeFromFile (string fn)
59 StreamReader reader = new StreamReader (fn);
60 return reader.ReadToEnd ();
61 } catch (FileNotFoundException) {
62 throw new JScriptException (JSError.FileNotFound);
63 } catch (ArgumentNullException) {
64 throw new JScriptException (JSError.FileNotFound);
65 } catch (ArgumentException) {
66 throw new JScriptException (JSError.FileNotFound);
67 } catch (IOException) {
68 throw new JScriptException (JSError.NoError);
69 } catch (OutOfMemoryException) {
70 throw new JScriptException (JSError.OutOfMemory);
75 class MonoEngineSite : IVsaSite {
76 public void GetCompiledState (out byte [] pe, out byte [] debugInfo)
78 throw new NotImplementedException ();
81 public object GetEventSourceInstance (string itemName, string eventSourceName)
83 throw new NotImplementedException ();
86 public object GetGlobalInstance (string name)
88 throw new NotImplementedException ();
91 public void Notify (string notify, object info)
93 throw new NotImplementedException ();
96 public bool OnCompilerError (IVsaError error)
98 throw new NotImplementedException ();