Store single native input tokens inline
This commit is contained in:
1 parent
9c93ff9750
commit
fb5cb5ada9
6 files changed
+64
-16
No files matched your search
@@ -76,6 +76,23 @@ impl From<Token> for InputToken {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone)]
|
||||
enum InputTokens {
|
||||
One(InputToken),
|
||||
Many(Vec<InputToken>),
|
||||
}
|
||||
|
||||
impl std::ops::Deref for InputTokens {
|
||||
type Target = [InputToken];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
Self::One(token) => std::slice::from_ref(token),
|
||||
Self::Many(tokens) => tokens,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A meaning is valid until the returned token is used or put back. Tokens
|
||||
// that bypass normal expansion may still need to be looked up by the caller.
|
||||
type ExpandedToken = (InputToken, Option<Meaning>);
|
||||
@@ -91,7 +108,7 @@ enum InputFrame {
|
||||
conditional_boundary: usize,
|
||||
},
|
||||
Tokens {
|
||||
tokens: Vec<InputToken>,
|
||||
tokens: InputTokens,
|
||||
cursor: usize,
|
||||
kind: TokenInputKind,
|
||||
},
|
||||
@@ -580,6 +597,12 @@ impl Executor {
|
||||
self.push_kind(tokens, TokenInputKind::Inserted)
|
||||
}
|
||||
fn push_kind(&mut self, tokens: Vec<InputToken>, kind: TokenInputKind) -> Result<(), Error> {
|
||||
self.push_input_tokens(InputTokens::Many(tokens), kind)
|
||||
}
|
||||
fn push_token(&mut self, token: InputToken) -> Result<(), Error> {
|
||||
self.push_input_tokens(InputTokens::One(token), TokenInputKind::Inserted)
|
||||
}
|
||||
fn push_input_tokens(&mut self, tokens: InputTokens, kind: TokenInputKind) -> Result<(), Error> {
|
||||
if tokens.len() > self.limits.tokens {
|
||||
return self.fail("native token limit exceeded");
|
||||
}
|
||||
@@ -587,7 +610,7 @@ impl Executor {
|
||||
return self.fail("native input stack limit exceeded");
|
||||
}
|
||||
if matches!(kind, TokenInputKind::BackedUp) && !self.alignments.is_empty() {
|
||||
for token in &tokens {
|
||||
for token in tokens.iter() {
|
||||
self.alignment_balance -= Self::alignment_brace_token(&token.token);
|
||||
}
|
||||
}
|
||||
@@ -603,7 +626,7 @@ impl Executor {
|
||||
fn unread(&mut self, mut token: InputToken) -> Result<(), Error> {
|
||||
token.xe_backed_char = false;
|
||||
self.discard_exhausted_tokens();
|
||||
self.push_kind(vec![token], TokenInputKind::BackedUp)
|
||||
self.push_input_tokens(InputTokens::One(token), TokenInputKind::BackedUp)
|
||||
}
|
||||
fn push_source(&mut self, file: SourceFile) -> Result<(), Error> {
|
||||
if self.inputs.len() >= self.limits.input_depth {
|
||||
@@ -831,12 +854,12 @@ impl Executor {
|
||||
} else {
|
||||
TokenKind::Character(c, cat)
|
||||
};
|
||||
self.push(vec![Token {
|
||||
self.push_token(Token {
|
||||
kind,
|
||||
span: token.span,
|
||||
invocation: token.invocation,
|
||||
}
|
||||
.into()])
|
||||
.into())
|
||||
}
|
||||
|
||||
fn roman_numeral(&self, mut number: usize) -> Result<String, Error> {
|
||||
@@ -1853,9 +1876,7 @@ impl Executor {
|
||||
tokens.into_iter().map(InputToken::from).collect(),
|
||||
TokenInputKind::Write,
|
||||
)?;
|
||||
self.push(vec![
|
||||
Token::new(TokenKind::Character('{', CatCode::BeginGroup), span).into(),
|
||||
])?;
|
||||
self.push_token(Token::new(TokenKind::Character('{', CatCode::BeginGroup), span).into())?;
|
||||
let previous_writing = std::mem::replace(&mut self.writing, true);
|
||||
let expanded = self.scan_expanded_group(files);
|
||||
self.writing = previous_writing;
|
||||
@@ -3981,7 +4002,7 @@ impl Executor {
|
||||
}
|
||||
fn insert_paragraph_token(&mut self, span: Span) -> Result<(), Error> {
|
||||
self.reads.insert(Dependency::ParagraphToken);
|
||||
self.push(vec![Token::new(self.state.paragraph_token(), span).into()])
|
||||
self.push_token(Token::new(self.state.paragraph_token(), span).into())
|
||||
}
|
||||
|
||||
fn in_unrestricted_horizontal_mode(&self) -> bool {
|
||||
|
||||
Reference in new issue
Block a user