summaryrefslogtreecommitdiff
path: root/src/library/utility/mod.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-05-25 13:50:33 +0200
committerLaurenz <laurmaedje@gmail.com>2022-05-25 13:59:06 +0200
commitc010cbc17dcbb2f0d6005d21530143bf57cb5871 (patch)
tree937fe79f0c121bcc025480181287fd4a3d0c0f4f /src/library/utility/mod.rs
parent6935cf8dfefff3d6cf234f077a7d61661fd5ca57 (diff)
Move route from context to VM
Diffstat (limited to 'src/library/utility/mod.rs')
-rw-r--r--src/library/utility/mod.rs23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs
index 6f0f9a4c..051f8195 100644
--- a/src/library/utility/mod.rs
+++ b/src/library/utility/mod.rs
@@ -8,19 +8,17 @@ pub use color::*;
pub use math::*;
pub use string::*;
-use std::mem;
-
use crate::eval::{Eval, Machine, Scopes};
use crate::library::prelude::*;
use crate::source::SourceFile;
/// The name of a value's type.
-pub fn type_(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn type_(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
Ok(args.expect::<Value>("value")?.type_name().into())
}
/// Ensure that a condition is fulfilled.
-pub fn assert(_: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn assert(_: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v, span } = args.expect::<Spanned<bool>>("condition")?;
if !v {
bail!(span, "assertion failed");
@@ -29,28 +27,21 @@ pub fn assert(_: &mut Context, args: &mut Args) -> TypResult<Value> {
}
/// Evaluate a string as Typst markup.
-pub fn eval(ctx: &mut Context, args: &mut Args) -> TypResult<Value> {
+pub fn eval(vm: &mut Machine, args: &mut Args) -> TypResult<Value> {
let Spanned { v: src, span } = args.expect::<Spanned<String>>("source")?;
// Parse the source and set a synthetic span for all nodes.
let source = SourceFile::synthesized(src, span);
let ast = source.ast()?;
- // Save the old route, then detach it.
- let prev_route = mem::take(&mut ctx.route);
-
// Evaluate the source.
- let std = ctx.config.std.clone();
+ let std = vm.ctx.config.std.clone();
let scopes = Scopes::new(Some(&std));
- let mut vm = Machine::new(ctx, scopes);
- let result = ast.eval(&mut vm);
- let flow = vm.flow;
-
- // Restore the old route.
- ctx.route = prev_route;
+ let mut sub = Machine::new(vm.ctx, vec![], scopes);
+ let result = ast.eval(&mut sub);
// Handle control flow.
- if let Some(flow) = flow {
+ if let Some(flow) = sub.flow {
return Err(flow.forbidden());
}