diff --git a/benches/oneshot.rs b/benches/oneshot.rs index e3b18390c..92721013b 100644 --- a/benches/oneshot.rs +++ b/benches/oneshot.rs @@ -5,7 +5,7 @@ use iai::{black_box, main, Iai}; use typst::loading::MemLoader; use typst::parse::{parse, Scanner, TokenMode, Tokens}; use typst::source::SourceId; -use typst::Context; +use typst::{Context, Vm}; const SRC: &str = include_str!("bench.typ"); const FONT: &[u8] = include_bytes!("../fonts/IBMPlexSans-Regular.ttf"); @@ -69,13 +69,15 @@ fn bench_edit(iai: &mut Iai) { fn bench_eval(iai: &mut Iai) { let (mut ctx, id) = context(); - iai.run(|| ctx.evaluate(id).unwrap()); + let mut vm = Vm::new(&mut ctx); + iai.run(|| vm.evaluate(id).unwrap()); } fn bench_layout(iai: &mut Iai) { let (mut ctx, id) = context(); - let module = ctx.evaluate(id).unwrap(); - iai.run(|| module.template.layout(&mut ctx)); + let mut vm = Vm::new(&mut ctx); + let module = vm.evaluate(id).unwrap(); + iai.run(|| module.template.layout(&mut vm)); } fn bench_highlight(iai: &mut Iai) { diff --git a/src/eval/capture.rs b/src/eval/capture.rs index 8585776a0..d62ec55c2 100644 --- a/src/eval/capture.rs +++ b/src/eval/capture.rs @@ -28,7 +28,7 @@ impl<'a> CapturesVisitor<'a> { /// Bind a new internal variable. pub fn bind(&mut self, ident: Ident) { - self.internal.def_mut(ident.take(), Value::None); + self.internal.top.def_mut(ident.take(), Value::None); } /// Capture a variable if it isn't internal. @@ -135,9 +135,9 @@ mod tests { let red = RedNode::from_root(green, SourceId::from_raw(0)); let mut scopes = Scopes::new(None); - scopes.def_const("x", 0); - scopes.def_const("y", 0); - scopes.def_const("z", 0); + scopes.top.def_const("x", 0); + scopes.top.def_const("y", 0); + scopes.top.def_const("z", 0); let mut visitor = CapturesVisitor::new(&scopes); visitor.visit(red.as_ref()); diff --git a/src/eval/class.rs b/src/eval/class.rs index c4880e9a9..28e49a999 100644 --- a/src/eval/class.rs +++ b/src/eval/class.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Formatter, Write}; use std::hash::{Hash, Hasher}; -use super::{Args, EvalContext, Func, StyleMap, Template, Value}; +use super::{Args, Func, StyleMap, Template, Value, Vm}; use crate::diag::TypResult; /// A class of nodes. @@ -36,7 +36,7 @@ use crate::diag::TypResult; #[derive(Clone)] pub struct Class { name: &'static str, - construct: fn(&mut EvalContext, &mut Args) -> TypResult, + construct: fn(&mut Vm, &mut Args) -> TypResult, set: fn(&mut Args, &mut StyleMap) -> TypResult<()>, } @@ -73,8 +73,8 @@ impl Class { /// This parses both property and data arguments (in this order), styles the /// template constructed from the data with the style properties and wraps /// it in a value. - pub fn construct(&self, ctx: &mut EvalContext, mut args: Args) -> TypResult { - let value = (self.construct)(ctx, &mut args)?; + pub fn construct(&self, vm: &mut Vm, mut args: Args) -> TypResult { + let value = (self.construct)(vm, &mut args)?; args.finish()?; Ok(value) } @@ -117,7 +117,7 @@ pub trait Construct { /// /// This is passed only the arguments that remain after execution of the /// class's set rule. - fn construct(ctx: &mut EvalContext, args: &mut Args) -> TypResult