public void Align(ProtoCore.Runtime.RuntimeMemory rMem) { if (null == rMem) { return; } mRestorePoint = 0; mStack.Clear(); mRestorePoint = rMem.Stack.Count; //Record the stack elements which is above the frame pointer int nDiff = mRestorePoint - rMem.FramePointer; for (int i = 0; i < nDiff; i++) { mStack.Add(rMem.Pop()); } mRestorePoint = rMem.Stack.Count; mRmem = rMem; return; }
/// <summary> /// VM Debugging API for general Debugging purposes /// temporarily used by Cmmand Line REPL /// </summary> /// <returns></returns> public string GetCoreDump() { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols StringBuilder globaltrace = null; ProtoCore.DSASM.Executive exec = runnerCore.CurrentExecutive.CurrentDSASMExec; ProtoCore.DSASM.Mirror.ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runnerCore); ProtoCore.DSASM.Executable exe = exec.rmem.Executable; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. string formattedString = string.Empty; if (exe.runtimeSymbols.Length > 0) { int blockId = 0; ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { //int n = symbolTable.symbolList.Count - 1; //formatParams.ResetOutputDepth(); ProtoCore.DSASM.SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { // These have gone out of scope, their values no longer exist //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); continue; } ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem; ProtoCore.DSASM.StackValue sv = rmem.GetStackData(blockId, i, ProtoCore.DSASM.Constants.kGlobalScope); formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId)); //if (null != globaltrace) //{ // int maxLength = 1020; // while (formattedString.Length > maxLength) // { // globaltrace.AppendLine(formattedString.Substring(0, maxLength)); // formattedString = formattedString.Remove(0, maxLength); // } // globaltrace.AppendLine(formattedString); //} } //formatParams.ResetOutputDepth(); } //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); return(formattedString); }
public void SetExprInterpreterProperties(int currentBlockID, ProtoCore.Runtime.RuntimeMemory memState, int watchScope, DebugProperties debugProps) { CurrentBlockId = currentBlockID; MemoryState = memState; WatchClassScope = watchScope; DebugProps = debugProps; }
public static StackValue ConcatString(StackValue op1, StackValue op2, ProtoCore.Runtime.RuntimeMemory rmem) { StackValue[] v1 = (AddressType.String == op1.optype) ? rmem.GetArrayElements(op1) : new StackValue[] { op1 }; StackValue[] v2 = (AddressType.String == op2.optype) ? rmem.GetArrayElements(op2) : new StackValue[] { op2 }; StackValue tmp = rmem.BuildArray(v1.Concat(v2).ToArray()); return(StackUtils.BuildString(tmp.opdata)); }
public static StackValue ConcatString(StackValue op1, StackValue op2, ProtoCore.Runtime.RuntimeMemory rmem) { StackValue[] v1 = op1.IsString ? rmem.GetArrayElements(op1) : new StackValue[] { op1 }; StackValue[] v2 = op2.IsString ? rmem.GetArrayElements(op2) : new StackValue[] { op2 }; StackValue tmp = rmem.BuildArray(v1.Concat(v2).ToArray()); return(StackValue.BuildString(tmp.opdata)); }
public static StackValue ConvertToString(StackValue sv, Core core, ProtoCore.Runtime.RuntimeMemory rmem) { StackValue returnSV; //TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new DSASM.Mirror.ExecutionMirror(new ProtoCore.DSASM.Executive(core), core); returnSV = ProtoCore.DSASM.StackValue.BuildString(mirror.GetStringValue(sv, core.Heap, 0, true), core.Heap); return(returnSV); }
public void SetData(string source, Dictionary <string, Object> context, Dictionary <string, bool> flagList, int currentBlockID, ProtoCore.Runtime.RuntimeMemory memState) { SourceCode = source; GlobalVarList = context; execFlagList = flagList; exprExecutionFlags = new Dictionary <int, bool>(); applySSATransform = true; CurrentBlockId = currentBlockID; MemoryState = memState; }
public void Align(ProtoCore.Runtime.RuntimeMemory rMem) { if (null == rMem) return; mRestorePoint = 0; mStack.Clear(); mRestorePoint = rMem.Stack.Count; //Record the stack elements which is above the frame pointer int nDiff = mRestorePoint - rMem.FramePointer; for (int i = 0; i < nDiff; i++) { mStack.Add(rMem.Pop()); } mRestorePoint = rMem.Stack.Count; mRmem = rMem; return; }
public static StackValue Coerce(StackValue sv, Type targetType, RuntimeCore runtimeCore) { ProtoCore.Runtime.RuntimeMemory rmem = runtimeCore.RuntimeMemory; //@TODO(Jun): FIX ME - abort coersion for default args if (sv.IsDefaultArgument) { return(sv); } if (!( sv.metaData.type == targetType.UID || (runtimeCore.DSExecutable.classTable.ClassNodes[sv.metaData.type].ConvertibleTo(targetType.UID)) || sv.IsArray)) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.ConversionNotPossible, Resources.kConvertNonConvertibleTypes); return(StackValue.Null); } //if it's an array if (sv.IsArray && !targetType.IsIndexable) { //This is an array rank reduction //this may only be performed in recursion and is illegal here string errorMessage = String.Format(Resources.kConvertArrayToNonArray, runtimeCore.DSExecutable.TypeSystem.GetType(targetType.UID)); runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.ConversionNotPossible, errorMessage); return(StackValue.Null); } if (sv.IsArray && targetType.IsIndexable) { Validity.Assert(sv.IsArray); //We're being asked to convert an array into an array //walk over the structure converting each othe elements //Validity.Assert(targetType.rank != -1, "Arbitrary rank array conversion not yet implemented {2EAF557F-62DE-48F0-9BFA-F750BBCDF2CB}"); //Decrease level of reductions by one Type newTargetType = new Type(); newTargetType.UID = targetType.UID; if (targetType.rank != Constants.kArbitraryRank) { newTargetType.rank = targetType.rank - 1; } else { if (ArrayUtils.GetMaxRankForArray(sv, runtimeCore) == 1) { //Last unpacking newTargetType.rank = 0; } else { newTargetType.rank = Constants.kArbitraryRank; } } var array = runtimeCore.Heap.ToHeapObject <DSArray>(sv); return(array.CopyArray(newTargetType, runtimeCore)); } if (!sv.IsArray && !sv.IsNull && targetType.IsIndexable && targetType.rank != DSASM.Constants.kArbitraryRank) { //We're being asked to promote the value into an array if (targetType.rank == 1) { Type newTargetType = new Type(); newTargetType.UID = targetType.UID; newTargetType.Name = targetType.Name; newTargetType.rank = 0; //Upcast once StackValue coercedValue = Coerce(sv, newTargetType, runtimeCore); try { StackValue newSv = rmem.Heap.AllocateArray(new StackValue[] { coercedValue }); return(newSv); } catch (RunOutOfMemoryException) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(StackValue.Null); } } else { Validity.Assert(targetType.rank > 1, "Target rank should be greater than one for this clause"); Type newTargetType = new Type(); newTargetType.UID = targetType.UID; newTargetType.Name = targetType.Name; newTargetType.rank = targetType.rank - 1; //Upcast once StackValue coercedValue = Coerce(sv, newTargetType, runtimeCore); try { StackValue newSv = rmem.Heap.AllocateArray(new StackValue[] { coercedValue }); return(newSv); } catch (RunOutOfMemoryException) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(StackValue.Null); } } } if (sv.IsPointer) { StackValue ret = ClassCoerece(sv, targetType, runtimeCore); return(ret); } //If it's anything other than array, just create a new copy switch (targetType.UID) { case (int)PrimitiveType.InvalidType: runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.InvalidType, Resources.kInvalidType); return(StackValue.Null); case (int)PrimitiveType.Bool: return(sv.ToBoolean(runtimeCore)); case (int)PrimitiveType.Char: { StackValue newSV = sv.ShallowClone(); newSV.metaData = new MetaData { type = (int)PrimitiveType.Char }; return(newSV); } case (int)PrimitiveType.Double: return(sv.ToDouble()); case (int)PrimitiveType.FunctionPointer: if (sv.metaData.type != (int)PrimitiveType.FunctionPointer) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.TypeMismatch, Resources.kFailToConverToFunction); return(StackValue.Null); } return(sv); case (int)PrimitiveType.Integer: { if (sv.metaData.type == (int)PrimitiveType.Double) { //TODO(lukechurch): Once the API is improved (MAGN-5174) //Replace this with a log entry notification //core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeConvertionCauseInfoLoss, Resources.kConvertDoubleToInt); } return(sv.ToInteger()); } case (int)PrimitiveType.Null: { if (sv.metaData.type != (int)PrimitiveType.Null) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.TypeMismatch, Resources.kFailToConverToNull); return(StackValue.Null); } return(sv); } case (int)PrimitiveType.Pointer: { if (sv.metaData.type != (int)PrimitiveType.Null) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.TypeMismatch, Resources.kFailToConverToPointer); return(StackValue.Null); } return(sv); } case (int)PrimitiveType.String: { StackValue newSV = sv.ShallowClone(); newSV.metaData = new MetaData { type = (int)PrimitiveType.String }; if (sv.metaData.type == (int)PrimitiveType.Char) { char ch = Convert.ToChar(newSV.CharValue); newSV = StackValue.BuildString(ch.ToString(), rmem.Heap); } return(newSV); } case (int)PrimitiveType.Var: { return(sv); } case (int)PrimitiveType.Array: { var array = runtimeCore.Heap.ToHeapObject <DSArray>(sv); return(array.CopyArray(targetType, runtimeCore)); } default: if (sv.IsNull) { return(StackValue.Null); } else { throw new NotImplementedException("Requested coercion not implemented"); } } }
private void ResetAll(Options options) { ProtoCore.Utils.Validity.AssertExpiry(); Options = options; Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>(); FunctionTable = new Lang.FunctionTable(); ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; Heap = new DSASM.Heap(); Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap); watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new DSASM.ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope); //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<ProtoCore.ReplicationGuide>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex; if (options.SuppressBuildOutput) { // don't log any of the build related messages // just accumulate them in relevant containers with // BuildStatus object // BuildStatus = new BuildStatus(this, false, false, false); } else { BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning); } RuntimeStatus = new RuntimeStatus(this); SSASubscript = 0; SSASubscript_GUID = System.Guid.NewGuid(); ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>(); //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); Configurations = new Dictionary<string, object>(); ContinuationStruct = new Lang.ContinuationStructure(); ParsingMode = ProtoCore.ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); csExecutionState = null; EnableCallsiteExecutionState = false; // TODO: Remove check once fully implemeted if (EnableCallsiteExecutionState) { csExecutionState = CallsiteExecutionState.LoadState(); } else { csExecutionState = new CallsiteExecutionState(); } CallsiteCache = new Dictionary<int, CallSite>(); CachedSSANodes = new List<AssociativeNode>(); CallSiteToNodeMap = new Dictionary<Guid, Guid>(); ASTToCallSiteMap = new Dictionary<int, CallSite>(); ForLoopBlockIndex = ProtoCore.DSASM.Constants.kInvalidIndex; GraphNodeCallList = new List<GraphNode>(); newEntryPoint = ProtoCore.DSASM.Constants.kInvalidIndex; }
private void ResetAll(Options options) { ProtoCore.Utils.Validity.AssertExpiry(); Options = options; Executives = new Dictionary<ProtoCore.Language, ProtoCore.Executive>(); FunctionTable = new Lang.FunctionTable(); ClassIndex = ProtoCore.DSASM.Constants.kInvalidIndex; Heap = new DSASM.Heap(); Rmem = new ProtoCore.Runtime.RuntimeMemory(Heap); watchClassScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchFunctionScope = ProtoCore.DSASM.Constants.kInvalidIndex; watchBaseOffset = 0; watchStack = new List<StackValue>(); watchSymbolList = new List<SymbolNode>(); watchFramePointer = ProtoCore.DSASM.Constants.kInvalidIndex; ID = FIRST_CORE_ID; //recurtion recursivePoint = new List<FunctionCounter>(); funcCounterTable = new List<FunctionCounter>(); calledInFunction = false; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; RunningBlock = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List<DSASM.CodeBlock>(); CompleteCodeBlockList = new List<DSASM.CodeBlock>(); DSExecutable = new ProtoCore.DSASM.Executable(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new DSASM.ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new DSASM.ProcedureTable(ProtoCore.DSASM.Constants.kGlobalScope); //Initialize the function pointer table FunctionPointerTable = new DSASM.FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DSASM.DynamicVariableTable(); DynamicFunctionTable = new DSASM.DynamicFunctionTable(); replicationGuides = new List<List<int>>(); ExceptionHandlingManager = new ExceptionHandlingManager(); startPC = ProtoCore.DSASM.Constants.kInvalidIndex; deltaCompileStartPC = ProtoCore.DSASM.Constants.kInvalidIndex; RuntimeStatus = new RuntimeStatus(this); SSASubscript = 0; ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; ExecMode = ProtoCore.DSASM.InterpreterMode.kNormal; assocCodegen = null; FunctionCallDepth = 0; // Default execution log is Console.Out. this.ExecutionLog = Console.Out; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started DebugProps = new DebugProperties(); //stackNodeExecutedSameTimes = new Stack<List<AssociativeGraph.GraphNode>>(); //stackExecutingGraphNodes = new Stack<AssociativeGraph.GraphNode>(); InterpreterProps = new Stack<InterpreterProperties>(); stackActiveExceptionRegistration = new Stack<ExceptionRegistration>(); ExecutiveProvider = new ExecutiveProvider(); Configurations = new Dictionary<string, object>(); ContinuationStruct = new Lang.ContinuationStructure(); ParsingMode = ProtoCore.ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); }