Minor cleanup
Now it constructs the context and parser only once.
This commit is contained in:
parent
9373c59c44
commit
8e093a98c7
1 changed files with 11 additions and 7 deletions
|
@ -7,6 +7,7 @@ namespace arookas {
|
||||||
sunContext mContext;
|
sunContext mContext;
|
||||||
sunBinary mBinary;
|
sunBinary mBinary;
|
||||||
sunImportResolver mResolver;
|
sunImportResolver mResolver;
|
||||||
|
sunParser mParser;
|
||||||
|
|
||||||
internal sunContext Context {
|
internal sunContext Context {
|
||||||
get { return mContext; }
|
get { return mContext; }
|
||||||
|
@ -18,6 +19,11 @@ namespace arookas {
|
||||||
get { return mResolver; }
|
get { return mResolver; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sunCompiler() {
|
||||||
|
mContext = new sunContext();
|
||||||
|
mParser = new sunParser();
|
||||||
|
}
|
||||||
|
|
||||||
public sunCompilerResults Compile(string name, Stream output) {
|
public sunCompilerResults Compile(string name, Stream output) {
|
||||||
return Compile(name, output, sunImportResolver.Default);
|
return Compile(name, output, sunImportResolver.Default);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +41,7 @@ namespace arookas {
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
try {
|
try {
|
||||||
mResolver = resolver;
|
mResolver = resolver;
|
||||||
mContext = new sunContext();
|
mContext.Clear();
|
||||||
using (mBinary = new sunBinary(output)) {
|
using (mBinary = new sunBinary(output)) {
|
||||||
var result = Import(name);
|
var result = Import(name);
|
||||||
if (result != sunImportResult.Loaded) {
|
if (result != sunImportResult.Loaded) {
|
||||||
|
@ -74,16 +80,14 @@ namespace arookas {
|
||||||
throw new ArgumentNullException("name");
|
throw new ArgumentNullException("name");
|
||||||
}
|
}
|
||||||
sunScriptFile file;
|
sunScriptFile file;
|
||||||
var result = ImportResolver.ResolveImport(name, out file);
|
var result = mResolver.ResolveImport(name, out file);
|
||||||
if (result == sunImportResult.Loaded) {
|
if (result == sunImportResult.Loaded) {
|
||||||
try {
|
try {
|
||||||
ImportResolver.EnterFile(file);
|
mResolver.EnterFile(file);
|
||||||
mContext.PushLocal();
|
mContext.PushLocal();
|
||||||
var parser = new sunParser();
|
mParser.Parse(file).Compile(this);
|
||||||
var tree = parser.Parse(file);
|
|
||||||
tree.Compile(this);
|
|
||||||
mContext.PopLocal();
|
mContext.PopLocal();
|
||||||
ImportResolver.ExitFile(file);
|
mResolver.ExitFile(file);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
file.Dispose();
|
file.Dispose();
|
||||||
|
|
Loading…
Add table
Reference in a new issue