private ProtoCore.Core CompileCodeSnapshot(AutoCompleteWorkData workData) { if (null != this.scopeIdentifiers) { this.scopeIdentifiers.Clear(); this.scopeIdentifiers = null; } ProtoCore.Options options = new ProtoCore.Options(); options.RootModulePathName = workData.ScriptPath; ProtoCore.Core core = new ProtoCore.Core(options); core.CurrentDSFileName = workData.ScriptPath; ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); // Register a message stream if we do have one. if (null != this.MessageHandler) { core.BuildStatus.MessageHandler = this.MessageHandler; } MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(workData.CodeSnapshot)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(stream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core); try { p.Parse(); CoreCodeGen.arrayTypeTable = new ArrayTypeTable(); AssociativeCodeGen codegen = new AssociativeCodeGen(core); codegen.Emit(p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception Caught in CodeGen"); System.Diagnostics.Debug.WriteLine(ex.Message); core = null; } finally { // Do necessary clean-up here. } return(core); }
public static bool Compile(string src, string entryFile) { ProtoLanguage.CompileOptions ops = new ProtoLanguage.CompileOptions(); ops.RootModulePathName = entryFile; if (null != AutoCompletionHelper.searchPaths) { ops.IncludeDirectories.AddRange(AutoCompletionHelper.searchPaths); } compileState = new ProtoLanguage.CompileStateTracker(ops); compileState.CurrentDSFileName = entryFile; CoreCodeGen.ResetInternalStates(); ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); // Register a message stream if we do have one. if (null != AutoCompletionHelper.MessageHandler) { compileState.BuildStatus.MessageHandler = MessageHandler; } MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(src)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(ms); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, compileState); try { p.Parse(); CoreCodeGen.arrayTypeTable = new ArrayTypeTable(); AssociativeCodeGen codegen = new AssociativeCodeGen(compileState); codegen.Emit(p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception Caught in CodeGen"); System.Diagnostics.Debug.WriteLine(ex.Message); return(false); } return(true); }