示例#1
0
 public void Dispose()
 {
     SubParseResult = SubParseResult.DisposeExchange();
     CallSubParserContext.ReleaseReference();
     CallSubParserContext = null;
     _poolCollection.ForkBranchPool.Release(this);
 }
示例#2
0
            public void BuildExecutionGraph()
            {
                if (_executionGraphBuilt)
                {
                    return;
                }

                _executionGraphBuilt = true;

                //InitNode.EnsureReady();
                //EnterNode.SubGraph.Graph.BeginNode.EnsureReady();

                if (Graph.BeginNode.ReturnPath.IsInvalid)
                {
                    return;
                }

                EmptyPath = new ExecutionPath(InitNode, new[]
                {
                    EnterNode,
                    Graph.BeginNode,
                }.Concat(Graph.BeginNode.ReturnPath.Nodes).ToArray(), -1);

                Automata.RegisterExecutionPath(EmptyPath);
            }
示例#3
0
                    public CallSubParserForkBranch <TSubGrammar, TSubToken> Mount(CallSubParserContext <TSubGrammar, TSubToken> callSubParserContext, Automata <Lexeme <TSubToken>, TSubToken> .ForkAutomataResult subParseResult, bool finish)
                    {
                        CallSubParserContext = callSubParserContext.AddReference();
                        SubParseResult       = subParseResult.AddReference();
                        _finish = finish;

                        return(this);
                    }
示例#4
0
            public override InstructionStream Advance(int instructionPointer, Automata <Lexeme <TToken>, TToken> automata)
            {
                var copy = (LexemeStream)Pool.Get().Mount(InstructionReader, automata);

                copy.AdvanceInstructionPosition(this, instructionPointer);

                return(copy);
            }
                public ExecutionPathGroupBuilder(Automata <TInstruction, TOperand> automata, IPool <ExecutionPathGroupBuilder> pool) : base(pool)
                {
                    _automata = automata;

                    for (var i = 0; i < ExecutionPathBuilders.Length; i++)
                    {
                        ExecutionPathBuilders[i] = new ExecutionPathQueueBuilder(this);
                    }
                }
示例#6
0
 protected SubGraph(Automata <TInstruction, TOperand> automata, FiniteState state, Graph invokingGraph) : base(state)
 {
     Automata = automata;
     automata.RegisterSubGraph(this);
     Graph         = automata.EnsureGraph(state);
     InvokingGraph = invokingGraph;
     EnterNode     = new EnterStateNode(automata, invokingGraph, this);
     LeaveNode     = new LeaveStateNode(automata, invokingGraph, this);
     DfaBarrier    = Graph.DfaBarrier;
 }
示例#7
0
            public EntryPointSubGraph(Automata <TInstruction, TOperand> automata, FiniteState state) : base(automata, state, null)
            {
                InitNode = new InitStateNode(automata, this);
                EndNode  = new EndStateNode(automata, this);

                InitNode.OutEdges.Add(new Edge(InitNode, EnterNode));
                LeaveNode.OutEdges.Add(new Edge(LeaveNode, EndNode));
                EndPath = new ExecutionPath(LeaveNode, new Node[] { EndNode }, -1);
                Automata.RegisterExecutionPath(EndPath);

                //EndNode.EnsureReady();
            }
示例#8
0
            private AutomataStack(AutomataStack source) : base(source.Pool)
            {
                _automata = source._automata;
                _automataSubGraphRegistry = _automata._subGraphRegistry;
                _hashCode = source.GetHashCode();

                Count = source._hashCodeDepth;
                Array = new int[Count];

                _hashCodeDirty = false;
                _hashCodeDepth = Count;
                _returnDepth   = source._returnDepth;

                System.Array.Copy(source.Array, source.Count - Count, Array, 0, Count);
            }
示例#9
0
            private Node(Automata <TInstruction, TOperand> automata)
            {
                _automata = automata;

                automata.RegisterNode(this);

                if (this is EnterStateNode || this is LeaveStateNode)
                {
                    Flags |= EnterReturn;
                }

                if (this is LazyNode)
                {
                    Flags |= Lazy;
                }
            }
示例#10
0
文件: Automata.cs 项目: Egaros/lib
            public ExecutionPathMethodCollection(IILBuilder ilBuilder, Automata <TInstruction, TOperand> automata)
            {
                _ilBuilder = ilBuilder;
                _automata  = automata;

                var length = 128;

                while (length < automata._executionPathRegistry.Count)
                {
                    length *= 2;
                }

                _executionPaths = new ExecutionPathMethod[length];

                for (var i = 0; i < length; i++)
                {
                    _executionPaths[i] = new ExecutionPathMethod(_ilBuilder, automata, i);
                }
            }
示例#11
0
            public ExecutionPathMethod(IILBuilder builder, Automata <TInstruction, TOperand> automata, int index)
            {
                _mainDelegate = (process, threadStack, closure) =>
                {
                    var executionPath = automata._executionPathRegistry[index];

                    _mainDelegate = builder.BuildMain(executionPath, out _mainClosure);

                    return(_mainDelegate(process, threadStack, _mainClosure));
                };

                _parallelDelegate = (process, threadStack, closure) =>
                {
                    var executionPath = automata._executionPathRegistry[index];

                    _parallelDelegate = builder.BuildParallel(executionPath, out _parallelClosure);

                    return(_parallelDelegate(process, threadStack, _parallelClosure));
                };
            }
示例#12
0
            protected DfaBuilder(IEnumerable <FiniteState> states, Automata <TInstruction, TOperand> automata)
            {
                _initialStateNodes     = new List <DfaNode>();
                _noOpInitialStateNodes = new List <DfaNode>();

                foreach (var subGraph in states.Select(automata.EnsureSubGraph))
                {
                    if (subGraph.Graph.CanSimulateDfa == false)
                    {
                        throw new InvalidOperationException($"FiniteState {subGraph.State} can not be simulated as DFA");
                    }

                    if (subGraph.Graph.HasOperandNodes == false)
                    {
                        _noOpInitialStateNodes.Add(CreateDfaNode(subGraph.Graph.BeginNode, new DfaTransition(subGraph, _transitionCount), null));
                    }
                    else
                    {
                        _initialStateNodes.Add(CreateDfaNode(subGraph.Graph.BeginNode, new DfaTransition(subGraph, _transitionCount), null));
                    }

                    _transitionCount++;
                }

                FastLookup = _initialStateNodes.Count < 100;

                var builderKey = GetBuilderKey();

                InitialState     = builderKey.Build(_initialStateNodes);
                NoOpInitialState = builderKey.Build(_noOpInitialStateNodes);

                ReleaseBuilderKey(builderKey);

                if (FastLookup)
                {
                    BuildFastLookup(InitialState);
                }
            }
示例#13
0
 public EndProductionNode(Automata <TInstruction, TOperand> automata, Graph graph, Production production) : base(automata, graph, production)
 {
 }
示例#14
0
 protected ProductionNode(Automata <TInstruction, TOperand> automata, Graph graph, Production production) : base(automata, graph)
 {
     Production = production;
 }
示例#15
0
 public ReturnStateNode(Automata <TInstruction, TOperand> automata, Graph graph) : base(automata, graph)
 {
 }
示例#16
0
 public PredicateNode(Automata <TInstruction, TOperand> automata, IPool <PredicateNode> pool) : base(automata, null)
 {
     _pool = pool;
 }
示例#17
0
 public ActionNode(Automata <TInstruction, TOperand> automata, Graph graph, ActionEntry actionEntry) : base(automata, graph)
 {
     ActionEntry = actionEntry;
 }
示例#18
0
 public LazyNode(Automata <TInstruction, TOperand> automata, Graph graph) : base(automata, graph)
 {
 }
示例#19
0
 public PredicateNode(Automata <TInstruction, TOperand> automata, Graph graph, PredicateEntryBase predicateEntry) : base(automata, graph)
 {
     PredicateEntry = predicateEntry;
 }
示例#20
0
 public EndStateNode(Automata <TInstruction, TOperand> automata, SubGraph subGraph) : base(automata, subGraph)
 {
 }
示例#21
0
 public virtual InstructionStream Advance(int instructionPointer, Automata <TInstruction, TOperand> automata)
 {
     throw new NotImplementedException();
 }
示例#22
0
 public EnterStateNode(Automata <TInstruction, TOperand> automata, Graph graph, SubGraph subGraph) : base(automata, graph, subGraph)
 {
 }
示例#23
0
 protected SubGraphNode(Automata <TInstruction, TOperand> automata, Graph graph, SubGraph subGraph) : base(automata, graph)
 {
     SubGraph = subGraph;
 }
示例#24
0
 public OperandNode(Automata <TInstruction, TOperand> automata, Graph graph, MatchEntry matchEntry) : base(automata, graph)
 {
     MatchEntry = matchEntry;
 }
示例#25
0
 public ForkNode(Automata <TInstruction, TOperand> automata, IPool <ForkNode> pool) : base(automata, null)
 {
     _pool = pool;
 }
示例#26
0
 public SubGraph(Automata <TInstruction, TOperand> automata, StateEntry stateEntry, Graph invokingGraph) : this(automata, stateEntry.State, invokingGraph)
 {
     StateEntry = stateEntry;
 }
示例#27
0
 protected EntryPointSubGraphNode(Automata <TInstruction, TOperand> automata, SubGraph subGraph) : base(automata, null, subGraph)
 {
 }
示例#28
0
 protected StateEntryNode(Automata <TInstruction, TOperand> automata, Graph graph, StateEntry stateEntry) : base(automata, graph)
 {
     StateEntry = stateEntry;
 }
示例#29
0
 public LeaveStateNode(Automata <TInstruction, TOperand> automata, Graph graph, SubGraph subGraph) : base(automata, graph, subGraph)
 {
     //LeavePath = new ExecutionPath(this, new Node[] {this});
 }
示例#30
0
 public InlineLeaveStateNode(Automata <TInstruction, TOperand> automata, Graph graph, StateEntry stateEntry) : base(automata, graph, stateEntry)
 {
 }