public Boolean RunTest() { try { GlobalMemory.Clear(); var sStream = new ANTLRStringStream(input); var lexer = new SGLLexer(sStream); var tStream = new CommonTokenStream(lexer); // Parsing var parser = new SGLParser(tStream); var t = (CommonTree)parser.main().Tree; // Printing tree Console.WriteLine("; " + t.ToStringTree()); // TreeWalking var treeStream = new CommonTreeNodeStream(t); var tw = new SGLTreeWalker(treeStream, true); AbstractNode returned = tw.main(); returned.Evaluate(); if (debug) { realOutput = GlobalMemory.Instance.DebugString; } else { realOutput = GlobalMemory.Instance.StoryboardCode.ToString(); } // comparison realOutput = realOutput.Trim(); output.Trim(); if (output.Equals(realOutput)) { return(true); } else { return(false); } } catch (CompilerException ce) { Console.WriteLine(ce.GetExceptionAsString()); return(false); } catch (Exception ex) { Console.WriteLine("Es ist ein Fehler aufgetreten."); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); return(false); } }
public AstNode Activate(AstNode pointer) { if (OpCode == Operation.Program) { GlobalMemory.Clear(); return(pointer.NextNode); } return(_Operate(pointer)); }
public Boolean Run() { // run lexer on input var lexer = new SGLLexer(new ANTLRStringStream(Input)); var tokenStream = new CommonTokenStream(lexer); // run parser on tokens var parser = new SGLParser(tokenStream); var ast = (CommonTree)parser.main().Tree; // maybe test the tree if (testTree) { if (!ast.ToStringTree().Trim().Equals(ExpectedTree.Trim())) { result += "Test " + name + "failed! Tree comparison failed!"; result += "Expected tree: " + ExpectedTree.Trim(); result += "Given tree: " + ast.ToStringTree().Trim(); return(false); } } var astStream = new CommonTreeNodeStream(ast); // run walker on AST GlobalMemory.Clear(); var treewalker = new SGLTreeWalker(astStream, true); treewalker.main().Evaluate(); //String output = treewalker.GetStoryboardCode().ToString(); if (testOutput) { String output = GlobalMemory.Instance.StoryboardCode.ToString(); if (!output.Trim().Equals(ExpectedOutput.Trim())) { result += "Test " + name + "failed! Output comparison failed!"; result += "Expected output: \r\n" + ExpectedOutput.Trim(); result += "Given output: \r\n" + output.Trim(); return(false); } } if (testDebug) { String debug = GlobalMemory.Instance.StoryboardCode.ToString(); if (!debug.Trim().Equals(ExpectedDebug.Trim())) { result += "Test " + name + "failed! Debug comparison failed!"; result += "Expected debug: \r\n" + ExpectedDebug.Trim(); result += "Given debug: \r\n" + debug.Trim(); return(false); } } return(true); }
private void Clear() { GlobalMemory.Clear(); /* * // get the library * Global library = Global.GetInstance(); * * // empty library * library.Empty(); * * // register methods * library.RegisterMethod();*/ }
/// <summary> /// Does the given globalvar exist with the given name? /// </summary> /// <param name="varName">The name of the globalvar to check for.</param> /// <returns>If a globalvar exists with the given name.</returns> public bool HasGlobal(string varName) { return(GlobalMemory.HasGlobal(varName)); }
/// <summary> /// Execute a Script. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The Script name.</param> /// <param name="args">The arguments.</param> /// <returns>The resulting return.</returns> public object ExecuteScript(RAM r, object scriptName, object[] args) { return(GlobalMemory.ExecuteScript(r, scriptName, args)); }
/// <summary> /// Default Constructor. /// </summary> /// <param name="globalMemory">The GlobalMemory of this Brack application.</param> /// <param name="operationSet">The OperationSet of this Brack application.</param> public RAM(GlobalMemory globalMemory, OperationSet operationSet) { GlobalMemory = globalMemory; OperationSet = operationSet; LocalMemoryStack = new Stack <LocalMemory>(); }
/// <summary> /// Instantiate a new globalvar dictionary. /// </summary> public void ResetGlobals() { GlobalMemory.ResetGlobals(); }
/// <summary> /// Get the names of the arguments of the given Script from this GlobalMemory. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script (nested operators are executed).</param> /// <returns>The argument names</returns> public string[] GetScriptArguments(RAM r, object scriptName) { return(GlobalMemory.GetScriptArguments(r, scriptName)); }
/// <summary> /// Delete the globalvar with the given name from memory (with garbage collection). /// </summary> /// <param name="varName">The name of the globalvar to delete.</param> public void DeleteGlobal(string varName) { GlobalMemory.DeleteGlobal(varName); }
protected override void CreateDeviceDependentResources() { _dxgiFactory = CreateDxgiFactory(); _dxgiAdapter = GetDxgiAdapter(); _d3dDevice = CreateD3DDevice(); StartInfoPump(); _commandQueue = CreateCommandQueue(); CreateDescriptorHeaps(); for (int i = 0; i < FrameCount; i++) { _commandAllocators[i] = CreateCommandAllocator(); } _fence = CreateFence(); _fenceValues = CreateFenceValues(); _fenceEvent = CreateFenceEvent(); _rootSignature = CreateRootSignature(); _pipelineState = CreatePipelineState(); _graphicsCommandLists = CreateGraphicsCommandLists(); SilkMarshal.ThrowHResult(CommandAllocator->Reset()); SilkMarshal.ThrowHResult(GraphicsCommandList->Reset(CommandAllocator, PipelineState)); CreateAssets(); ID3D12CommandAllocator *CreateCommandAllocator() { ID3D12CommandAllocator *commandAllocator; var iid = ID3D12CommandAllocator.Guid; SilkMarshal.ThrowHResult ( D3DDevice->CreateCommandAllocator (CommandListType.CommandListTypeDirect, &iid, (void **)&commandAllocator) ); return(commandAllocator); } ID3D12CommandQueue *CreateCommandQueue() { var queueDesc = new CommandQueueDesc(); ID3D12CommandQueue *commandQueue; var iid = ID3D12CommandQueue.Guid; SilkMarshal.ThrowHResult(D3DDevice->CreateCommandQueue(&queueDesc, &iid, (void **)&commandQueue)); return(commandQueue); } ID3D12Device *CreateD3DDevice() { ID3D12Device *d3dDevice; var iid = ID3D12Device.Guid; SilkMarshal.ThrowHResult ( D3D12.CreateDevice ((IUnknown *)_dxgiAdapter, D3DFeatureLevel.D3DFeatureLevel110, &iid, (void **)&d3dDevice) ); return(d3dDevice); } IDXGIFactory4 *CreateDxgiFactory() { var dxgiFactoryFlags = TryEnableDebugLayer() ? 0x01 : 0u; IDXGIFactory4 *dxgiFactory; var iid = IDXGIFactory4.Guid; SilkMarshal.ThrowHResult(Dxgi.CreateDXGIFactory2(dxgiFactoryFlags, &iid, (void **)&dxgiFactory)); return(dxgiFactory); } ID3D12Fence *CreateFence() { ID3D12Fence *fence; var iid = ID3D12Fence.Guid; SilkMarshal.ThrowHResult (D3DDevice->CreateFence(InitialValue: 0, FenceFlags.FenceFlagNone, &iid, (void **)&fence)); return(fence); } IntPtr CreateFenceEvent() { var fenceEvent = SilkMarshal.CreateWindowsEvent(null, false, false, null); if (fenceEvent == IntPtr.Zero) { var hr = Marshal.GetHRForLastWin32Error(); Marshal.ThrowExceptionForHR(hr); } return(fenceEvent); } ulong[] CreateFenceValues() { var fenceValues = new ulong[FrameCount]; fenceValues[0] = 1; return(fenceValues); } ID3D12GraphicsCommandList *[] CreateGraphicsCommandLists() { var graphicsCommandLists = new ID3D12GraphicsCommandList *[FrameCount]; for (uint i = 0u; i < FrameCount; i++) { ID3D12GraphicsCommandList *graphicsCommandList; var iid = ID3D12GraphicsCommandList.Guid; SilkMarshal.ThrowHResult ( D3DDevice->CreateCommandList ( nodeMask: 0, CommandListType.CommandListTypeDirect, _commandAllocators[i], PipelineState, &iid, (void **)&graphicsCommandList ) ); SilkMarshal.ThrowHResult(graphicsCommandList->Close()); graphicsCommandLists[i] = graphicsCommandList; } return(graphicsCommandLists); } IDXGIAdapter1 *GetDxgiAdapter() { if (UseWarpDevice) { IDXGIAdapter1 *adapter; var iid = IDXGIAdapter.Guid; SilkMarshal.ThrowHResult(_dxgiFactory->EnumWarpAdapter(&iid, (void **)&adapter)); return(adapter); } else { return(GetHardwareAdapter((IDXGIFactory1 *)_dxgiFactory)); } } bool TryEnableDebugLayer() { #if DEBUG // Enable the debug layer (requires the Graphics Tools "optional feature"). // NOTE: Enabling the debug layer after device creation will invalidate the active device. using ComPtr <ID3D12Debug> debugController = null; var iid = ID3D12Debug.Guid; var hr = D3D12.GetDebugInterface(&iid, (void **)&debugController); if (HResult.IndicatesSuccess(hr)) { debugController.Get().EnableDebugLayer(); Log.LogInformation("Debug layer enabled"); return(_debug = true); } else { Log.LogWarning ( Marshal.GetExceptionForHR(hr), $"Failed to enable debug layer, failed with result {hr} (0x{hr:x8})" ); } #endif return(false); } void StartInfoPump() { #if DEBUG if (!_debug) { Log.LogInformation("Skipped creation of info pump due to the debug layer not being enabled."); return; } var iid = ID3D12InfoQueue.Guid; fixed(ID3D12InfoQueue ** @out = &_infoQueue) { SilkMarshal.ThrowHResult(D3DDevice->QueryInterface(&iid, (void **)@out)); } _infoPumpCancellationToken = new(); _infoPump = Task.Run ( () => { Log.LogInformation("Info queue pump started"); while (!_infoPumpCancellationToken.Token.IsCancellationRequested) { var numMessages = _infoQueue->GetNumStoredMessages(); if (numMessages == 0) { continue; } for (var i = 0ul; i < numMessages; i++) { nuint msgByteLength; SilkMarshal.ThrowHResult(_infoQueue->GetMessageA(i, null, &msgByteLength)); using var memory = GlobalMemory.Allocate((int)msgByteLength); SilkMarshal.ThrowHResult ( _infoQueue->GetMessageA(i, memory.AsPtr <Message>(), &msgByteLength) ); ref var msg = ref memory.AsRef <Message>(); var descBytes = new Span <byte>(msg.PDescription, (int)msg.DescriptionByteLength); var desc = Encoding.UTF8.GetString(descBytes[..^ 1]); var eid = new EventId((int)msg.ID, msg.ID.ToString()["MessageID".Length..]);
/// <summary> /// Get the Script with the given name. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to get from (nested brack operations execute).</param> /// <returns>The Script found with the given name.</returns> public Script GetScript(RAM r, object scriptName) { return(GlobalMemory.GetScript(r, scriptName)); }
/// <summary> /// Delete the Script with the given name from memory (with garbage collection). /// </summary> /// <param name="scriptName">The name of the Script to delete.</param> public void DeleteScript(string scriptName) { GlobalMemory.DeleteScript(scriptName); }
/// <summary> /// Set the Script with the given name to have the given value, and declare a Script with the given name if none exist already. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to check for (nested brack operations execute).</param> /// <param name="script">The Script to add.</param> /// <returns>If a Script exists with the given name.</returns> public void SetScript(RAM r, object scriptName, Script script) { GlobalMemory.SetScript(r, scriptName, script); }
/// <summary> /// Get the Script with the given name. /// </summary> /// <param name="scriptName">The name of the Script.</param> /// <returns>The Script found with the given name.</returns> public Script GetScript(string scriptName) { return(GlobalMemory.GetScript(scriptName)); }
/// <summary> /// Set the Script with the given name to have the given value, and declare a Script with the given name if none exist already. /// </summary> /// <param name="scriptName">The name of the Script to alter or declare.</param> /// <param name="script">The Script to add.</param> public void SetScript(string scriptName, Script script) { GlobalMemory.SetScript(scriptName, script); }
/// <summary> /// Does a Script exist with the given name? /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to check for (nested brack operations execute).</param> /// <returns>If a Script exists with the given name.</returns> public bool HasScript(RAM r, object scriptName) { return(GlobalMemory.HasScript(r, scriptName)); }
/// <summary> /// Does a Script exist with the given name? /// </summary> /// <param name="scriptName">The name of the Script to check for.</param> /// <returns>If a Script exists with the given name.</returns> public bool HasScript(string scriptName) { return(GlobalMemory.HasScript(scriptName)); }
/// <summary> /// Does the given globalvar exist with the given name? /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the globalvar to check for (nested brack operations execute).</param> /// <returns>If a globalvar exists with the given name.</returns> public bool HasGlobal(RAM r, object varName) { return(GlobalMemory.HasGlobal(r, varName)); }
public static void Clear() { GlobalMemory.Clear(); }
/// <summary> /// Set the globalvar with the given name to have the given value, and declare a globalvar with the given name if none exist already. /// </summary> /// <param name="varName">The name of the globalvar to alter or declare.</param> /// <param name="value">The value to store in the globalvar.</param> public void SetGlobal(string varName, object value) { GlobalMemory.SetGlobal(varName, value); }
/// <summary> /// Get the value of the globalvar with the given name. /// </summary> /// <param name="varName">The name of the globalvar.</param> /// <returns>The value found in the globalvar.</returns> public object GetGlobal(string varName) { return(GlobalMemory.GetGlobal(varName)); }
/// <summary> /// Get the value of the globalvar with the given name. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the globavar to get from (nested brack operations execute).</param> /// <returns>The value found in the globalvar with the given name.</returns> public object GetGlobal(RAM r, object varName) { return(GlobalMemory.GetGlobal(r, varName)); }
/// <summary> /// Get the names of the arguments of the Script of the given name. /// </summary> /// <param name="scriptName">The name of the Script .</param> /// <returns>The argument names.</returns> public string[] GetScriptArguments(string scriptName) { return(GlobalMemory.GetScriptArguments(scriptName)); }
/// <summary> /// Delete the Script with the given name from memory (with garbage collection). /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="scriptName">The name of the Script to delete (nested brack operations execute).</param> public void DeleteScript(RAM r, object scriptName) { GlobalMemory.DeleteScript(r, scriptName); }
/// <summary> /// Delete the globavar with the given name from memory (with garbage collection). /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the globavar to delete (nested brack operations execute).</param> public void DeleteGlobal(RAM r, object varName) { GlobalMemory.DeleteGlobal(r, varName); }
/// <summary> /// Instantiate a new Script Dictionary. /// </summary> public void ResetScripts() { GlobalMemory.ResetScripts(); }
/// <summary> /// Set the globalvar with the given name to have the given value, and declare a globalvar with the given name if none exist already. /// </summary> /// <param name="r">The RAM used for this execution.</param> /// <param name="varName">The name of the globalvar to check for (nested brack operations execute).</param> /// <param name="value">The value to store in the globalvar.</param> /// <returns>If a globalvar exists with the given name.</returns> public void SetGlobal(RAM r, object varName, object value) { GlobalMemory.SetGlobal(r, varName, value); }