2005-02-14 Cesar Lopez Nataren <cnataren@novell.com>
authorCésar Natarén <cesar@mono-cvs.ximian.com>
Mon, 14 Feb 2005 08:01:36 +0000 (08:01 -0000)
committerCésar Natarén <cesar@mono-cvs.ximian.com>
Mon, 14 Feb 2005 08:01:36 +0000 (08:01 -0000)
* Added this file.

* Makefile: add reference to Microsoft.Vsa.
* mjs.cs (Main): As we can't directly create a Context outside of
Microsoft.JScript, we use the VsaEngine to add the code items and
after that guide the compilation, added method
GetCodeFromFile. Added class MonoEngineSite.

svn path=/trunk/mcs/; revision=40606

mcs/tools/mjs/ChangeLog [new file with mode: 0644]
mcs/tools/mjs/Makefile
mcs/tools/mjs/mjs.cs

diff --git a/mcs/tools/mjs/ChangeLog b/mcs/tools/mjs/ChangeLog
new file mode 100644 (file)
index 0000000..2042e17
--- /dev/null
@@ -0,0 +1,10 @@
+2005-02-14  Cesar Lopez Nataren  <cnataren@novell.com>
+
+       * Added this file.
+       
+       * Makefile: add reference to Microsoft.Vsa.
+       * mjs.cs (Main): As we can't directly create a Context outside of
+       Microsoft.JScript, we use the VsaEngine to add the code items and
+       after that guide the compilation, added method
+       GetCodeFromFile. Added class MonoEngineSite.
+
index 140ec05da2d94c2092ba9335acd0573fd9738e28..dbcdb2c2a2cb12dfba218d6c4b011a3716a9ae1c 100644 (file)
@@ -3,6 +3,6 @@ SUBDIRS =
 include ../../build/rules.make
 
 PROGRAM = mjs.exe
-LOCAL_MCS_FLAGS = /r:Microsoft.JScript.dll
+LOCAL_MCS_FLAGS = /r:Microsoft.JScript.dll /r:Microsoft.Vsa.dll
 
 include ../../build/executable.make
index 875255f772995111f6b7c7f86edc676980cb62b6..c91643ea23b7fc2a4ab15c61e647459f7d621181 100644 (file)
@@ -5,6 +5,7 @@
 //     Cesar Lopez Nataren (cesar@ciencias.unam.mx)
 //
 // (C) 2003, Cesar Lopez Nataren
+// (C) 2005, Novell Inc. (http://www.novell.com)
 //
 
 //
 //
 
 using System;
+using System.IO;
+using Microsoft.Vsa;
+using Microsoft.JScript;
+using Microsoft.JScript.Vsa;
 
-namespace Microsoft.JScript {
-
-       public class Driver {
-               
-               public static void Main (string [] args) {
+class Driver {         
+       public static void Main (string [] args) {
        
-                       if (args.Length < 1) {
-                               Console.WriteLine ("Usage: [mono] mjs.exe filename.js");
-                               Environment.Exit (0);
-                       }
-
-                       string filename = args [0];
-                       Context ctx = new Context (filename);
-                       JSParser parser = new JSParser (ctx);
-                       ScriptBlock prog_tree = parser.Parse ();                        
-                       SemanticAnalyser.Run (prog_tree);
-                       CodeGenerator.Run (args [0], prog_tree);
-                       Console.WriteLine ("Compilation succeeded.");
+               if (args.Length < 1) {
+                       Console.WriteLine ("Usage: [mono] mjs.exe filename.js");
+                       Environment.Exit (0);
                }
+
+               VsaEngine engine = new VsaEngine ();
+               engine.InitVsaEngine ("mjs:com.mono-project", new MonoEngineSite ());
+
+               foreach (string fn in args) {
+                       IVsaCodeItem item = (IVsaCodeItem) engine.Items.CreateItem (fn, VsaItemType.Code, VsaItemFlag.None);
+                       item.SourceText = GetCodeFromFile (fn);
+               }
+               engine.Compile ();
+       }
+
+       static string GetCodeFromFile (string fn)
+       {
+               try {
+                       StreamReader reader = new StreamReader (fn);
+                       return reader.ReadToEnd ();
+               } catch (FileNotFoundException) {
+                       throw new JScriptException (JSError.FileNotFound);
+               } catch (ArgumentNullException) {
+                       throw new JScriptException (JSError.FileNotFound);
+               } catch (ArgumentException) {
+                       throw new JScriptException (JSError.FileNotFound);
+               } catch (IOException) {
+                       throw new JScriptException (JSError.NoError);
+               } catch (OutOfMemoryException) {
+                       throw new JScriptException (JSError.OutOfMemory);
+               }
+       }
+}
+
+class MonoEngineSite : IVsaSite {
+       public void GetCompiledState (out byte [] pe, out byte [] debugInfo)
+       {
+               throw new NotImplementedException ();
+       }
+
+       public object GetEventSourceInstance (string itemName, string eventSourceName)
+       {
+               throw new NotImplementedException ();
+       }
+
+       public object GetGlobalInstance (string name)
+       {
+               throw new NotImplementedException ();
+       }
+
+       public void Notify (string notify, object info)
+       {
+               throw new NotImplementedException ();
+       }
+
+       public bool OnCompilerError (IVsaError error)
+       {
+               throw new NotImplementedException ();
        }
 }