/// <summary>
/// Compiles
/// <code>source</code>
/// and returns the transformed and optimized
/// <see cref="Rhino.Ast.ScriptNode">Rhino.Ast.ScriptNode</see>
/// </summary>
protected internal virtual ScriptNode Compile(CharSequence source)
{
string mainMethodClassName = "Main";
string scriptClassName = "Main";
CompilerEnvirons compilerEnv = new CompilerEnvirons();
compilerEnv.InitFromContext(cx);
ErrorReporter compilationErrorReporter = compilerEnv.GetErrorReporter();
Parser p = new Parser(compilerEnv, compilationErrorReporter);
AstRoot ast = p.Parse(source.ToString(), "<eval>", 1);
IRFactory irf = new IRFactory(compilerEnv);
ScriptNode tree = irf.TransformTree(ast);
Codegen codegen = new Codegen();
codegen.SetMainMethodClass(mainMethodClassName);
codegen.CompileToClassFile(compilerEnv, scriptClassName, tree, tree.GetEncodedSource(), false);
return tree;
}