internal override void Compile()
 {
     if (this.binaryCode == null)
     {
         JSParser parser = new JSParser(this.codeContext);
         if (base.ItemType == ((JSVsaItemType) 0x16))
         {
             this.binaryCode = parser.ParseExpressionItem();
         }
         else
         {
             this.binaryCode = parser.Parse();
         }
         if (this.optimize && !parser.HasAborted)
         {
             this.binaryCode.ProcessAssemblyAttributeLists();
             this.binaryCode.PartiallyEvaluate();
         }
         if (base.engine.HasErrors && !base.engine.alwaysGenerateIL)
         {
             throw new EndOfFile();
         }
         if (this.compileToIL)
         {
             this.compiledBlock = this.binaryCode.TranslateToILClass(base.engine.CompilerGlobals).CreateType();
         }
     }
 }
Beispiel #2
0
        public static void Run(string file_name, ScriptBlock [] blocks)
        {
            CodeGenerator.Init (file_name);

            //
            // Emit first all the declarations (function and variables)
            //
            foreach (ScriptBlock script_block in blocks)
                CodeGenerator.EmitDecls (script_block);

            //
            // emit everything that's not a declaration
            //
            foreach (ScriptBlock script_block in blocks)
                script_block.Emit ();

            //
            // Create the types ('JScript N')
            //
            foreach (ScriptBlock script_block in blocks)
                script_block.CreateType ();

            //
            // Build the default 'JScript Main' class
            //
            TypeBuilder main_type_builder = module_builder.DefineType ("JScript Main");
            emit_jscript_main (main_type_builder);
            main_type_builder.CreateType ();

            CodeGenerator.Save (trim_extension (file_name) + ".exe");
        }
 internal override void Close()
 {
     base.Close();
     this.binaryCode = null;
     this.scope = null;
     this.codeContext = null;
     this.compiledBlock = null;
 }
 public void AppendSourceText(string SourceCode)
 {
     if ((SourceCode != null) && (SourceCode.Length != 0))
     {
         this.codeContext.SetSourceContext(this.codeContext.document, this.codeContext.source_string + SourceCode);
         this.executed = false;
         this.binaryCode = null;
     }
 }
 internal VsaScriptCode(VsaEngine engine, string itemName, JSVsaItemType type, IVsaScriptScope scope) : base(engine, itemName, type, JSVsaItemFlag.None)
 {
     this.binaryCode = null;
     this.executed = false;
     this.scope = (VsaScriptScope) scope;
     this.codeContext = new Context(new DocumentContext(this), null);
     this.compiledBlock = null;
     this.compileToIL = true;
     this.optimize = true;
 }
 internal void Parse()
 {
     if ((this.block == null) && (this.compiledClass == null))
     {
         GlobalScope item = (GlobalScope) base.engine.GetGlobalScope().GetObject();
         item.evilScript = !item.fast || (base.engine.GetStaticCodeBlockCount() > 1);
         base.engine.Globals.ScopeStack.Push(item);
         try
         {
             JSParser parser = new JSParser(this.codeContext);
             this.block = parser.Parse();
             if (parser.HasAborted)
             {
                 this.block = null;
             }
         }
         finally
         {
             base.engine.Globals.ScopeStack.Pop();
         }
     }
 }
Beispiel #7
0
		internal Environment (ScriptBlock [] blocks)
			: this ()
		{
			//
			// FIXME: when we implement the package stm. For each package
			// name we must add a identification table that will store
			// id's defined inside it.
			//

			//
			// integrate the builtin functions, objects, ...
			//
			BuildGlobalEnv ();
		}
Beispiel #8
0
        ScriptBlock Parse()
        {
            decompiler = CreateDecompiler ();
            ScriptBlock current_script_or_fn = new ScriptBlock (new Location (ts.SourceName, ts.LineNumber));
            decompiler.GetCurrentOffset ();
            decompiler.AddToken (Token.SCRIPT);
            ok = true;

            try {
                for (;;) {
                    //hwd
                    try
                    {

                        ts.allow_reg_exp = true;
                        int tt = ts.GetToken();
                        ts.allow_reg_exp = false;

                        if (tt <= Token.EOF)
                            break;

                        AST n;
                        if (tt == Token.FUNCTION)
                        {
                            try
                            {
                                n = Function(current_script_or_fn, FunctionType.Statement);
                            }
                            catch (ParserException)
                            {
                                ok = false;
                                break;
                            }
                        }
                        else
                        {
                            ts.UnGetToken(tt);
                            n = Statement(current_script_or_fn);
                        }
                        current_script_or_fn.Add(n);

                    }
                    catch (Exception exc)
                    {
                        //hwd
                        ReportError(exc.Message);
                    }

                }
            } catch (StackOverflowException) {
                throw new Exception ("Error: too deep parser recursion.");
            }

            if (!ok)
                return null;

            this.decompiler = null; // It helps GC
            return current_script_or_fn;
        }
Beispiel #9
0
        internal ScriptBlock[] ParseAll()
        {
            int i = 0, n = code_items.Count;
            ScriptBlock [] blocks = new ScriptBlock [n];

            foreach (VsaCodeItem item in code_items)
                blocks [i++] = Parse (item.SourceText, item.Name, 0);

            return blocks;
        }
 internal override void Reset()
 {
     this.compiledClass = null;
     this.block = null;
     this.codeContext = new Context(new DocumentContext(this), this.codeContext.source_string);
 }
 internal override void Reset()
 {
     this.binaryCode = null;
     this.compiledBlock = null;
     this.executed = false;
     this.codeContext = new Context(new DocumentContext(this), this.codeContext.source_string);
 }
Beispiel #12
0
		internal static bool Run (ScriptBlock [] blocks, Assembly [] ref_items)
		{
			assemblies = ref_items;

			if (assemblies != null && assemblies.Length > 0)
				ComputeNamespaces ();

			env = new Environment (blocks);
			bool r = true;

			foreach (ScriptBlock script_block in blocks)
				((ICanModifyContext) script_block).PopulateContext (env, String.Empty);

			foreach (ScriptBlock script_block in blocks)
				r &= script_block.Resolve (env);

			return r;
		}
 internal void Parse() {
   if (this.block == null && this.compiledClass == null) {
     GlobalScope glob = (GlobalScope)this.engine.GetGlobalScope().GetObject();
     //Provide for the possibility of forward references to declarations in code blocks yet to come.
     glob.evilScript = !glob.fast || this.engine.GetStaticCodeBlockCount() > 1;
     this.engine.Globals.ScopeStack.Push(glob);
     try{
       JSParser p = new JSParser(this.codeContext);
       this.block = (ScriptBlock)p.Parse();
       if (p.HasAborted)
         this.block = null;
     }finally{
       this.engine.Globals.ScopeStack.Pop();
     }
   }
 }
 internal override void Reset() {
   this.compiledClass = null;
   this.block = null;
   // We reset codeContext because the DocumentContext holds a reference to engine.compilerGlobals
   // (which we must have set to null before calling Reset on the VsaItems).
   this.codeContext = new Context(new DocumentContext(this), this.codeContext.source_string);
 }
Beispiel #15
0
        internal static void EmitDecls(ScriptBlock prog)
        {
            if (prog == null)
                return;

            string next_type = CodeGenerator.NextType;

            prog.InitTypeBuilder (module_builder, next_type);
            prog.InitGlobalCode ();

            global_types.Add (next_type);
            global_methods.Add (next_type, prog.GlobalCode);
            source_file_to_type.Add (prog.Location.SourceName, next_type);

            prog.EmitDecls (module_builder);
        }