Skip to content

Commit

Permalink
Reimplement dynamic memory allocation (#3)
Browse files Browse the repository at this point in the history
This is to make the dynamic memory allocation system work with serializable
VMs.
  • Loading branch information
jamespfennell committed Jun 12, 2023
1 parent 0a16635 commit 49fd0e9
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 238 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"muglue",
"nevec",
"newcommand",
"newint",
"newintarray",
"noexpand",
"PDFTEX",
"randtex",
Expand Down
1 change: 0 additions & 1 deletion crates/texlang-core/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ impl PrimitiveKey {
variable::IndexResolver::Dynamic(f) => Some(
PrimitiveKey::VariableArrayDynamic(variable_key, *f as usize),
),
variable::IndexResolver::DynamicVirtual(_) => None,
},
}
}
Expand Down
15 changes: 0 additions & 15 deletions crates/texlang-core/src/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,20 +326,6 @@ pub enum IndexResolver<S> {
/// For example, in `\count 4` the index of `4` is determined by parsing a number
/// from the input token stream.
Dynamic(fn(token::Token, &mut vm::ExpandedStream<S>) -> Result<Index, Box<error::Error>>),
/// A dynamic index, but determined using virtual method dispatch.
///
/// This method is more flexible than the Dynamic variant, but less performant.
DynamicVirtual(Box<dyn DynamicIndexResolver<S>>),
}

/// Trait used for dynamically determining an index using virtual method dispatch.
pub trait DynamicIndexResolver<S> {
/// Determine the index of a variable.
fn resolve(
&self,
token: token::Token,
input: &mut vm::ExpandedStream<S>,
) -> Result<Index, Box<error::Error>>;
}

impl<S> IndexResolver<S> {
Expand All @@ -352,7 +338,6 @@ impl<S> IndexResolver<S> {
match self {
IndexResolver::Static(addr) => Ok(*addr),
IndexResolver::Dynamic(f) => f(token, input),
IndexResolver::DynamicVirtual(v) => v.resolve(token, input),
}
}
}
Expand Down
Loading

0 comments on commit 49fd0e9

Please sign in to comment.