From 6935cf8dfefff3d6cf234f077a7d61661fd5ca57 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 25 May 2022 11:46:51 +0200 Subject: Virtual machine --- src/library/utility/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/library') diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs index c4e847c3..6f0f9a4c 100644 --- a/src/library/utility/mod.rs +++ b/src/library/utility/mod.rs @@ -10,7 +10,7 @@ pub use string::*; use std::mem; -use crate::eval::{Eval, Scopes}; +use crate::eval::{Eval, Machine, Scopes}; use crate::library::prelude::*; use crate::source::SourceFile; @@ -33,22 +33,24 @@ pub fn eval(ctx: &mut Context, args: &mut Args) -> TypResult { let Spanned { v: src, span } = args.expect::>("source")?; // Parse the source and set a synthetic span for all nodes. - let mut source = SourceFile::detached(src); - source.synthesize(span); + let source = SourceFile::synthesized(src, span); let ast = source.ast()?; - // Save the old context, then detach it. - let prev_flow = ctx.flow.take(); + // 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 mut scp = Scopes::new(Some(&std)); - let result = ast.eval(ctx, &mut scp); + 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 context and handle control flow. + // Restore the old route. ctx.route = prev_route; - if let Some(flow) = mem::replace(&mut ctx.flow, prev_flow) { + + // Handle control flow. + if let Some(flow) = flow { return Err(flow.forbidden()); } -- cgit v1.2.3