VsaEngine.cs 6.4 KB

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