summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/src/layout/enum.rs4
-rw-r--r--library/src/layout/list.rs9
-rw-r--r--library/src/layout/mod.rs9
-rw-r--r--library/src/layout/page.rs7
-rw-r--r--library/src/layout/par.rs5
-rw-r--r--library/src/layout/table.rs11
-rw-r--r--library/src/meta/counter.rs40
-rw-r--r--library/src/meta/numbering.rs20
-rw-r--r--library/src/meta/outline.rs6
-rw-r--r--library/src/meta/query.rs7
-rw-r--r--library/src/meta/reference.rs5
-rw-r--r--library/src/meta/state.rs22
12 files changed, 84 insertions, 61 deletions
diff --git a/library/src/layout/enum.rs b/library/src/layout/enum.rs
index 1c08cd5f..05b42bd8 100644
--- a/library/src/layout/enum.rs
+++ b/library/src/layout/enum.rs
@@ -180,7 +180,7 @@ impl Layout for EnumNode {
let resolved = if full {
parents.push(number);
- let content = numbering.apply(vt.world, &parents)?.display();
+ let content = numbering.apply_vt(vt, &parents)?.display();
parents.pop();
content
} else {
@@ -188,7 +188,7 @@ impl Layout for EnumNode {
Numbering::Pattern(pattern) => {
TextNode::packed(pattern.apply_kth(parents.len(), number))
}
- other => other.apply(vt.world, &[number])?.display(),
+ other => other.apply_vt(vt, &[number])?.display(),
}
};
diff --git a/library/src/layout/list.rs b/library/src/layout/list.rs
index c954ab67..fe78131d 100644
--- a/library/src/layout/list.rs
+++ b/library/src/layout/list.rs
@@ -128,7 +128,7 @@ impl Layout for ListNode {
};
let depth = self.depth(styles);
- let marker = self.marker(styles).resolve(vt.world, depth)?;
+ let marker = self.marker(styles).resolve(vt, depth)?;
let mut cells = vec![];
for item in self.children() {
@@ -181,17 +181,14 @@ pub enum ListMarker {
impl ListMarker {
/// Resolve the marker for the given depth.
- fn resolve(&self, world: Tracked<dyn World>, depth: usize) -> SourceResult<Content> {
+ fn resolve(&self, vt: &mut Vt, depth: usize) -> SourceResult<Content> {
Ok(match self {
Self::Content(list) => list
.get(depth)
.or(list.last())
.cloned()
.unwrap_or_else(|| TextNode::packed('•')),
- Self::Func(func) => {
- let args = Args::new(func.span(), [Value::Int(depth as i64)]);
- func.call_detached(world, args)?.display()
- }
+ Self::Func(func) => func.call_vt(vt, [Value::Int(depth as i64)])?.display(),
})
}
}
diff --git a/library/src/layout/mod.rs b/library/src/layout/mod.rs
index fc0279eb..b29da700 100644
--- a/library/src/layout/mod.rs
+++ b/library/src/layout/mod.rs
@@ -47,6 +47,7 @@ use std::mem;
use typed_arena::Arena;
use typst::diag::SourceResult;
+use typst::eval::Tracer;
use typst::model::{applicable, realize, SequenceNode, StyleVecBuilder, StyledNode};
use crate::math::{FormulaNode, LayoutMath};
@@ -68,11 +69,12 @@ impl LayoutRoot for Content {
fn cached(
node: &Content,
world: Tracked<dyn World>,
+ tracer: TrackedMut<Tracer>,
provider: TrackedMut<StabilityProvider>,
introspector: Tracked<Introspector>,
styles: StyleChain,
) -> SourceResult<Document> {
- let mut vt = Vt { world, provider, introspector };
+ let mut vt = Vt { world, tracer, provider, introspector };
let scratch = Scratch::default();
let (realized, styles) = realize_root(&mut vt, &scratch, node, styles)?;
realized
@@ -84,6 +86,7 @@ impl LayoutRoot for Content {
cached(
self,
vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
TrackedMut::reborrow_mut(&mut vt.provider),
vt.introspector,
styles,
@@ -129,12 +132,13 @@ impl Layout for Content {
fn cached(
node: &Content,
world: Tracked<dyn World>,
+ tracer: TrackedMut<Tracer>,
provider: TrackedMut<StabilityProvider>,
introspector: Tracked<Introspector>,
styles: StyleChain,
regions: Regions,
) -> SourceResult<Fragment> {
- let mut vt = Vt { world, provider, introspector };
+ let mut vt = Vt { world, tracer, provider, introspector };
let scratch = Scratch::default();
let (realized, styles) = realize_block(&mut vt, &scratch, node, styles)?;
realized
@@ -146,6 +150,7 @@ impl Layout for Content {
cached(
self,
vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
TrackedMut::reborrow_mut(&mut vt.provider),
vt.introspector,
styles,
diff --git a/library/src/layout/page.rs b/library/src/layout/page.rs
index 962e8a16..eeb74a55 100644
--- a/library/src/layout/page.rs
+++ b/library/src/layout/page.rs
@@ -403,13 +403,10 @@ pub enum Marginal {
impl Marginal {
/// Resolve the marginal based on the page number.
- pub fn resolve(&self, vt: &Vt, page: usize) -> SourceResult<Content> {
+ pub fn resolve(&self, vt: &mut Vt, page: usize) -> SourceResult<Content> {
Ok(match self {
Self::Content(content) => content.clone(),
- Self::Func(func) => {
- let args = Args::new(func.span(), [Value::Int(page as i64)]);
- func.call_detached(vt.world, args)?.display()
- }
+ Self::Func(func) => func.call_vt(vt, [Value::Int(page as i64)])?.display(),
})
}
}
diff --git a/library/src/layout/par.rs b/library/src/layout/par.rs
index 1906dd7c..8657d7fb 100644
--- a/library/src/layout/par.rs
+++ b/library/src/layout/par.rs
@@ -1,3 +1,4 @@
+use typst::eval::Tracer;
use unicode_bidi::{BidiInfo, Level as BidiLevel};
use unicode_script::{Script, UnicodeScript};
use xi_unicode::LineBreakIterator;
@@ -138,6 +139,7 @@ impl ParNode {
fn cached(
par: &ParNode,
world: Tracked<dyn World>,
+ tracer: TrackedMut<Tracer>,
provider: TrackedMut<StabilityProvider>,
introspector: Tracked<Introspector>,
styles: StyleChain,
@@ -145,7 +147,7 @@ impl ParNode {
region: Size,
expand: bool,
) -> SourceResult<Fragment> {
- let mut vt = Vt { world, provider, introspector };
+ let mut vt = Vt { world, tracer, provider, introspector };
let children = par.children();
// Collect all text into one string for BiDi analysis.
@@ -166,6 +168,7 @@ impl ParNode {
cached(
self,
vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
TrackedMut::reborrow_mut(&mut vt.provider),
vt.introspector,
styles,
diff --git a/library/src/layout/table.rs b/library/src/layout/table.rs
index 024bb0d6..d4b6e7d7 100644
--- a/library/src/layout/table.rs
+++ b/library/src/layout/table.rs
@@ -227,14 +227,13 @@ pub enum Celled<T> {
impl<T: Cast + Clone> Celled<T> {
/// Resolve the value based on the cell position.
- pub fn resolve(&self, vt: &Vt, x: usize, y: usize) -> SourceResult<T> {
+ pub fn resolve(&self, vt: &mut Vt, x: usize, y: usize) -> SourceResult<T> {
Ok(match self {
Self::Value(value) => value.clone(),
- Self::Func(func) => {
- let args =
- Args::new(func.span(), [Value::Int(x as i64), Value::Int(y as i64)]);
- func.call_detached(vt.world, args)?.cast().at(func.span())?
- }
+ Self::Func(func) => func
+ .call_vt(vt, [Value::Int(x as i64), Value::Int(y as i64)])?
+ .cast()
+ .at(func.span())?,
})
}
}
diff --git a/library/src/meta/counter.rs b/library/src/meta/counter.rs
index b8f719ac..b61e8913 100644
--- a/library/src/meta/counter.rs
+++ b/library/src/meta/counter.rs
@@ -3,6 +3,7 @@ use std::str::FromStr;
use ecow::{eco_vec, EcoVec};
use smallvec::{smallvec, SmallVec};
+use typst::eval::Tracer;
use super::{Numbering, NumberingPattern};
use crate::layout::PageNode;
@@ -125,10 +126,16 @@ impl Show for CounterNode {
return counter.resolve(vt, id, &numbering);
}
- let sequence = counter.sequence(vt.world, vt.introspector)?;
+ let sequence = counter.sequence(
+ vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
+ TrackedMut::reborrow_mut(&mut vt.provider),
+ vt.introspector,
+ )?;
+
Ok(match (sequence.single(id), sequence.single(None)) {
(Some(current), Some(total)) => {
- numbering.apply(vt.world, &[current, total])?.display()
+ numbering.apply_vt(vt, &[current, total])?.display()
}
_ => Content::empty(),
})
@@ -213,7 +220,7 @@ impl Counter {
/// id.
pub fn resolve(
&self,
- vt: &Vt,
+ vt: &mut Vt,
stop: Option<StableId>,
numbering: &Numbering,
) -> SourceResult<Content> {
@@ -221,9 +228,15 @@ impl Counter {
return Ok(Content::empty());
}
- let sequence = self.sequence(vt.world, vt.introspector)?;
+ let sequence = self.sequence(
+ vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
+ TrackedMut::reborrow_mut(&mut vt.provider),
+ vt.introspector,
+ )?;
+
Ok(match sequence.at(stop) {
- Some(state) => numbering.apply(vt.world, &state.0)?.display(),
+ Some(state) => numbering.apply_vt(vt, &state.0)?.display(),
None => Content::empty(),
})
}
@@ -236,8 +249,11 @@ impl Counter {
fn sequence(
&self,
world: Tracked<dyn World>,
+ tracer: TrackedMut<Tracer>,
+ provider: TrackedMut<StabilityProvider>,
introspector: Tracked<Introspector>,
) -> SourceResult<CounterSequence> {
+ let mut vt = Vt { world, tracer, provider, introspector };
let mut search = Selector::Node(
NodeId::of::<CounterNode>(),
Some(dict! { "counter" => self.clone() }),
@@ -277,7 +293,7 @@ impl Counter {
None => Some(CounterUpdate::Step(NonZeroUsize::ONE)),
},
} {
- state.update(world, update)?;
+ state.update(&mut vt, update)?;
}
stops.push((id, state.clone()));
@@ -335,17 +351,15 @@ pub struct CounterState(pub SmallVec<[NonZeroUsize; 3]>);
impl CounterState {
/// Advance the counter and return the numbers for the given heading.
- pub fn update(
- &mut self,
- world: Tracked<dyn World>,
- update: CounterUpdate,
- ) -> SourceResult<()> {
+ pub fn update(&mut self, vt: &mut Vt, update: CounterUpdate) -> SourceResult<()> {
match update {
CounterUpdate::Set(state) => *self = state,
CounterUpdate::Step(level) => self.step(level),
CounterUpdate::Func(func) => {
- let args = Args::new(func.span(), self.0.iter().copied().map(Into::into));
- *self = func.call_detached(world, args)?.cast().at(func.span())?
+ *self = func
+ .call_vt(vt, self.0.iter().copied().map(Into::into))?
+ .cast()
+ .at(func.span())?
}
}
Ok(())
diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs
index 6febc408..6facb833 100644
--- a/library/src/meta/numbering.rs
+++ b/library/src/meta/numbering.rs
@@ -64,7 +64,7 @@ pub fn numbering(
#[variadic]
numbers: Vec<NonZeroUsize>,
) -> Value {
- numbering.apply(vm.world(), &numbers)?
+ numbering.apply_vm(vm, &numbers)?
}
/// How to number a sequence of things.
@@ -78,11 +78,7 @@ pub enum Numbering {
impl Numbering {
/// Apply the pattern to the given numbers.
- pub fn apply(
- &self,
- world: Tracked<dyn World>,
- numbers: &[NonZeroUsize],
- ) -> SourceResult<Value> {
+ pub fn apply_vm(&self, vm: &mut Vm, numbers: &[NonZeroUsize]) -> SourceResult<Value> {
Ok(match self {
Self::Pattern(pattern) => Value::Str(pattern.apply(numbers).into()),
Self::Func(func) => {
@@ -90,7 +86,17 @@ impl Numbering {
func.span(),
numbers.iter().map(|n| Value::Int(n.get() as i64)),
);
- func.call_detached(world, args)?
+ func.call_vm(vm, args)?
+ }
+ })
+ }
+
+ /// Apply the pattern to the given numbers.
+ pub fn apply_vt(&self, vt: &mut Vt, numbers: &[NonZeroUsize]) -> SourceResult<Value> {
+ Ok(match self {
+ Self::Pattern(pattern) => Value::Str(pattern.apply(numbers).into()),
+ Self::Func(func) => {
+ func.call_vt(vt, numbers.iter().map(|n| Value::Int(n.get() as i64)))?
}
})
}
diff --git a/library/src/meta/outline.rs b/library/src/meta/outline.rs
index 97611036..7cd26eba 100644
--- a/library/src/meta/outline.rs
+++ b/library/src/meta/outline.rs
@@ -91,10 +91,12 @@ impl Show for OutlineNode {
let depth = self.depth(styles);
let mut ancestors: Vec<&HeadingNode> = vec![];
- for node in vt.introspector.query(Selector::Node(
+ let nodes = vt.introspector.query(Selector::Node(
NodeId::of::<HeadingNode>(),
Some(dict! { "outlined" => true }),
- )) {
+ ));
+
+ for node in &nodes {
let heading = node.to::<HeadingNode>().unwrap();
let stable_id = heading.0.stable_id().unwrap();
if !heading.outlined(StyleChain::default()) {
diff --git a/library/src/meta/query.rs b/library/src/meta/query.rs
index c91f0d1a..bab8ed7c 100644
--- a/library/src/meta/query.rs
+++ b/library/src/meta/query.rs
@@ -59,11 +59,6 @@ impl Show for QueryNode {
let target = self.target();
let (before, after) = vt.introspector.query_split(target, id);
let func = self.format();
- let args = Args::new(func.span(), [encode(before), encode(after)]);
- Ok(func.call_detached(vt.world, args)?.display())
+ Ok(func.call_vt(vt, [before.into(), after.into()])?.display())
}
}
-
-fn encode(list: Vec<&Content>) -> Value {
- Value::Array(list.into_iter().cloned().map(Value::Content).collect())
-}
diff --git a/library/src/meta/reference.rs b/library/src/meta/reference.rs
index f05692dd..0603ee4e 100644
--- a/library/src/meta/reference.rs
+++ b/library/src/meta/reference.rs
@@ -80,7 +80,7 @@ impl Show for RefNode {
return self.to_citation(styles).show(vt, styles);
}
- let &[node] = matches.as_slice() else {
+ let [node] = matches.as_slice() else {
bail!(self.span(), if matches.is_empty() {
"label does not exist in the document"
} else {
@@ -102,8 +102,7 @@ impl Show for RefNode {
Smart::Custom(None) => Content::empty(),
Smart::Custom(Some(Supplement::Content(content))) => content.clone(),
Smart::Custom(Some(Supplement::Func(func))) => {
- let args = Args::new(func.span(), [node.clone().into()]);
- func.call_detached(vt.world, args)?.display()
+ func.call_vt(vt, [node.clone().into()])?.display()
}
};
diff --git a/library/src/meta/state.rs b/library/src/meta/state.rs
index 8b0a0aa6..6b521301 100644
--- a/library/src/meta/state.rs
+++ b/library/src/meta/state.rs
@@ -1,6 +1,7 @@
use std::fmt::{self, Debug, Formatter, Write};
use ecow::EcoVec;
+use typst::eval::Tracer;
use crate::prelude::*;
@@ -118,7 +119,7 @@ impl State {
/// Display the state at the postition of the given stable id.
fn resolve(
&self,
- vt: &Vt,
+ vt: &mut Vt,
stop: Option<StableId>,
func: Option<Func>,
) -> SourceResult<Content> {
@@ -126,12 +127,17 @@ impl State {
return Ok(Content::empty());
}
- let sequence = self.sequence(vt.world, vt.introspector)?;
+ let sequence = self.sequence(
+ vt.world,
+ TrackedMut::reborrow_mut(&mut vt.tracer),
+ TrackedMut::reborrow_mut(&mut vt.provider),
+ vt.introspector,
+ )?;
+
Ok(match sequence.at(stop) {
Some(value) => {
if let Some(func) = func {
- let args = Args::new(func.span(), [value]);
- func.call_detached(vt.world, args)?.display()
+ func.call_vt(vt, [value])?.display()
} else {
value.display()
}
@@ -148,8 +154,11 @@ impl State {
fn sequence(
&self,
world: Tracked<dyn World>,
+ tracer: TrackedMut<Tracer>,
+ provider: TrackedMut<StabilityProvider>,
introspector: Tracked<Introspector>,
) -> SourceResult<StateSequence> {
+ let mut vt = Vt { world, tracer, provider, introspector };
let search = Selector::Node(
NodeId::of::<StateNode>(),
Some(dict! { "state" => self.clone() }),
@@ -165,10 +174,7 @@ impl State {
if let StateAction::Update(update) = node.action() {
match update {
StateUpdate::Set(value) => state = value,
- StateUpdate::Func(func) => {
- let args = Args::new(func.span(), [state]);
- state = func.call_detached(world, args)?;
- }
+ StateUpdate::Func(func) => state = func.call_vt(&mut vt, [state])?,
}
}