private void AdvanceInstructionPosition(LexemeStream lexemeStream, int instructionPointer) { StartPosition = SeekableInstructionReader.Position; StartInstructionPointer = instructionPointer; var lexemeIndex = instructionPointer & LocalIndexMask; var lexemePageIndex = instructionPointer >> PageIndexShift; EnsurePagesCapacity(lexemePageIndex + 1); for (var iPage = lexemeStream.HeadPage; iPage <= lexemePageIndex; iPage++) { InstructionReader.RentBuffers(PageSize, out var instructionsBuffer, out var operandsBuffer); var pageSource = lexemeStream.Pages[iPage]; var pageCopy = new InstructionPage(instructionsBuffer, operandsBuffer, pageSource.PageIndex, pageSource.PageLength); Array.Copy(pageSource.InstructionsBuffer, 0, pageCopy.InstructionsBuffer, 0, pageCopy.PageLength); Array.Copy(pageSource.OperandsBuffer, 0, pageCopy.OperandsBuffer, 0, pageCopy.PageLength); pageCopy.ReferenceCount = pageSource.ReferenceCount; Pages[pageCopy.PageIndex] = pageCopy; } var lexemePage = Pages[lexemePageIndex]; lexemePage.PageLength = lexemeIndex; for (var i = lexemeIndex; i < PageSize; i++) { lexemePage.OperandsBuffer[i] = int.MinValue; lexemePage.InstructionsBuffer[i] = default; } HeadPage = lexemeStream.HeadPage; PageCount = lexemePageIndex + 1; ReadOperand(ref instructionPointer); }
public Parser(List<Lexer.Lexeme> input) { Stream = new LexemeStream(input.ToArray()); }