2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / Microsoft.JScript / Microsoft.JScript.Vsa / VsaEngine.cs
1 //
2 // VsaEngine.cs:
3 //
4 // Author: Cesar Octavio Lopez Nataren
5 //
6 // (C) Cesar Octavio Lopez Nataren, <cesar@ciencias.unam.mx>
7 //
8
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using System;
31 using System.Reflection;
32 using Microsoft.Vsa;
33 using System.Collections;
34
35 namespace Microsoft.JScript.Vsa {
36
37         public class VsaEngine : BaseVsaEngine,  IRedirectOutput {
38                 
39                 static private Hashtable options;
40                 internal VsaScriptScope global_scope;
41                 internal Stack globals;
42
43                 public VsaEngine ()
44                         : this (true)
45                 {
46                         InitOptions ();
47                 }
48
49                 public VsaEngine (bool b)
50                         : base ("JScript", "0.0.1", true)
51                 {
52                         globals = new Stack (4);                        
53                 }
54
55                 public virtual IVsaEngine Clone (AppDomain appDom)
56                 {
57                         throw new NotImplementedException ();
58                 }
59
60                 public virtual bool CompileEmpty ()
61                 {
62                         throw new NotImplementedException ();
63                 }
64
65                 public virtual void ConectEvents ()
66                 {
67                         throw new NotImplementedException ();
68                 }
69
70                 public static GlobalScope CreateEngineAndGetGlobalScope (bool fast, string [] assembly_names)
71                 {
72                         int i, n;
73                         GlobalScope scope;
74
75                         VsaEngine engine = new VsaEngine (fast);                        
76                         engine.InitVsaEngine ("JScript.Vsa.VsaEngine://Microsoft.JScript.VsaEngine.Vsa",
77                                               new DefaultVsaSite ());
78                         n = assembly_names.Length;
79
80                         for (i = 0; i < n; i++) {
81                                 string assembly_name = assembly_names [i];
82                                 VsaReferenceItem r = (VsaReferenceItem) engine.Items.CreateItem (assembly_name,
83                                                                                                  VsaItemType.Reference,
84                                                                                                  VsaItemFlag.None);
85                                 r.AssemblyName = assembly_name;
86                         }
87                         scope = (GlobalScope) engine.GetGlobalScope ().GetObject ();
88                         return scope;
89                 }
90
91                 public static GlobalScope CreateEngineAndGetGlobalScopeWithType (bool b, string [] assemblyNames,
92                                                                                  RuntimeTypeHandle callTypeHandle)
93                 {
94                         throw new NotImplementedException ();
95                 }
96
97                 public static VsaEngine CreateEngine ()
98                 {
99                         throw new NotImplementedException ();
100                 }
101
102                 public static VsaEngine CreateEngineWithType (RuntimeTypeHandle callTypeHandle)
103                 {
104                         throw new NotImplementedException ();
105                 }
106
107                 public virtual void DisconnectEvents ()
108                 {
109                         throw new NotImplementedException ();
110                 }
111
112                 public virtual Assembly GetAssembly ()
113                 {
114                         throw new NotImplementedException ();
115                 }
116
117                 public virtual IVsaScriptScope GetGlobalScope ()
118                 {
119                         if (global_scope == null) {
120                                 global_scope = new VsaScriptScope (this, "Global", null);
121                         }
122
123                         return global_scope;
124                 }
125
126                 public virtual GlobalScope GetMainScope ()
127                 {
128                         throw new NotImplementedException ();
129                 }
130
131                 public virtual Module GetModule ()
132                 {
133                         throw new NotImplementedException ();
134                 }
135
136                 public ArrayConstructor GetOriginalArrayConstructor ()
137                 {
138                         throw new NotImplementedException ();
139                 }
140
141                 public ObjectConstructor GetOriginalObjectConstructor ()
142                 {
143                         throw new NotImplementedException ();
144                 }
145
146                 public RegExpConstructor GetOriginalRegExpConstructor ()
147                 {
148                         throw new NotImplementedException ();
149                 }
150
151                 public void InitVsaEngine (string moniker, IVsaSite site)
152                 {
153                         RootMoniker = moniker;
154                         Site = site;
155                         InitNewCalled = true;
156                         RootNamespace = "JScript.DefaultNamespace";
157                         IsDirty = true;
158                         compiled = false;
159                 }
160
161                 public virtual void Interrupt ()
162                 {
163                         throw new NotImplementedException ();
164                 }
165
166
167                 public override bool IsValidIdentifier (string ident)
168                 {
169                         throw new NotImplementedException ();
170                 }
171
172
173                 public LenientGlobalObject LenientGlobalObject {
174                         get { throw new NotImplementedException (); }
175                 }
176
177                 public ScriptObject PopScriptObject ()
178                 {
179                         ScriptObject script_obj = null;
180
181                         try {
182                                 script_obj = (ScriptObject) globals.Pop ();
183                         } catch (NullReferenceException e) {
184                         }
185                         return script_obj;
186                 }
187
188                 public void PushScriptObject (ScriptObject obj)
189                 {
190                         try {
191                                 globals.Push (obj);
192                         } catch (NullReferenceException e) {
193                         }
194                 }
195
196                 public virtual void RegisterEventSource (string name)
197                 {
198                         throw new NotImplementedException ();
199                 }
200
201                 public override void Reset ()
202                 {
203                         throw new NotImplementedException ();
204                 }
205
206                 public virtual void Restart ()
207                 {
208                         throw new NotImplementedException ();
209                 }
210
211                 public virtual void RunEmpty ()
212                 {
213                         throw new NotImplementedException ();
214                 }
215
216                 public virtual void Run (AppDomain appDom)
217                 {
218                         throw new NotImplementedException ();
219                 }
220
221                 public ScriptObject ScriptObjectStackTop ()
222                 {
223                         return (ScriptObject) globals.Peek ();
224                 }
225
226                 public virtual void SetOutputStream (IMessageReceiver output)
227                 {
228                         throw new NotImplementedException ();
229                 }
230
231                 internal static void InitOptions ()
232                 {
233                         options = new Hashtable ();
234                 
235                         options.Add ("AlwaysGenerateIL", false);
236                         options.Add ("CLSCompliant", false);
237                         options.Add ("DebugDirectory", "");
238                         options.Add ("Defines", new Hashtable ());
239                         options.Add ("Fast", true);
240                         // FIXME: "ManagedResources"
241                         options.Add ("Print", true);
242                         options.Add ("UseContextRelativeStatics", false);
243                         options.Add ("VersionSafe", false);
244                         options.Add ("WarnAsError", false);
245                         options.Add ("WarningLevel", 1);
246                         options.Add ("Win32Resource", "");
247                 }
248
249                 protected override object GetSpecificOption (string name)
250                 {
251                         object opt;
252
253                         try {
254                                 opt = options [name];
255                         } catch (NotSupportedException e) {
256                                 throw new VsaException (VsaError.OptionNotSupported);
257                         }
258                         return opt;
259                 }
260
261                 protected override void SetSpecificOption (string name, object val)
262                 {
263                         try {
264                                 options [name] = val;
265                         } catch (NotSupportedException e) {
266                                 throw new VsaException (VsaError.OptionNotSupported);
267                         }
268                 }
269         }
270
271         class DefaultVsaSite : BaseVsaSite {            
272         }
273 }