public void TestNonPointers01() { var heap = new Heap(); var values = new StackValue[] { StackValue.BuildInt(0), StackValue.BuildInt(1), StackValue.BuildInt(2) }; var array1 = heap.AllocateArray(values); var allTypes = new List<StackValue>(); var rawPointer = (int)array1.RawIntValue; for (int i = 0; i < (int)AddressType.ArrayKey; ++i) { var val = new StackValue() { optype = (AddressType)i, opdata = rawPointer }; if (!val.IsReferenceType) { allTypes.Add(val); } } var array2 = heap.AllocateArray(allTypes.ToArray()); heap.GCMarkAndSweep(new List<StackValue>() { array1}, testExecutive); Assert.IsNotNull(heap.ToHeapObject<DSArray>(array1)); heap.Free(); }
public RuntimeCore(Heap heap) { // The heap is initialized by the core and is used to allocate strings // Use the that heap for runtime Validity.Assert(heap != null); this.Heap = heap; RuntimeMemory = new RuntimeMemory(Heap); InterpreterProps = new Stack<InterpreterProperties>(); ReplicationGuides = new List<List<ReplicationGuide>>(); RunningBlock = 0; ExecutionState = (int)ExecutionStateEventArgs.State.kInvalid; //not yet started FFIPropertyChangedMonitor = new FFIPropertyChangedMonitor(this); ContinuationStruct = new ContinuationStructure(); watchStack = new List<StackValue>(); watchFramePointer = Constants.kInvalidIndex; WatchSymbolList = new List<SymbolNode>(); FunctionCallDepth = 0; cancellationPending = false; watchClassScope = Constants.kInvalidIndex; ExecutionInstance = CurrentExecutive = new Executive(this); ExecutiveProvider = new ExecutiveProvider(); RuntimeStatus = new ProtoCore.RuntimeStatus(this); StartPC = Constants.kInvalidPC; RuntimeData = new ProtoCore.RuntimeData(); }
public void Append(int lastPtr, Heap rhs) { TotalSize += rhs.TotalSize; rhs.ReallocPointers(lastPtr); Heaplist.InsertRange(lastPtr, rhs.Heaplist); }
public RuntimeMemory(Heap heap) { FramePointer = 0; Stack = new List<StackValue>(); ConstructBlockIds = new List<int>(); Heap = heap; StackRestorer = new StackAlignToFramePointerRestorer(); }
public Heap Clone() { Heap ret = new Heap(); ret.TotalSize = TotalSize; ret.freeList = freeList; foreach (HeapElement he in Heaplist) ret.Heaplist.Add(he.Clone()); return ret; }
public RuntimeMemory(Heap heap) { FramePointer = 0; Executable = null; Stack = new List<StackValue>(); ConstructBlockIds = new List<int>(); Heap = heap; StackRestorer = new StackAlignToFramePointerRestorer(); mapModifiedSymbols = new Dictionary<string, SymbolNode>(); }
public void TestMultiDimensionaldArray() { var heap = new Heap(); var array1 = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(0) }); var array2 = heap.AllocateArray(new StackValue[] { array1 }); var array3 = heap.AllocateArray(new StackValue[] { array2 }); heap.FullGC(new List<StackValue>() {}, testExecutive); Assert.IsNull(heap.ToHeapObject<DSArray>(array1)); Assert.IsNull(heap.ToHeapObject<DSArray>(array2)); Assert.IsNull(heap.ToHeapObject<DSArray>(array3)); }
public void TestBasic() { var heap = new Heap(); var values = new StackValue[] { StackValue.BuildInt(0), StackValue.BuildInt(1), StackValue.BuildInt(2) }; var array = heap.AllocateArray(values); var str = heap.AllocateString("hello world"); heap.GCMarkAndSweep(new List<StackValue>(), testExecutive); Assert.IsNull(heap.ToHeapObject<DSArray>(array)); Assert.IsNull(heap.ToHeapObject<DSArray>(str)); }
public void TestBasic() { var heap = new Heap(); var values = new StackValue[] { StackValue.BuildInt(0), StackValue.BuildInt(1), StackValue.BuildInt(2) }; var array = heap.AllocateArray(values); var str = heap.AllocateString("hello world"); heap.GCMarkAndSweep(new List<StackValue>(), testExecutive); HeapElement arrayHeapElement; Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement)); HeapElement strHeapElement; Assert.IsFalse(heap.TryGetHeapElement(str, out strHeapElement)); }
public DSString(int size, Heap heap) : base(size, heap) { MetaData = new MetaData { type = (int)PrimitiveType.String }; }
public DSObject(StackValue[] values, Heap heap) : base(values, heap) { MetaData = new MetaData { type = (int)PrimitiveType.Pointer }; }
public DSObject(int size, Heap heap) : base(size, heap) { MetaData = new MetaData { type = (int)PrimitiveType.Pointer }; }
/// <summary> /// Create an array and populuate with input values /// </summary> /// <param name="values"></param> /// <param name="heap"></param> public DSArray(StackValue[] values, Heap heap) : base(values, heap) { Dict = new Dictionary<StackValue, StackValue>(); MetaData = new MetaData { type = (int)PrimitiveType.Array }; }
public void TestNonPointers02() { var heap = new Heap(); var values = new StackValue[] { StackValue.BuildInt(0), StackValue.BuildInt(1), StackValue.BuildInt(2) }; var array = heap.AllocateArray(values); var allTypes = new List<StackValue>(); var rawPointer = (int)array.RawIntValue; for (int i = 0; i < (int)AddressType.ArrayKey; ++i) { var val = new StackValue() { optype = (AddressType)i, opdata = rawPointer }; if (!val.IsReferenceType) { allTypes.Add(val); } } // non pointer gc root won't retain memory heap.GCMarkAndSweep(allTypes, testExecutive); HeapElement arrayHeapElement; Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement)); heap.Free(); }
public void TestDictionary() { var heap = new Heap(); var key = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(42) }); var val = heap.AllocateString("Hello world"); var dict = new Dictionary<StackValue, StackValue>(); dict[key] = val; var array = heap.AllocateArray(new StackValue[] { }); heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive); Assert.IsNull(heap.ToHeapObject<DSArray>(val)); Assert.IsNull(heap.ToHeapObject<DSArray>(array)); }
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); }
public void TestCircularReference() { var heap = new Heap(); var svArray1 = heap.AllocateArray(new StackValue[] { StackValue.Null }); var svArray2 = heap.AllocateArray(new StackValue[] { svArray1 }); var array1 = heap.ToHeapObject<DSArray>(svArray1); // self reference array1.SetValueForIndex(0, svArray2, null); heap.GCMarkAndSweep(new List<StackValue>() { }, testExecutive); Assert.IsNull(heap.ToHeapObject<DSArray>(svArray1)); Assert.IsNull(heap.ToHeapObject<DSArray>(svArray2)); }
public DSString(StackValue[] values, Heap heap) : base(values, heap) { MetaData = new MetaData { type = (int)PrimitiveType.String }; }
public void TestMultiDimensionaldArray() { var heap = new Heap(); var array1 = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(0) }); var array2 = heap.AllocateArray(new StackValue[] { array1 }); var array3 = heap.AllocateArray(new StackValue[] { array2 }); heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive); HeapElement array1HeapElement; Assert.IsFalse(heap.TryGetHeapElement(array1, out array1HeapElement)); HeapElement array2HeapElement; Assert.IsFalse(heap.TryGetHeapElement(array2, out array2HeapElement)); HeapElement array3HeapElement; Assert.IsFalse(heap.TryGetHeapElement(array3, out array3HeapElement)); }
public static StackValue BuildString(string str, Heap heap) { var svchars = new List<StackValue>(); foreach (char ch in str) { svchars.Add(ProtoCore.DSASM.StackUtils.BuildChar(ch)); } lock (heap.cslock) { int size = str.Length; int ptr = heap.Allocate(size); for (int i = 0; i < size; ++i) { heap.Heaplist[ptr].Stack[i] = BuildChar(str[i]); } return StackUtils.BuildString(ptr); } }
public void TestCircularReference() { var heap = new Heap(); var array1 = heap.AllocateArray(new StackValue[] { StackValue.Null }); var array2 = heap.AllocateArray(new StackValue[] { array1 }); var array1HeapElement = heap.GetHeapElement(array1); // self reference array1HeapElement.Stack[0] = array2; heap.GCMarkAndSweep(new List<StackValue>() { }, testExecutive); HeapElement array1Hpe; Assert.IsFalse(heap.TryGetHeapElement(array1, out array1Hpe)); HeapElement array2Hpe; Assert.IsFalse(heap.TryGetHeapElement(array2, out array2Hpe)); }
public void TestSelfReference() { var heap = new Heap(); var array = heap.AllocateArray(new StackValue[] { StackValue.Null }); var arrayHeapElement = heap.GetHeapElement(array); // self reference arrayHeapElement.Stack[0] = array; heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive); HeapElement releasedHeapElement; Assert.IsFalse(heap.TryGetHeapElement(array, out releasedHeapElement)); }
public void TestDictionary() { var heap = new Heap(); var key = heap.AllocateArray(new StackValue[] { StackValue.BuildInt(42) }); var val = heap.AllocateString("Hello world"); var dict = new Dictionary<StackValue, StackValue>(); dict[key] = val; var array = heap.AllocateArray(new StackValue[] { }, dict); heap.GCMarkAndSweep(new List<StackValue>() {}, testExecutive); HeapElement valHeapElement; Assert.IsFalse(heap.TryGetHeapElement(val, out valHeapElement)); HeapElement arrayHeapElement; Assert.IsFalse(heap.TryGetHeapElement(array, out arrayHeapElement)); }
public DSArray(int size, Heap heap) : base(size, heap) { Dict = new Dictionary<StackValue, StackValue>(); MetaData = new MetaData { type = (int)PrimitiveType.kTypeArray }; }
public static StackValue BuildString(string str, Heap heap) { return heap.AllocateString(str); }
private void ResetAll(Options options) { Heap = new Heap(); //Rmem = new RuntimeMemory(Heap); Configurations = new Dictionary<string, object>(); DllTypesToLoad = new List<System.Type>(); Options = options; Compilers = new Dictionary<Language, Compiler>(); ClassIndex = Constants.kInvalidIndex; FunctionTable = new FunctionTable(); watchFunctionScope = Constants.kInvalidIndex; watchSymbolList = new List<SymbolNode>(); watchBaseOffset = 0; GlobOffset = 0; GlobHeapOffset = 0; BaseOffset = 0; GraphNodeUID = 0; CodeBlockIndex = 0; RuntimeTableIndex = 0; CodeBlockList = new List<CodeBlock>(); CompleteCodeBlockList = new List<CodeBlock>(); CallsiteGuidMap = new Dictionary<Guid, int>(); AssocNode = null; // TODO Jun/Luke type system refactoring // Initialize the globalClass table and type system ClassTable = new ClassTable(); TypeSystem = new TypeSystem(); TypeSystem.SetClassTable(ClassTable); ProcNode = null; ProcTable = new ProcedureTable(Constants.kGlobalScope); // Initialize internal attributes internalAttributes = new InternalAttributes(ClassTable); //Initialize the function pointer table FunctionPointerTable = new FunctionPointerTable(); //Initialize the dynamic string table and dynamic function table DynamicVariableTable = new DynamicVariableTable(); DynamicFunctionTable = new DynamicFunctionTable(); watchStartPC = Constants.kInvalidIndex; deltaCompileStartPC = Constants.kInvalidIndex; BuildStatus = new BuildStatus(this, Options.BuildOptWarningAsError, null, Options.BuildOptErrorAsWarning); SSAExpressionUID = 0; SSASubscript = 0; SSASubscript_GUID = Guid.NewGuid(); SSAExprUID = 0; ExpressionUID = 0; ModifierBlockUID = 0; ModifierStateSubscript = 0; ExprInterpreterExe = null; Options.RunMode = InterpreterMode.Normal; assocCodegen = null; // Default execution log is Console.Out. ExecutionLog = Console.Out; DebuggerProperties = new DebugProperties(); ParsingMode = ParseMode.Normal; IsParsingPreloadedAssembly = false; IsParsingCodeBlockNode = false; ImportHandler = null; deltaCompileStartPC = 0; builtInsLoaded = false; ForLoopBlockIndex = Constants.kInvalidIndex; GraphNodeCallList = new List<GraphNode>(); InlineConditionalBodyGraphNodes = new Stack<List<GraphNode>>(); newEntryPoint = Constants.kInvalidIndex; }
public void TestSelfReference() { var heap = new Heap(); var svArray = heap.AllocateArray(new StackValue[] { StackValue.Null }); var array = heap.ToHeapObject<DSArray>(svArray); // self reference array.SetValueForIndex(0, svArray, null); heap.FullGC(new List<StackValue>() {}, testExecutive); Assert.IsNull(heap.ToHeapObject<DSArray>(svArray)); }