public bool Compile(string code, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { // No More HashAngleReplace for unified parser (Fuqiang) //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
public bool Compile(string code, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { // No More HashAngleReplace for unified parser (Fuqiang) //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return buildSucceeded; }
/// <summary> /// Compile and execute the source that is stored in the static context /// </summary> /// <param name="staticContext"></param> /// <param name="runtimeContext"></param> /// <param name="core"></param> /// <param name="isTest"></param> /// <returns></returns> public ExecutionMirror Execute(ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext, ProtoCore.Core core, bool isTest = true) { Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode); core.AddContextData(staticContext.GlobalVarList); int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; bool succeeded = Compile(staticContext, core, out blockId); if (succeeded) { core.GenerateExecutable(); Validity.Assert(null != runtimeContext); Execute(core, blockId, staticContext, runtimeContext); if (!isTest) { core.Heap.Free(); } } else { throw new ProtoCore.Exceptions.CompileErrorsOccured(); } if (isTest && !core.Options.CompileToLib) { return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core)); } return(null); }
public bool Compile(string code, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { // No More HashAngleReplace for unified parser (Fuqiang) //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); System.IO.MemoryStream sourceMemStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(code)); ProtoScript.GenerateScript gs = new ProtoScript.GenerateScript(core); core.Script = gs.preParseFromStream(sourceMemStream); foreach (ProtoCore.LanguageCodeBlock codeblock in core.Script.codeblockList) { ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = codeblock.language; core.Executives[id].Compile(out blockId, null, codeblock, context, EventSink); } core.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
public CoreCodeGen(Core coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null) { Debug.Assert(coreObj != null); this.core = coreObj; argOffset = 0; globalClassIndex = core.ClassIndex; if (null == CoreCodeGen.CodeRangeTable) { CoreCodeGen.CodeRangeTable = new CodeRangeTable(); } if (null == CoreCodeGen.IdentLocation) { CoreCodeGen.IdentLocation = new IdentLocationTable(); } if (null == CoreCodeGen.ImportTable) { CoreCodeGen.ImportTable = new ImportTable(); } context = new ProtoCore.CompileTime.Context(); opKwData = new ProtoCore.DSASM.OpKeywordData(); targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex; enforceTypeCheck = true; localProcedure = core.ProcNode; globalProcIndex = null != localProcedure ? localProcedure.procId : ProtoCore.DSASM.Constants.kGlobalScope; tryLevel = 0; }
/// <summary> /// Does the first pass of compilation and returns a list of wanrnings in compilation /// </summary> /// <param name="code"></param> /// <param name="core"></param> /// <param name="blockId"></param> /// <returns></returns> public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlockNode codeBlock, out int blockId) { core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Executives[id].Compile(out blockId, null, globalBlock, context, codeBlockNode: codeBlock); core.BuildStatus.ReportBuildResult(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (!(ex is ProtoCore.BuildHaltException)) { throw ex; } } return(core.BuildStatus); }
public ProtoLanguage.CompileStateTracker Compile(string code, out int blockId) { ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { System.IO.MemoryStream sourceMemStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(code)); ProtoScript.GenerateScript gs = new ProtoScript.GenerateScript(compileState); compileState.Script = gs.preParseFromStream(sourceMemStream); foreach (ProtoCore.LanguageCodeBlock codeblock in compileState.Script.codeblockList) { ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = codeblock.language; compileState.Executives[id].Compile(compileState, out blockId, null, codeblock, context, EventSink); } compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(compileState); }
/// <summary> /// A list of the current known breakpoints /// Interact with through register and unregister methods /// </summary> #endregion private bool Compile(out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.Language; core.Compilers[id].Compile(out blockId, null, globalBlock, context); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; core.GenerateExecutable(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); } return(buildSucceeded); }
public CoreCodeGen(ProtoLanguage.CompileStateTracker compileState, ProtoCore.DSASM.CodeBlock parentBlock = null) { Debug.Assert(compileState != null); this.compileState = compileState; argOffset = 0; globalClassIndex = compileState.ClassIndex; if (null == CoreCodeGen.CodeRangeTable) CoreCodeGen.CodeRangeTable = new CodeRangeTable(); if (null == CoreCodeGen.IdentLocation) CoreCodeGen.IdentLocation = new IdentLocationTable(); if (null == CoreCodeGen.ImportTable) CoreCodeGen.ImportTable = new ImportTable(); context = new ProtoCore.CompileTime.Context(); targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex; enforceTypeCheck = true; localProcedure = compileState.ProcNode; globalProcIndex = null != localProcedure ? localProcedure.procId : ProtoCore.DSASM.Constants.kGlobalScope; tryLevel = 0; }
public override bool Compile( out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink = null, ProtoCore.AST.Node codeBlockNode = null, ProtoCore.AssociativeGraph.GraphNode graphNode = null) { Validity.Assert(langBlock != null); bool buildSucceeded = true; blockId = 0; core.assocCodegen = new ProtoVHDL.CodeGen(core, callContext, parentBlock); System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(langBlock.body)); ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core, core.builtInsLoaded); p.Parse(); core.builtInsLoaded = true; codeBlockNode = p.root; List <ProtoCore.AST.Node> astNodes = ProtoCore.Utils.ParserUtils.GetAstNodes(codeBlockNode); core.AstNodeList = astNodes; core.assocCodegen.Emit(codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode); buildSucceeded = core.BuildStatus.BuildSucceeded; return(buildSucceeded); }
public bool Compile(string code, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { // No More HashAngleReplace for unified parser (Fuqiang) //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); System.IO.MemoryStream sourceMemStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(code)); ProtoScript.GenerateScript gs = new ProtoScript.GenerateScript(core); core.Script = gs.preParseFromStream(sourceMemStream); foreach (ProtoCore.LanguageCodeBlock codeblock in core.Script.codeblockList) { ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = codeblock.language; core.Executives[id].Compile(out blockId, null, codeblock, context, EventSink); } core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return buildSucceeded; }
private bool Compile(string code, ProtoCore.Core core, ProtoCore.CompileTime.Context context) { bool buildSucceeded = false; try { // No More HashAngleReplace for unified parser (Fuqiang) //String strSource = ProtoCore.Utils.LexerUtils.HashAngleReplace(code); //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.Language id = globalBlock.Language; int blockId = Constants.kInvalidIndex; core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
public ProtoLanguage.CompileStateTracker Compile(string code, out int blockId) { ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink); compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(compileState); }
public ProtoLanguage.CompileStateTracker Compile(string code, out int blockId) { ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { System.IO.MemoryStream sourceMemStream = new System.IO.MemoryStream(System.Text.Encoding.Default.GetBytes(code)); ProtoScript.GenerateScript gs = new ProtoScript.GenerateScript(compileState); compileState.Script = gs.preParseFromStream(sourceMemStream); foreach (ProtoCore.LanguageCodeBlock codeblock in compileState.Script.codeblockList) { ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = codeblock.language; compileState.Executives[id].Compile(compileState, out blockId, null, codeblock, context, EventSink); } compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return compileState; }
/// <summary> /// Compile and execute the source that is stored in the static context /// </summary> /// <param name="staticContext"></param> /// <param name="runtimeContext"></param> /// <param name="core"></param> /// <param name="isTest"></param> /// <returns></returns> public ExecutionMirror Execute( ProtoCore.CompileTime.Context staticContext, ProtoCore.Core core, out ProtoCore.RuntimeCore runtimeCoreOut, bool isTest = true) { Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode); ProtoCore.RuntimeCore runtimeCore = null; core.AddContextData(staticContext.GlobalVarList); string code = staticContext.SourceCode; bool succeeded = CompileAndGenerateExe(code, core, staticContext); if (succeeded) { runtimeCore = ExecuteVM(core); if (!isTest) { runtimeCore.RuntimeMemory.Heap.Free(); } } else { throw new ProtoCore.Exceptions.CompileErrorsOccured(); } runtimeCoreOut = runtimeCore; if (isTest) { return(new ExecutionMirror(runtimeCore.CurrentExecutive.CurrentDSASMExec, runtimeCore)); } return(null); }
protected int ExecuteAndVerify(String code, ValidationData[] data, Dictionary<string, Object> context, out int nErrors) { ProtoCore.Core core = Setup(); ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScript.Runners.ProtoScriptRunner(); ProtoCore.CompileTime.Context compileContext = new ProtoCore.CompileTime.Context(code, context); ProtoCore.RuntimeCore runtimeCore = null; ExecutionMirror mirror = fsr.Execute(compileContext, core, out runtimeCore); int nWarnings = runtimeCore.RuntimeStatus.WarningCount; nErrors = core.BuildStatus.ErrorCount; if (data == null) { runtimeCore.Cleanup(); return nWarnings + nErrors; } TestFrameWork thisTest = new TestFrameWork(); foreach (var item in data) { if (item.ExpectedValue == null) { object nullOb = null; TestFrameWork.Verify(mirror, item.ValueName, nullOb, item.BlockIndex); } else { TestFrameWork.Verify(mirror, item.ValueName, item.ExpectedValue, item.BlockIndex); } } runtimeCore.Cleanup(); return nWarnings + nErrors; }
/// <summary> /// Does the first pass of compilation and returns a list of wanrnings in compilation /// </summary> /// <param name="code"></param> /// <param name="core"></param> /// <param name="blockId"></param> /// <returns></returns> public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlockNode codeBlock, out int blockId) { blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.Language; core.Compilers[id].Compile(out blockId, null, globalBlock, context, codeBlockNode: codeBlock); core.BuildStatus.ReportBuildResult(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (!(ex is ProtoCore.BuildHaltException)) { throw ex; } } return(core.BuildStatus); }
/// <summary> /// The public method to compile DS AST and stores the executable in core /// </summary> /// <param name="astList"></param> /// <param name="compileCore"></param> /// <returns></returns> public bool CompileAndGenerateExe( List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core compileCore, ProtoCore.CompileTime.Context context) { bool succeeded = Compile(astList, compileCore, context); if (succeeded) { compileCore.GenerateExecutable(); } return(succeeded); }
private ProtoLanguage.CompileStateTracker Compile(out int blockId) { blockId = ProtoCore.DSASM.Constants.kInvalidIndex; compileState = ProtoScript.CompilerUtils.BuildDebuggertCompilerState(); compileState.CurrentDSFileName = core.CurrentDSFileName; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink); compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; compileState.compileSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); // This is the boundary between compilestate and runtime core // Generate the executable compileState.GenerateExecutable(); // Get the executable from the compileState core.DSExecutable = compileState.DSExecutable; core.Rmem.PushGlobFrame(compileState.GlobOffset); } catch (Exception ex) { Messages.FatalCompileError fce = new Messages.FatalCompileError { Message = ex.ToString() }; Console.WriteLine(fce.Message); return(null); } return(compileState); }
public void PreStart(String source, Dictionary <string, Object> context) { ProtoCore.Options options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; RunnerCore = new ProtoCore.Core(options); RunnerCore.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(RunnerCore)); RunnerCore.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(RunnerCore)); ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); ExecutionContext = new ProtoCore.CompileTime.Context(source, context); Runner = new ProtoScriptRunner(); }
public void PreStart(String source, Dictionary<string, Object> context) { ProtoCore.Options options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; RunnerCore = new ProtoCore.Core(options); RunnerCore.Compilers.Add(ProtoCore.Language.Associative, new ProtoAssociative.Compiler(RunnerCore)); RunnerCore.Compilers.Add(ProtoCore.Language.Imperative, new ProtoImperative.Compiler(RunnerCore)); ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); ExecutionContext = new ProtoCore.CompileTime.Context(source, context); Runner = new ProtoScriptRunner(); }
public bool Compile(string code, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; //compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; compileState.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, compileState); // Save the global offset and restore after compilation int offsetRestore = compileState.GlobOffset; compileState.GlobOffset = Core.Rmem.Stack.Count; compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink); // Restore the global offset compileState.GlobOffset = offsetRestore; compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
public ExecutionMirror Execute(ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext, ProtoCore.Core core, bool isTest = true) { Validity.Assert(null != staticContext.SourceCode && String.Empty != staticContext.SourceCode); int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; ProtoLanguage.CompileStateTracker compileState = Compile(staticContext, core, out blockId); Validity.Assert(null != compileState); if (compileState.compileSucceeded) { // This is the boundary between compilestate and runtime core // Generate the executable compileState.GenerateExecutable(); // Get the executable from the compileState core.DSExecutable = compileState.DSExecutable; core.Rmem.PushGlobFrame(compileState.GlobOffset); core.RunningBlock = blockId; core.InitializeContextGlobals(staticContext.GlobalVarList); Validity.Assert(null != runtimeContext); Execute(core, runtimeContext, compileState); if (!isTest) { core.Heap.Free(); } } else { throw new ProtoCore.Exceptions.CompileErrorsOccured(); } if (isTest && !core.Options.CompileToLib) { return(new ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core)); } // Save the Callsite state for this execution if (core.EnableCallsiteExecutionState) { ProtoCore.CallsiteExecutionState.SaveState(core.csExecutionState); } return(null); }
public bool Compile(string code, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; //compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; compileState.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, compileState); // Save the global offset and restore after compilation int offsetRestore = compileState.GlobOffset; compileState.GlobOffset = Core.Rmem.Stack.Count; compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink); // Restore the global offset compileState.GlobOffset = offsetRestore; compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return buildSucceeded; }
public bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; if (astList.Count <= 0) { // Nothing to compile buildSucceeded = true; } else { try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = string.Empty; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); context.SetData(string.Empty, new Dictionary <string, object>(), null); ProtoCore.Language id = globalBlock.language; ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); codeblock.Body.AddRange(astList); core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } return(buildSucceeded); }
public bool Compile(string code, int currentBlockID, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; //globalBlock.language = ProtoCore.Language.kImperative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); context.SetExprInterpreterProperties(currentBlockID, runtimeCore.RuntimeMemory, runtimeCore.watchClassScope, runtimeCore.DebugProps); ProtoCore.Language id = globalBlock.language; runtimeCore.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, Core); // Save the global offset and restore after compilation int offsetRestore = Core.GlobOffset; Core.GlobOffset = runtimeCore.RuntimeMemory.Stack.Count; Core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink); // Restore the global offset Core.GlobOffset = offsetRestore; Core.BuildStatus.ReportBuildResult(); buildSucceeded = Core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
private void InitRunner(Options options) { graphCompiler = GraphToDSCompiler.GraphCompiler.CreateInstance(); graphCompiler.SetCore(GraphUtilities.GetCore()); runner = new ProtoScriptTestRunner(); executionOptions = options; InitOptions(); InitCore(); taskQueue = new Queue <Task>(); workerThread = new Thread(new ThreadStart(TaskExecMethod)); workerThread.IsBackground = true; workerThread.Start(); staticContext = new ProtoCore.CompileTime.Context(); }
/// <summary> /// Execute the data stored in core /// This is the entry point of all DS code to be executed /// </summary> /// <param name="core"></param> /// <param name="runningBlock"></param> /// <param name="staticContext"></param> /// <param name="runtimeContext"></param> public ProtoCore.RuntimeCore Execute( ProtoCore.Core core, int runningBlock, ProtoCore.CompileTime.Context staticContext, ProtoCore.Runtime.Context runtimeContext) { //========================Generate runtimecore here===============================// ProtoCore.RuntimeCore runtimeCore = core.__TempCoreHostForRefactoring; // Move these core setup to runtime core runtimeCore.RuntimeMemory.PushFrameForGlobals(core.GlobOffset); runtimeCore.RunningBlock = runningBlock; runtimeCore.RuntimeStatus.MessageHandler = core.BuildStatus.MessageHandler; try { runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBegin); foreach (ProtoCore.DSASM.CodeBlock codeblock in core.CodeBlockList) { // Comment Jun: // On first bounce, the stackframe depth is initialized to -1 in the Stackfame constructor. // Passing it to bounce() increments it so the first depth is always 0 ProtoCore.DSASM.StackFrame stackFrame = new ProtoCore.DSASM.StackFrame(core.GlobOffset); stackFrame.FramePointer = runtimeCore.RuntimeMemory.FramePointer; // Comment Jun: Tell the new bounce stackframe that this is an implicit bounce // Register TX is used for this. StackValue svCallConvention = StackValue.BuildCallingConversion((int)ProtoCore.DSASM.CallingConvention.BounceType.kImplicit); stackFrame.TX = svCallConvention; // Initialize the entry point interpreter int locals = 0; // This is the global scope, there are no locals ProtoCore.DSASM.Interpreter interpreter = new ProtoCore.DSASM.Interpreter(runtimeCore); runtimeCore.CurrentExecutive.CurrentDSASMExec = interpreter.runtime; runtimeCore.CurrentExecutive.CurrentDSASMExec.Bounce(codeblock.codeBlockId, codeblock.instrStream.entrypoint, runtimeContext, stackFrame, locals); } runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd); } catch { runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionEnd); throw; } return(runtimeCore); }
public bool Compile(string code, int currentBlockID, out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; //globalBlock.language = ProtoCore.Language.kImperative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); context.SetExprInterpreterProperties(currentBlockID, runtimeCore.RuntimeMemory, runtimeCore.watchClassScope, runtimeCore.DebugProps); ProtoCore.Language id = globalBlock.language; runtimeCore.ExprInterpreterExe.iStreamCanvas = new InstructionStream(globalBlock.language, Core); // Save the global offset and restore after compilation int offsetRestore = Core.GlobOffset; Core.GlobOffset = runtimeCore.RuntimeMemory.Stack.Count; Core.Compilers[id].Compile(out blockId, null, globalBlock, context, EventSink); // Restore the global offset Core.GlobOffset = offsetRestore; Core.BuildStatus.ReportBuildResult(); buildSucceeded = Core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return buildSucceeded; }
public DependencyTracker Analyse(LanguageCodeBlock cb, ProtoCore.CompileTime.Context ct) { //@TODO: Replace this with a parser //For now, assume that the code block is //a = 1..1000..+1 //b = SQRT(a) //c = a * 2 //d = //{ // FromPoint(a<1>, b<2>, c<3>) //} //This will give us an AST representation DependencyTracker tracker = new DependencyTracker(); throw new NotImplementedException(); }
public bool Compile(List <ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = string.Empty; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); codeblock.Body.AddRange(astList); core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock); core.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(buildSucceeded); }
private bool Compile(out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink); core.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings); core.GenerateExecutable(); core.Rmem.PushGlobFrame(core.GlobOffset); } catch (Exception ex) { Messages.FatalCompileError fce = new Messages.FatalCompileError { Message = ex.ToString() }; Console.WriteLine(fce.Message); return(false); } return(buildSucceeded); }
public ProtoVMState PreStart(String source, Dictionary <string, Object> context) { ProtoCore.Options options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; RunnerCore = new ProtoCore.Core(options); RunnerCore.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(RunnerCore)); RunnerCore.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(RunnerCore)); ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); //Validity.Assert(null == ExecutionContext); ExecutionContext = new ProtoCore.CompileTime.Context(source, context); //Validity.Assert(null == Runner); Runner = new ProtoScriptRunner(); // TODO Jun: Implement run and halt at the first instruction //ProtoCore.DSASM.Mirror.ExecutionMirror mirror = null; // runner.Execute(executionContext, RunnerCore); return(new ProtoVMState(RunnerCore, runtimeCore)); }
public ProtoVMState PreStart(String source, Dictionary<string, Object> context) { ProtoCore.Options options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; RunnerCore = new ProtoCore.Core(options); RunnerCore.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(RunnerCore)); RunnerCore.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(RunnerCore)); ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper()); //Validity.Assert(null == ExecutionContext); ExecutionContext = new ProtoCore.CompileTime.Context(source, context); //Validity.Assert(null == Runner); Runner = new ProtoScriptRunner(); // TODO Jun: Implement run and halt at the first instruction //ProtoCore.DSASM.Mirror.ExecutionMirror mirror = null; // runner.Execute(executionContext, RunnerCore); return new ProtoVMState(RunnerCore, runtimeCore); }
public ProtoLanguage.CompileStateTracker Compile(string code, ProtoCore.Core core, out int blockId) { ProtoLanguage.CompileStateTracker compileState = ProtoScript.CompilerUtils.BuildDefaultCompilerState(); bool buildSucceeded = false; core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; compileState.Executives[id].Compile(compileState, out blockId, null, globalBlock, context, EventSink); compileState.BuildStatus.ReportBuildResult(); int errors = 0; int warnings = 0; compileState.compileSucceeded = buildSucceeded = compileState.BuildStatus.GetBuildResult(out errors, out warnings); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return compileState; }
/// <summary> /// The public method to compile DS code and stores the executable in core /// </summary> /// <param name="sourcecode"></param> /// <param name="compileCore"></param> /// <returns></returns> public bool CompileAndGenerateExe(string sourcecode, ProtoCore.Core compileCore, ProtoCore.CompileTime.Context context) { bool succeeded = Compile(sourcecode, compileCore, context); if (succeeded) { compileCore.GenerateExecutable(); } return(succeeded); }
private void InitRunner(Options options) { graphCompiler = GraphToDSCompiler.GraphCompiler.CreateInstance(); graphCompiler.SetCore(GraphUtilities.GetCore()); runner = new ProtoScriptTestRunner(); executionOptions = options; InitOptions(); InitCore(); taskQueue = new Queue<Task>(); workerThread = new Thread(new ThreadStart(TaskExecMethod)); workerThread.IsBackground = true; workerThread.Start(); staticContext = new ProtoCore.CompileTime.Context(); terminating = false; changeSetComputer = new ChangeSetComputer(runnerCore); changeSetApplier = new ChangeSetApplier(); }
public abstract bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock codeblock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink = null, ProtoCore.AST.Node codeBlockNode = null, ProtoCore.AssociativeGraph.GraphNode graphNode = null);
/// <summary> /// Re-initializes the LiveRunner to reset the VM /// Used temporarily when importing libraries on-demand during delta execution /// Will be deprecated once this is supported by the core language /// </summary> public void ReInitializeLiveRunner() { runner = new ProtoScriptTestRunner(); executionOptions = new Options(); deltaSymbols = 0; coreOptions = null; InitOptions(); InitCore(); staticContext = new ProtoCore.CompileTime.Context(); changeSetComputer = new ChangeSetComputer(runnerCore); CLRModuleType.ClearTypes(); }
private void EmitLanguageBlockNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode graphNode, ProtoCore.DSASM.AssociativeSubCompilePass subPass = ProtoCore.DSASM.AssociativeSubCompilePass.kNone) { // // TODO Jun: // Add support for language blocks, classes and functions in GRAPH post july release // This Temporary guard will no longer be necessary bool disableLanguageBlocks = compileStateTracker.IsParsingCodeBlockNode || compileStateTracker.IsParsingPreloadedAssembly; if (disableLanguageBlocks) { compileStateTracker.BuildStatus.LogSemanticError("Defining language blocks are not yet supported"); } if (IsParsingGlobal() || IsParsingGlobalFunctionBody() || IsParsingMemberFunctionBody() ) { if (subPass == ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier) { return; } LanguageBlockNode langblock = node as LanguageBlockNode; //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.kInvalid == langblock.codeblock.language) throw new BuildHaltException("Invalid language block type (D1B95A65)"); ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); int entry = 0; int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; // Top block signifies the auto inserted global block bool isTopBlock = null == codeBlock.parent; // The warning is enforced only if this is not the top block if (ProtoCore.Language.kAssociative == langblock.codeblock.language && !isTopBlock) { // TODO Jun: Move the associative and all common string into some table buildStatus.LogSyntaxError("An associative language block is declared within an associative language block.", compileStateTracker.CurrentDSFileName, langblock.line, langblock.col); } // Set the current class scope so the next language can refer to it compileStateTracker.ClassIndex = globalClassIndex; if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && compileStateTracker.ProcNode == null) { if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex) compileStateTracker.ProcNode = compileStateTracker.ClassTable.ClassNodes[globalClassIndex].vtable.procList[globalProcIndex]; else compileStateTracker.ProcNode = codeBlock.procedureTable.procList[globalProcIndex]; } ProtoCore.AssociativeGraph.GraphNode propagateGraphNode = null; if (compileStateTracker.Options.AssociativeToImperativePropagation && Language.kImperative == langblock.codeblock.language) { propagateGraphNode = graphNode; } compileStateTracker.Executives[langblock.codeblock.language].Compile(compileStateTracker, out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode, propagateGraphNode); graphNode.isLanguageBlock = true; graphNode.languageBlockId = blockId; setBlkId(blockId); inferedType = compileStateTracker.InferedType; //Debug.Assert(codeBlock.children[codeBlock.children.Count - 1].blockType == ProtoCore.DSASM.CodeBlockType.kLanguage); codeBlock.children[codeBlock.children.Count - 1].Attributes = PopulateAttributes(langblock.Attributes); #if ENABLE_EXCEPTION_HANDLING core.ExceptionHandlingManager.Register(blockId, globalProcIndex, globalClassIndex); #endif int startpc = pc; EmitInstrConsole(ProtoCore.DSASM.kw.bounce + " " + blockId + ", " + entry.ToString()); EmitBounceIntrinsic(blockId, entry); // The callee language block will have stored its result into the RX register. EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regRX); ProtoCore.DSASM.StackValue opRes = new ProtoCore.DSASM.StackValue(); opRes.optype = ProtoCore.DSASM.AddressType.Register; opRes.opdata = (int)ProtoCore.DSASM.Registers.RX; EmitPush(opRes); } }
public LiveRunner(Configuration configuration) { this.configuration = configuration; graphCompiler = GraphCompiler.CreateInstance(); graphCompiler.SetCore(GraphUtilities.GetCore()); runner = new ProtoScriptTestRunner(); InitCore(); taskQueue = new Queue<Task>(); workerThread = new Thread(new ThreadStart(TaskExecMethod)); workerThread.IsBackground = true; workerThread.Start(); staticContext = new ProtoCore.CompileTime.Context(); terminating = false; changeSetComputer = new ChangeSetComputer(runnerCore); changeSetApplier = new ChangeSetApplier(); }
public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null) { Debug.Assert(langBlock != null); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; bool buildSucceeded = false; bool isLanguageSignValid = isLanguageSignValid = core.Langverify.Verify(langBlock); if (isLanguageSignValid) { try { ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(core, parentBlock); //(Fuqiang, Ayush) : The below code is to parse an Imperative code block. An imoerative code block should // never need to be parsed at this stage, as it would be parsed by the Assoc parser. //System.IO.MemoryStream memstream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(langBlock.body)); //ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(memstream); //ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core); //System.IO.StringWriter parseErrors = new System.IO.StringWriter(); //p.errors.errorStream = parseErrors; //p.Parse(); //if (parseErrors.ToString() != String.Empty) //{ // core.BuildStatus.LogSyntaxError(parseErrors.ToString()); //} //core.BuildStatus.errorCount += p.errors.count; codegen.context = callContext; codegen.codeBlock.EventSink = sink; blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode); } catch (ProtoCore.BuildHaltException e) { #if DEBUG //core.BuildStatus.LogSemanticError(e.errorMsg); #endif } int errors = 0; int warnings = 0; buildSucceeded = core.BuildStatus.GetBuildResult(out errors, out warnings); } return(buildSucceeded); }
public LiveRunner(Configuration configuration) { this.configuration = configuration; runner = new ProtoScriptRunner(); InitCore(); taskQueue = new Queue<Task>(); workerThread = new Thread(new ThreadStart(TaskExecMethod)); workerThread.IsBackground = true; workerThread.Start(); staticContext = new ProtoCore.CompileTime.Context(); terminating = false; changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore); changeSetApplier = new ChangeSetApplier(); }
public LiveRunner(Configuration configuration) { this.configuration = configuration; runner = new ProtoScriptRunner(); InitCore(); staticContext = new ProtoCore.CompileTime.Context(); changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore); changeSetApplier = new ChangeSetApplier(); }
public CodeGen(Core coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null) { Validity.Assert(coreObj != null); core = coreObj; buildStatus = core.BuildStatus; isEntrySet = false; emitReplicationGuide = false; dumpByteCode = core.Options.DumpByteCode; isAssocOperator = false; pc = 0; argOffset = 0; globalClassIndex = core.ClassIndex; context = new ProtoCore.CompileTime.Context(); targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex; enforceTypeCheck = true; localProcedure = core.ProcNode; globalProcIndex = null != localProcedure ? localProcedure.ID : ProtoCore.DSASM.Constants.kGlobalScope; tryLevel = 0; functionCallStack = new List<DSASM.ProcedureNode>(); IsAssociativeArrayIndexing = false; if (core.AsmOutput == null) { core.AsmOutput = Console.Out; } ssaPointerStack = new Stack<List<AST.AssociativeAST.AssociativeNode>>(); }
/// <summary> /// Does the first pass of compilation and returns a list of wanrnings in compilation /// </summary> /// <param name="code"></param> /// <param name="core"></param> /// <param name="blockId"></param> /// <returns></returns> public static ProtoCore.BuildStatus PreCompile(string code, Core core, CodeBlockNode codeBlock, out int blockId) { blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.Language; core.Compilers[id].Compile(out blockId, null, globalBlock, context, codeBlockNode: codeBlock); core.BuildStatus.ReportBuildResult(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (!(ex is ProtoCore.BuildHaltException)) { throw ex; } } return core.BuildStatus; }
/// <summary> /// Does the first pass of compilation and returns a list of wanrnings in compilation /// </summary> /// <param name="code"></param> /// <param name="core"></param> /// <param name="blockId"></param> /// <returns></returns> private static ProtoCore.BuildStatus PreCompile(string code, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Executives[id].Compile(out blockId, null, globalBlock, context); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); if (!(ex is ProtoCore.BuildHaltException)) { throw ex; } } return core.BuildStatus; }
private bool Compile(out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = code; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.language; core.Compilers[id].Compile(out blockId, null, globalBlock, context); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; core.GenerateExecutable(); } catch (Exception ex) { Messages.FatalCompileError fce = new Messages.FatalCompileError { Message = ex.ToString() }; Console.WriteLine(fce.Message); return false; } return buildSucceeded; }
private void EmitLanguageBlockNode(ImperativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode propogateUpdateGraphNode = null) { if (IsParsingGlobal() || IsParsingGlobalFunctionBody()) { LanguageBlockNode langblock = node as LanguageBlockNode; //(Fuqiang, Ayush) : Throwing an assert stops NUnit. Negative tests expect to catch a // CompilerException, so we throw that instead. //Validity.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.kInvalid == langblock.codeblock.language) { throw new ProtoCore.Exceptions.CompileErrorsOccured("Invalid language block"); } ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); // Save the guid of the current scope (which is stored in the current graphnodes) to the nested language block. // This will be passed on to the nested language block that will be compiled if (propogateUpdateGraphNode != null) { context.guid = propogateUpdateGraphNode.guid; } int entry = 0; int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; if (ProtoCore.Language.kImperative == langblock.codeblock.language) { // TODO Jun: Move the associative and all common string into some table buildStatus.LogSyntaxError(Resources.InvalidNestedImperativeBlock, core.CurrentDSFileName, langblock.line, langblock.col); } if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && core.ProcNode == null) core.ProcNode = codeBlock.procedureTable.procList[globalProcIndex]; core.Compilers[langblock.codeblock.language].Compile(out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode); if (propogateUpdateGraphNode != null) { propogateUpdateGraphNode.languageBlockId = blockId; CodeBlock childBlock = core.CompleteCodeBlockList[blockId]; foreach (var subGraphNode in childBlock.instrStream.dependencyGraph.GraphList) { foreach (var depentNode in subGraphNode.dependentList) { if (depentNode.updateNodeRefList != null && depentNode.updateNodeRefList.Count > 0 && depentNode.updateNodeRefList[0].nodeList != null && depentNode.updateNodeRefList[0].nodeList.Count > 0) { SymbolNode dependentSymbol = depentNode.updateNodeRefList[0].nodeList[0].symbol; int symbolBlockId = dependentSymbol.codeBlockId; if (symbolBlockId != Constants.kInvalidIndex) { CodeBlock symbolBlock = core.CompleteCodeBlockList[symbolBlockId]; if (!symbolBlock.IsMyAncestorBlock(codeBlock.codeBlockId)) { propogateUpdateGraphNode.PushDependent(depentNode); } } } } } } setBlkId(blockId); inferedType = core.InferedType; //Validity.Assert(codeBlock.children[codeBlock.children.Count - 1].blockType == ProtoCore.DSASM.CodeBlockType.kLanguage); codeBlock.children[codeBlock.children.Count - 1].Attributes = PopulateAttributes(langblock.Attributes); EmitInstrConsole("bounce " + blockId + ", " + entry.ToString()); EmitBounceIntrinsic(blockId, entry); // The callee language block will have stored its result into the RX register. EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regRX); StackValue opRes = StackValue.BuildRegister(Registers.RX); EmitPush(opRes); } }
public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink, ProtoCore.AST.Node codeBlockNode, ProtoCore.AssociativeGraph.GraphNode graphNode = null) { Validity.Assert(langBlock != null); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; bool buildSucceeded = false; try { ProtoImperative.CodeGen codegen = new ProtoImperative.CodeGen(core, callContext, parentBlock); codegen.context = callContext; codegen.codeBlock.EventSink = sink; blockId = codegen.Emit(codeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode, graphNode); } catch (ProtoCore.BuildHaltException) { } buildSucceeded = core.BuildStatus.BuildSucceeded; return(buildSucceeded); }
private void EmitLanguageBlockNode(ImperativeNode node, ref ProtoCore.Type inferedType) { if (IsParsingGlobal() || IsParsingGlobalFunctionBody()) { LanguageBlockNode langblock = node as LanguageBlockNode; //(Fuqiang, Ayush) : Throwing an assert stops NUnit. Negative tests expect to catch a // CompilerException, so we throw that instead. //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.kInvalid == langblock.codeblock.language) { throw new ProtoCore.Exceptions.CompileErrorsOccured("Invalid language block"); } ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && compileState.ProcNode == null) compileState.ProcNode = codeBlock.procedureTable.procList[globalProcIndex]; if (langblock.codeblock.language == Language.kAssociative) { AssociativeCodeGen codegen = new AssociativeCodeGen(compileState, codeBlock); blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode); } else if (langblock.codeblock.language == Language.kImperative) { ImperativeCodeGen codegen = new ImperativeCodeGen(compileState, codeBlock); blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode); } //core.Executives[langblock.codeblock.language].Compile(out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode); inferedType = compileState.InferedType; ExceptionRegistration registration = compileState.ExceptionHandlingManager.ExceptionTable.GetExceptionRegistration(blockId, globalProcIndex, globalClassIndex); if (registration == null) { registration = compileState.ExceptionHandlingManager.ExceptionTable.Register(blockId, globalProcIndex, globalClassIndex); Debug.Assert(registration != null); } } }
private void EmitLanguageBlockNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.DSASM.AssociativeSubCompilePass subPass = ProtoCore.DSASM.AssociativeSubCompilePass.kNone) { if (IsParsingGlobal() || IsParsingGlobalFunctionBody() || IsParsingMemberFunctionBody()) { if (subPass == ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier) { return; } LanguageBlockNode langblock = node as LanguageBlockNode; //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.kInvalid == langblock.codeblock.language) throw new BuildHaltException("Invalid language block type"); ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; // Top block signifies the auto inserted global block bool isTopBlock = null == codeBlock.parent; // Set the current class scope so the next language can refer to it core.ClassIndex = globalClassIndex; if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && core.ProcNode == null) { if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex) core.ProcNode = core.ClassTable.ClassNodes[globalClassIndex].vtable.procList[globalProcIndex]; else core.ProcNode = codeBlock.procedureTable.procList[globalProcIndex]; } if (langblock.codeblock.language == Language.kAssociative) { AssociativeCodeGen codegen = new AssociativeCodeGen(core, codeBlock); blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode); } else if (langblock.codeblock.language == Language.kImperative) { ImperativeCodeGen codegen = new ImperativeCodeGen(core, codeBlock); blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode); } //core.Executives[langblock.codeblock.language].Compile(out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode); inferedType = core.InferedType; ExceptionRegistration registration = core.ExceptionHandlingManager.ExceptionTable.GetExceptionRegistration(blockId, globalProcIndex, globalClassIndex); if (registration == null) { registration = core.ExceptionHandlingManager.ExceptionTable.Register(blockId, globalProcIndex, globalClassIndex); Debug.Assert(registration != null); } } }
/// <summary> /// Re-initializes the LiveRunner to reset the VM /// Used temporarily when importing libraries on-demand during delta execution /// Will be deprecated once this is supported by the core language /// </summary> public void ReInitializeLiveRunner() { runner = new ProtoScriptRunner(); deltaSymbols = 0; InitCore(); staticContext = new ProtoCore.CompileTime.Context(); changeSetComputer = new ChangeSetComputer(runnerCore, runtimeCore); CLRModuleType.ClearTypes(); }
public CodeGen(Core coreObj, ProtoCore.DSASM.CodeBlock parentBlock = null) { Validity.Assert(coreObj != null); core = coreObj; buildStatus = core.BuildStatus; isEntrySet = false; emitReplicationGuide = false; dumpByteCode = core.Options.DumpByteCode; isAssocOperator = false; pc = 0; argOffset = 0; globalClassIndex = core.ClassIndex; context = new ProtoCore.CompileTime.Context(); targetLangBlock = ProtoCore.DSASM.Constants.kInvalidIndex; enforceTypeCheck = true; localProcedure = core.ProcNode; globalProcIndex = null != localProcedure ? localProcedure.ID : ProtoCore.DSASM.Constants.kGlobalScope; tryLevel = 0; functionCallStack = new List<DSASM.ProcedureNode>(); IsAssociativeArrayIndexing = false; if (core.AsmOutput == null) { if (core.Options.CompileToLib) { string path = ""; if (core.Options.LibPath == null) { path += core.Options.RootModulePathName + "ASM"; } else { path = Path.Combine(core.Options.LibPath, Path.GetFileNameWithoutExtension(core.Options.RootModulePathName) + ".dsASM"); } core.AsmOutput = new StreamWriter(File.Open(path, FileMode.Create)); } else { core.AsmOutput = Console.Out; } } ssaPointerStack = new Stack<List<AST.AssociativeAST.AssociativeNode>>(); }
private void EmitLanguageBlockNode(ImperativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode propogateUpdateGraphNode = null) { // // TODO Jun: // Add support for language blocks, classes and functions in GRAPH post july release // This Temporary guard will no longer be necessary bool disableLanguageBlocks = compileStateTracker.IsParsingCodeBlockNode || compileStateTracker.IsParsingPreloadedAssembly; if (disableLanguageBlocks) { compileStateTracker.BuildStatus.LogSemanticError("Defining language blocks are not yet supported"); } if (IsParsingGlobal() || IsParsingGlobalFunctionBody()) { LanguageBlockNode langblock = node as LanguageBlockNode; //(Fuqiang, Ayush) : Throwing an assert stops NUnit. Negative tests expect to catch a // CompilerException, so we throw that instead. //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.kInvalid == langblock.codeblock.language) { throw new ProtoCore.Exceptions.CompileErrorsOccured("Invalid language block"); } ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); int entry = 0; int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; if (ProtoCore.Language.kImperative == langblock.codeblock.language) { // TODO Jun: Move the associative and all common string into some table buildStatus.LogSyntaxError("An imperative language block is declared within an imperative language block.", compileStateTracker.CurrentDSFileName, langblock.line, langblock.col); } if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && compileStateTracker.ProcNode == null) { compileStateTracker.ProcNode = codeBlock.procedureTable.procList[globalProcIndex]; } compileStateTracker.Executives[langblock.codeblock.language].Compile(compileStateTracker, out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode); if (propogateUpdateGraphNode != null) { propogateUpdateGraphNode.languageBlockId = blockId; CodeBlock childBlock = compileStateTracker.CompleteCodeBlockList[blockId]; foreach (var subGraphNode in childBlock.instrStream.dependencyGraph.GraphList) { foreach (var depentNode in subGraphNode.dependentList) { if (depentNode.updateNodeRefList != null && depentNode.updateNodeRefList.Count > 0 && depentNode.updateNodeRefList[0].nodeList != null && depentNode.updateNodeRefList[0].nodeList.Count > 0) { SymbolNode dependentSymbol = depentNode.updateNodeRefList[0].nodeList[0].symbol; int symbolBlockId = dependentSymbol.codeBlockId; if (symbolBlockId != Constants.kInvalidIndex) { CodeBlock symbolBlock = compileStateTracker.CompleteCodeBlockList[symbolBlockId]; if (!symbolBlock.IsMyAncestorBlock(codeBlock.codeBlockId)) { propogateUpdateGraphNode.PushDependent(depentNode); } } } } } } setBlkId(blockId); inferedType = compileStateTracker.InferedType; //Debug.Assert(codeBlock.children[codeBlock.children.Count - 1].blockType == ProtoCore.DSASM.CodeBlockType.kLanguage); codeBlock.children[codeBlock.children.Count - 1].Attributes = PopulateAttributes(langblock.Attributes); #if ENABLE_EXCEPTION_HANDLING core.ExceptionHandlingManager.Register(blockId, globalProcIndex, globalClassIndex); #endif EmitInstrConsole("bounce " + blockId + ", " + entry.ToString()); EmitBounceIntrinsic(blockId, entry); // The callee language block will have stored its result into the RX register. EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regRX); ProtoCore.DSASM.StackValue opRes = new ProtoCore.DSASM.StackValue(); opRes.optype = ProtoCore.DSASM.AddressType.Register; opRes.opdata = (int)ProtoCore.DSASM.Registers.RX; EmitPush(opRes); } }
/// <summary> /// A list of the current known breakpoints /// Interact with through register and unregister methods /// </summary> #endregion private bool Compile(out int blockId) { bool buildSucceeded = false; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.Language = ProtoCore.Language.Associative; globalBlock.Code = code; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); ProtoCore.Language id = globalBlock.Language; core.Compilers[id].Compile(out blockId, null, globalBlock, context); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; core.GenerateExecutable(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } return buildSucceeded; }
public override bool Compile(out int blockId, ProtoCore.DSASM.CodeBlock parentBlock, ProtoCore.LanguageCodeBlock langBlock, ProtoCore.CompileTime.Context callContext, ProtoCore.DebugServices.EventSink sink = null, ProtoCore.AST.Node codeBlockNode = null, ProtoCore.AssociativeGraph.GraphNode graphNode = null) { Validity.Assert(langBlock != null); blockId = ProtoCore.DSASM.Constants.kInvalidIndex; bool buildSucceeded = false; bool isLangSignValid = core.Langverify.Verify(langBlock); if (isLangSignValid) { try { ProtoCore.CodeGen oldCodegen = core.assocCodegen; if (ProtoCore.DSASM.InterpreterMode.kNormal == core.ExecMode) { if ((core.IsParsingPreloadedAssembly || core.IsParsingCodeBlockNode) && parentBlock == null) { if (core.CodeBlockList.Count == 0) { core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock); } else { // We reuse the existing toplevel CodeBlockList's for the procedureTable's // by calling this overloaded constructor - pratapa core.assocCodegen = new ProtoAssociative.CodeGen(core); } } else { core.assocCodegen = new ProtoAssociative.CodeGen(core, callContext, parentBlock); } } if (null != core.AssocNode) { ProtoCore.AST.AssociativeAST.CodeBlockNode cnode = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); cnode.Body.Add(core.AssocNode as ProtoCore.AST.AssociativeAST.AssociativeNode); core.assocCodegen.context = callContext; blockId = core.assocCodegen.Emit((cnode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode); } else { //if not null, Compile has been called from DfsTraverse. No parsing is needed. if (codeBlockNode == null) { var p = ParserUtils.CreateParser(langBlock.body, core); p.Parse(); // TODO Jun: Set this flag inside a persistent object core.builtInsLoaded = true; codeBlockNode = p.root; //core.AstNodeList = p.GetParsedASTList(codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode); List <ProtoCore.AST.Node> astNodes = ProtoCore.Utils.ParserUtils.GetAstNodes(codeBlockNode); core.AstNodeList = astNodes; } else { if (!core.builtInsLoaded) { // Load the built-in methods manually ProtoCore.Utils.CoreUtils.InsertPredefinedAndBuiltinMethods(core, codeBlockNode, false); core.builtInsLoaded = true; } } core.assocCodegen.context = callContext; //Temporarily change the code block for code gen to the current block, in the case it is an imperative block //CodeGen for ProtoImperative is modified to passing in the core object. ProtoCore.DSASM.CodeBlock oldCodeBlock = core.assocCodegen.codeBlock; if (core.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter) { int tempBlockId = core.GetCurrentBlockId(); ProtoCore.DSASM.CodeBlock tempCodeBlock = core.GetCodeBlock(core.CodeBlockList, tempBlockId); while (null != tempCodeBlock && tempCodeBlock.blockType != ProtoCore.DSASM.CodeBlockType.kLanguage) { tempCodeBlock = tempCodeBlock.parent; } core.assocCodegen.codeBlock = tempCodeBlock; } core.assocCodegen.codeBlock.EventSink = sink; if (core.BuildStatus.ErrorCount == 0) //if there is syntax error, no build needed { blockId = core.assocCodegen.Emit((codeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode), graphNode); } if (core.ExecMode == ProtoCore.DSASM.InterpreterMode.kExpressionInterpreter) { blockId = core.assocCodegen.codeBlock.codeBlockId; //Restore the code block. core.assocCodegen.codeBlock = oldCodeBlock; } } // @keyu: we have to restore asscoCodegen here. It may be // reused later on. Suppose for an inline expression // "x = 1 == 2 ? 3 : 4", we dynamically create assocCodegen // to compile true and false expression in this inline // expression, and if we don't restore assocCodegen, the pc // is totally messed up. // // But if directly replace with old assocCodegen, will it // replace some other useful information? Need to revisit it. // // Also refer to defect IDE-2120. if (oldCodegen != null && core.assocCodegen != oldCodegen) { core.assocCodegen = oldCodegen; } } catch (ProtoCore.BuildHaltException) { #if DEBUG //core.BuildStatus.LogSemanticError(e.errorMsg); #endif } buildSucceeded = core.BuildStatus.BuildSucceeded; } return(buildSucceeded); }
private void EmitLanguageBlockNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.AssociativeGraph.GraphNode graphNode, ProtoCore.CompilerDefinitions.Associative.SubCompilePass subPass = ProtoCore.CompilerDefinitions.Associative.SubCompilePass.kNone) { if (IsParsingGlobal() || IsParsingGlobalFunctionBody() || IsParsingMemberFunctionBody() ) { if (subPass == ProtoCore.CompilerDefinitions.Associative.SubCompilePass.kUnboundIdentifier) { return; } LanguageBlockNode langblock = node as LanguageBlockNode; //Validity.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.NotSpecified == langblock.codeblock.Language) throw new BuildHaltException("Invalid language block type (D1B95A65)"); ProtoCore.CompileTime.Context nextContext = new ProtoCore.CompileTime.Context(); // Save the guid of the current scope (which is stored in the current graphnodes) to the nested language block. // This will be passed on to the nested language block that will be compiled nextContext.guid = graphNode.guid; int entry = 0; int blockId = ProtoCore.DSASM.Constants.kInvalidIndex; // Top block signifies the auto inserted global block bool isTopBlock = null == codeBlock.parent; // The warning is enforced only if this is not the top block if (ProtoCore.Language.Associative == langblock.codeblock.Language && !isTopBlock) { // TODO Jun: Move the associative and all common string into some table buildStatus.LogSyntaxError(Resources.InvalidNestedAssociativeBlock, core.CurrentDSFileName, langblock.line, langblock.col); } // Set the current class scope so the next language can refer to it core.ClassIndex = globalClassIndex; if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && core.ProcNode == null) { if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex) core.ProcNode = core.ClassTable.ClassNodes[globalClassIndex].ProcTable.Procedures[globalProcIndex]; else core.ProcNode = codeBlock.procedureTable.Procedures[globalProcIndex]; } ProtoCore.AssociativeGraph.GraphNode propagateGraphNode = null; if (core.Options.AssociativeToImperativePropagation && Language.Imperative == langblock.codeblock.Language) { propagateGraphNode = graphNode; } core.Compilers[langblock.codeblock.Language].Compile(out blockId, codeBlock, langblock.codeblock, nextContext, codeBlock.EventSink, langblock.CodeBlockNode, propagateGraphNode); graphNode.isLanguageBlock = true; graphNode.languageBlockId = blockId; foreach (GraphNode dNode in nextContext.DependentVariablesInScope) { graphNode.PushDependent(dNode); } setBlkId(blockId); inferedType = core.InferedType; //Validity.Assert(codeBlock.children[codeBlock.children.Count - 1].blockType == ProtoCore.DSASM.CodeBlockType.kLanguage); codeBlock.children[codeBlock.children.Count - 1].Attributes = PopulateAttributes(langblock.Attributes); EmitInstrConsole(ProtoCore.DSASM.kw.bounce + " " + blockId + ", " + entry.ToString()); EmitBounceIntrinsic(blockId, entry); // The callee language block will have stored its result into the RX register. EmitInstrConsole(ProtoCore.DSASM.kw.push, ProtoCore.DSASM.kw.regRX); StackValue opRes = StackValue.BuildRegister(Registers.RX); EmitPush(opRes); } }
private void EmitDynamicLanguageBlockNode(AssociativeNode node, AssociativeNode singleBody, ref ProtoCore.Type inferedType, ref int blockId, ProtoCore.AssociativeGraph.GraphNode graphNode = null, ProtoCore.CompilerDefinitions.Associative.SubCompilePass subPass = ProtoCore.CompilerDefinitions.Associative.SubCompilePass.kNone) { if (IsParsingGlobal() || IsParsingGlobalFunctionBody() || IsParsingMemberFunctionBody()) { if (subPass == ProtoCore.CompilerDefinitions.Associative.SubCompilePass.kUnboundIdentifier) { return; } LanguageBlockNode langblock = node as LanguageBlockNode; //Validity.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language); if (ProtoCore.Language.NotSpecified == langblock.codeblock.Language) throw new BuildHaltException("Invalid language block type (B1C57E37)"); ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); // Set the current class scope so the next language can refer to it core.ClassIndex = globalClassIndex; if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && core.ProcNode == null) { if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex) core.ProcNode = core.ClassTable.ClassNodes[globalClassIndex].ProcTable.Procedures[globalProcIndex]; else core.ProcNode = codeBlock.procedureTable.Procedures[globalProcIndex]; } core.Compilers[langblock.codeblock.Language].Compile( out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode, null); } }
public bool Compile(List<ProtoCore.AST.AssociativeAST.AssociativeNode> astList, ProtoCore.Core core, out int blockId) { bool buildSucceeded = false; core.ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; blockId = ProtoCore.DSASM.Constants.kInvalidIndex; try { //defining the global Assoc block that wraps the entire .ds source file ProtoCore.LanguageCodeBlock globalBlock = new ProtoCore.LanguageCodeBlock(); globalBlock.language = ProtoCore.Language.kAssociative; globalBlock.body = string.Empty; //the wrapper block can be given a unique id to identify it as the global scope globalBlock.id = ProtoCore.LanguageCodeBlock.OUTERMOST_BLOCK_ID; //passing the global Assoc wrapper block to the compiler ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context(); context.SetData(string.Empty, new Dictionary<string, object>(), null); ProtoCore.Language id = globalBlock.language; ProtoCore.AST.AssociativeAST.CodeBlockNode codeblock = new ProtoCore.AST.AssociativeAST.CodeBlockNode(); codeblock.Body.AddRange(astList); core.Executives[id].Compile(out blockId, null, globalBlock, context, EventSink, codeblock); core.BuildStatus.ReportBuildResult(); buildSucceeded = core.BuildStatus.BuildSucceeded; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return buildSucceeded; }